diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-15 21:36:57 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-15 21:36:57 +0000 |
commit | f363aea21641de7de5ea4b8835b76900ecca0a85 (patch) | |
tree | 6cf3c89b6849ab38ec1689687d291a3e249796ab /CMake | |
parent | 673746244b2ade8dc80ad3f84a3114e8d2b0ab16 (diff) | |
parent | 49c8bf1afa2dd4067e948e89a0bdc21e40effdbe (diff) | |
download | abseil-cpp-f363aea21641de7de5ea4b8835b76900ecca0a85.tar.gz |
Snap for 8730993 from 49c8bf1afa2dd4067e948e89a0bdc21e40effdbe to mainline-tzdata3-releaseaml_tz3_314012070aml_tz3_314012050aml_tz3_314012010aml_tz3_313110000aml_tz3_312511020aml_tz3_312511010aml_tz3_312410020aml_tz3_312410010android12-mainline-tzdata3-releaseaml_tz3_314012010
Change-Id: I5e56968d342207f843d5c40fc8163c3965c248bd
Diffstat (limited to 'CMake')
-rw-r--r-- | CMake/AbseilDll.cmake | 73 | ||||
-rw-r--r-- | CMake/AbseilHelpers.cmake | 135 | ||||
-rw-r--r-- | CMake/AbseilInstallDirs.cmake | 20 | ||||
-rw-r--r-- | CMake/Googletest/CMakeLists.txt.in | 11 | ||||
-rw-r--r-- | CMake/Googletest/DownloadGTest.cmake | 19 | ||||
-rw-r--r-- | CMake/README.md | 96 | ||||
-rw-r--r-- | CMake/abslConfig.cmake.in | 5 | ||||
-rw-r--r-- | CMake/install_test_project/CMakeLists.txt | 4 | ||||
-rw-r--r-- | CMake/install_test_project/simple.cc | 9 | ||||
-rwxr-xr-x | CMake/install_test_project/test.sh | 164 |
10 files changed, 182 insertions, 354 deletions
diff --git a/CMake/AbseilDll.cmake b/CMake/AbseilDll.cmake index fa323ff8..90c9f1f6 100644 --- a/CMake/AbseilDll.cmake +++ b/CMake/AbseilDll.cmake @@ -1,5 +1,4 @@ include(CMakeParseArguments) -include(GNUInstallDirs) set(ABSL_INTERNAL_DLL_FILES "algorithm/algorithm.h" @@ -9,15 +8,17 @@ set(ABSL_INTERNAL_DLL_FILES "base/casts.h" "base/config.h" "base/const_init.h" + "base/dynamic_annotations.cc" "base/dynamic_annotations.h" "base/internal/atomic_hook.h" + "base/internal/bits.h" "base/internal/cycleclock.cc" "base/internal/cycleclock.h" "base/internal/direct_mmap.h" - "base/internal/dynamic_annotations.h" "base/internal/endian.h" "base/internal/errno_saver.h" - "base/internal/fast_type_id.h" + "base/internal/exponential_biased.cc" + "base/internal/exponential_biased.h" "base/internal/hide_ptr.h" "base/internal/identity.h" "base/internal/invoke.h" @@ -26,14 +27,14 @@ set(ABSL_INTERNAL_DLL_FILES "base/internal/low_level_alloc.h" "base/internal/low_level_scheduling.h" "base/internal/per_thread_tls.h" + "base/internal/periodic_sampler.cc" + "base/internal/periodic_sampler.h" "base/internal/pretty_function.h" "base/internal/raw_logging.cc" "base/internal/raw_logging.h" "base/internal/scheduling_mode.h" "base/internal/scoped_set_env.cc" "base/internal/scoped_set_env.h" - "base/internal/strerror.h" - "base/internal/strerror.cc" "base/internal/spinlock.cc" "base/internal/spinlock.h" "base/internal/spinlock_wait.cc" @@ -57,8 +58,6 @@ set(ABSL_INTERNAL_DLL_FILES "base/policy_checks.h" "base/port.h" "base/thread_annotations.h" - "cleanup/cleanup.h" - "cleanup/internal/cleanup.h" "container/btree_map.h" "container/btree_set.h" "container/fixed_array.h" @@ -120,35 +119,27 @@ set(ABSL_INTERNAL_DLL_FILES "hash/internal/hash.h" "hash/internal/hash.cc" "hash/internal/spy_hash_state.h" - "hash/internal/low_level_hash.h" - "hash/internal/low_level_hash.cc" "memory/memory.h" "meta/type_traits.h" - "numeric/bits.h" "numeric/int128.cc" "numeric/int128.h" - "numeric/internal/bits.h" - "numeric/internal/representation.h" - "profiling/internal/exponential_biased.cc" - "profiling/internal/exponential_biased.h" - "profiling/internal/periodic_sampler.cc" - "profiling/internal/periodic_sampler.h" - "profiling/internal/sample_recorder.h" "random/bernoulli_distribution.h" "random/beta_distribution.h" "random/bit_gen_ref.h" "random/discrete_distribution.cc" "random/discrete_distribution.h" + "random/distribution_format_traits.h" "random/distributions.h" "random/exponential_distribution.h" "random/gaussian_distribution.cc" "random/gaussian_distribution.h" + "random/internal/distributions.h" "random/internal/distribution_caller.h" - "random/internal/fastmath.h" "random/internal/fast_uniform_bits.h" + "random/internal/fastmath.h" + "random/internal/gaussian_distribution_gentables.cc" "random/internal/generate_real.h" "random/internal/iostream_state_saver.h" - "random/internal/mock_helpers.h" "random/internal/nonsecure_base.h" "random/internal/pcg_engine.h" "random/internal/platform.h" @@ -161,7 +152,6 @@ set(ABSL_INTERNAL_DLL_FILES "random/internal/randen_engine.h" "random/internal/randen_hwaes.cc" "random/internal/randen_hwaes.h" - "random/internal/randen_round_keys.cc" "random/internal/randen_slow.cc" "random/internal/randen_slow.h" "random/internal/randen_traits.h" @@ -182,12 +172,8 @@ set(ABSL_INTERNAL_DLL_FILES "random/uniform_int_distribution.h" "random/uniform_real_distribution.h" "random/zipf_distribution.h" - "status/internal/status_internal.h" - "status/internal/statusor_internal.h" "status/status.h" "status/status.cc" - "status/statusor.h" - "status/statusor.cc" "status/status_payload_printer.h" "status/status_payload_printer.cc" "strings/ascii.cc" @@ -198,37 +184,12 @@ set(ABSL_INTERNAL_DLL_FILES "strings/cord.h" "strings/escaping.cc" "strings/escaping.h" + "strings/internal/cord_internal.h" "strings/internal/charconv_bigint.cc" "strings/internal/charconv_bigint.h" "strings/internal/charconv_parse.cc" "strings/internal/charconv_parse.h" - "strings/internal/cord_internal.cc" - "strings/internal/cord_internal.h" - "strings/internal/cord_rep_consume.h" - "strings/internal/cord_rep_consume.cc" - "strings/internal/cord_rep_btree.cc" - "strings/internal/cord_rep_btree.h" - "strings/internal/cord_rep_btree_navigator.cc" - "strings/internal/cord_rep_btree_navigator.h" - "strings/internal/cord_rep_btree_reader.cc" - "strings/internal/cord_rep_btree_reader.h" - "strings/internal/cord_rep_flat.h" - "strings/internal/cord_rep_ring.cc" - "strings/internal/cord_rep_ring.h" - "strings/internal/cord_rep_ring_reader.h" - "strings/internal/cordz_functions.cc" - "strings/internal/cordz_functions.h" - "strings/internal/cordz_handle.cc" - "strings/internal/cordz_handle.h" - "strings/internal/cordz_info.cc" - "strings/internal/cordz_info.h" - "strings/internal/cordz_sample_token.cc" - "strings/internal/cordz_sample_token.h" - "strings/internal/cordz_statistics.h" - "strings/internal/cordz_update_scope.h" - "strings/internal/cordz_update_tracker.h" "strings/internal/stl_type_traits.h" - "strings/internal/string_constant.h" "strings/match.cc" "strings/match.h" "strings/numbers.cc" @@ -283,7 +244,6 @@ set(ABSL_INTERNAL_DLL_FILES "synchronization/notification.h" "synchronization/internal/create_thread_identity.cc" "synchronization/internal/create_thread_identity.h" - "synchronization/internal/futex.h" "synchronization/internal/graphcycles.cc" "synchronization/internal/graphcycles.h" "synchronization/internal/kernel_timeout.h" @@ -332,8 +292,6 @@ set(ABSL_INTERNAL_DLL_FILES "types/internal/conformance_aliases.h" "types/internal/conformance_archetype.h" "types/internal/conformance_profile.h" - "types/internal/parentheses.h" - "types/internal/transform_args.h" "types/internal/variant.h" "types/optional.h" "types/internal/optional.h" @@ -458,7 +416,6 @@ set(ABSL_INTERNAL_DLL_TARGETS "raw_hash_set" "layout" "tracked" - "sample_recorder" ) function(absl_internal_dll_contains) @@ -522,7 +479,7 @@ function(absl_make_dll) abseil_dll PUBLIC "$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>" - $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> + $<INSTALL_INTERFACE:${ABSL_INSTALL_INCLUDEDIR}> ) target_compile_options( @@ -540,8 +497,8 @@ function(absl_make_dll) ${ABSL_CC_LIB_DEFINES} ) install(TARGETS abseil_dll EXPORT ${PROJECT_NAME}Targets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${ABSL_INSTALL_BINDIR} + LIBRARY DESTINATION ${ABSL_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${ABSL_INSTALL_LIBDIR} ) endfunction() diff --git a/CMake/AbseilHelpers.cmake b/CMake/AbseilHelpers.cmake index f2ce5675..86ff9eba 100644 --- a/CMake/AbseilHelpers.cmake +++ b/CMake/AbseilHelpers.cmake @@ -17,14 +17,13 @@ include(CMakeParseArguments) include(AbseilConfigureCopts) include(AbseilDll) +include(AbseilInstallDirs) # The IDE folder for Abseil that will be used if Abseil is included in a CMake # project that sets # set_property(GLOBAL PROPERTY USE_FOLDERS ON) # For example, Visual Studio supports folders. -if(NOT DEFINED ABSL_IDE_FOLDER) - set(ABSL_IDE_FOLDER Abseil) -endif() +set(ABSL_IDE_FOLDER Abseil) # absl_cc_library() # @@ -40,7 +39,7 @@ endif() # LINKOPTS: List of link options # PUBLIC: Add this so that this library will be exported under absl:: # Also in IDE, target will appear in Abseil folder while non PUBLIC will be in Abseil/internal. -# TESTONLY: When added, this target will only be built if BUILD_TESTING=ON. +# TESTONLY: When added, this target will only be built if user passes -DABSL_RUN_TESTS=ON to CMake. # # Note: # By default, absl_cc_library will always create a library named absl_${NAME}, @@ -82,7 +81,7 @@ function(absl_cc_library) ${ARGN} ) - if(ABSL_CC_LIB_TESTONLY AND NOT BUILD_TESTING) + if(ABSL_CC_LIB_TESTONLY AND NOT ABSL_RUN_TESTS) return() endif() @@ -103,7 +102,7 @@ function(absl_cc_library) endif() endforeach() - if(ABSL_CC_SRCS STREQUAL "") + if("${ABSL_CC_SRCS}" STREQUAL "") set(ABSL_CC_LIB_IS_INTERFACE 1) else() set(ABSL_CC_LIB_IS_INTERFACE 0) @@ -121,11 +120,7 @@ function(absl_cc_library) # 4. "static" -- This target does not depend on the DLL and should be built # statically. if (${ABSL_BUILD_DLL}) - if(ABSL_ENABLE_INSTALL) - absl_internal_dll_contains(TARGET ${_NAME} OUTPUT _in_dll) - else() - absl_internal_dll_contains(TARGET ${ABSL_CC_LIB_NAME} OUTPUT _in_dll) - endif() + absl_internal_dll_contains(TARGET ${_NAME} OUTPUT _in_dll) if (${_in_dll}) # This target should be replaced by the DLL set(_build_type "dll") @@ -140,54 +135,8 @@ function(absl_cc_library) set(_build_type "static") endif() - # Generate a pkg-config file for every library: - if((_build_type STREQUAL "static" OR _build_type STREQUAL "shared") - AND ABSL_ENABLE_INSTALL) - if(NOT ABSL_CC_LIB_TESTONLY) - if(absl_VERSION) - set(PC_VERSION "${absl_VERSION}") - else() - set(PC_VERSION "head") - endif() - foreach(dep ${ABSL_CC_LIB_DEPS}) - if(${dep} MATCHES "^absl::(.*)") - # Join deps with commas. - if(PC_DEPS) - set(PC_DEPS "${PC_DEPS},") - endif() - set(PC_DEPS "${PC_DEPS} absl_${CMAKE_MATCH_1} = ${PC_VERSION}") - endif() - endforeach() - foreach(cflag ${ABSL_CC_LIB_COPTS}) - if(${cflag} MATCHES "^(-Wno|/wd)") - # These flags are needed to suppress warnings that might fire in our headers. - set(PC_CFLAGS "${PC_CFLAGS} ${cflag}") - elseif(${cflag} MATCHES "^(-W|/w[1234eo])") - # Don't impose our warnings on others. - else() - set(PC_CFLAGS "${PC_CFLAGS} ${cflag}") - endif() - endforeach() - FILE(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/lib/pkgconfig/absl_${_NAME}.pc" CONTENT "\ -prefix=${CMAKE_INSTALL_PREFIX}\n\ -exec_prefix=\${prefix}\n\ -libdir=${CMAKE_INSTALL_FULL_LIBDIR}\n\ -includedir=${CMAKE_INSTALL_FULL_INCLUDEDIR}\n\ -\n\ -Name: absl_${_NAME}\n\ -Description: Abseil ${_NAME} library\n\ -URL: https://abseil.io/\n\ -Version: ${PC_VERSION}\n\ -Requires:${PC_DEPS}\n\ -Libs: -L\${libdir} $<JOIN:${ABSL_CC_LIB_LINKOPTS}, > $<$<NOT:$<BOOL:${ABSL_CC_LIB_IS_INTERFACE}>>:-labsl_${_NAME}>\n\ -Cflags: -I\${includedir}${PC_CFLAGS}\n") - INSTALL(FILES "${CMAKE_BINARY_DIR}/lib/pkgconfig/absl_${_NAME}.pc" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") - endif() - endif() - if(NOT ABSL_CC_LIB_IS_INTERFACE) - if(_build_type STREQUAL "dll_dep") + if(${_build_type} STREQUAL "dll_dep") # This target depends on the DLL. When adding dependencies to this target, # any depended-on-target which is contained inside the DLL is replaced # with a dependency on the DLL. @@ -216,7 +165,7 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n") "${_gtest_link_define}" ) - elseif(_build_type STREQUAL "static" OR _build_type STREQUAL "shared") + elseif(${_build_type} STREQUAL "static" OR ${_build_type} STREQUAL "shared") add_library(${_NAME} "") target_sources(${_NAME} PRIVATE ${ABSL_CC_LIB_SRCS} ${ABSL_CC_LIB_HDRS}) target_link_libraries(${_NAME} @@ -239,7 +188,7 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n") target_include_directories(${_NAME} PUBLIC "$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>" - $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> + $<INSTALL_INTERFACE:${ABSL_INSTALL_INCLUDEDIR}> ) target_compile_options(${_NAME} PRIVATE ${ABSL_CC_LIB_COPTS}) @@ -254,23 +203,9 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n") set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER}/internal) endif() - if(ABSL_PROPAGATE_CXX_STD) - # Abseil libraries require C++11 as the current minimum standard. - # Top-level application CMake projects should ensure a consistent C++ - # standard for all compiled sources by setting CMAKE_CXX_STANDARD. - target_compile_features(${_NAME} PUBLIC cxx_std_11) - else() - # Note: This is legacy (before CMake 3.8) behavior. Setting the - # target-level CXX_STANDARD property to ABSL_CXX_STANDARD (which is - # initialized by CMAKE_CXX_STANDARD) should have no real effect, since - # that is the default value anyway. - # - # CXX_STANDARD_REQUIRED does guard against the top-level CMake project - # not having enabled CMAKE_CXX_STANDARD_REQUIRED (which prevents - # "decaying" to an older standard if the requested one isn't available). - set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD}) - set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) - endif() + # INTERFACE libraries can't have the CXX_STANDARD property set + set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD}) + set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) # When being installed, we lose the absl_ prefix. We want to put it back # to have properly named lib files. This is a no-op when we are not being @@ -278,7 +213,6 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n") if(ABSL_ENABLE_INSTALL) set_target_properties(${_NAME} PROPERTIES OUTPUT_NAME "absl_${_NAME}" - SOVERSION "2111.0.0" ) endif() else() @@ -287,10 +221,10 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n") target_include_directories(${_NAME} INTERFACE "$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>" - $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> + $<INSTALL_INTERFACE:${ABSL_INSTALL_INCLUDEDIR}> ) - if (_build_type STREQUAL "dll") + if (${_build_type} STREQUAL "dll") set(ABSL_CC_LIB_DEPS abseil_dll) endif() @@ -301,25 +235,15 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n") ${ABSL_DEFAULT_LINKOPTS} ) target_compile_definitions(${_NAME} INTERFACE ${ABSL_CC_LIB_DEFINES}) - - if(ABSL_PROPAGATE_CXX_STD) - # Abseil libraries require C++11 as the current minimum standard. - # Top-level application CMake projects should ensure a consistent C++ - # standard for all compiled sources by setting CMAKE_CXX_STANDARD. - target_compile_features(${_NAME} INTERFACE cxx_std_11) - - # (INTERFACE libraries can't have the CXX_STANDARD property set, so there - # is no legacy behavior else case). - endif() endif() # TODO currently we don't install googletest alongside abseil sources, so # installed abseil can't be tested. if(NOT ABSL_CC_LIB_TESTONLY AND ABSL_ENABLE_INSTALL) install(TARGETS ${_NAME} EXPORT ${PROJECT_NAME}Targets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${ABSL_INSTALL_BINDIR} + LIBRARY DESTINATION ${ABSL_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${ABSL_INSTALL_LIBDIR} ) endif() @@ -360,11 +284,11 @@ endfunction() # "awesome_test.cc" # DEPS # absl::awesome -# GTest::gmock -# GTest::gtest_main +# gmock +# gtest_main # ) function(absl_cc_test) - if(NOT BUILD_TESTING) + if(NOT ABSL_RUN_TESTS) return() endif() @@ -414,23 +338,8 @@ function(absl_cc_test) # Add all Abseil targets to a folder in the IDE for organization. set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER}/test) - if(ABSL_PROPAGATE_CXX_STD) - # Abseil libraries require C++11 as the current minimum standard. - # Top-level application CMake projects should ensure a consistent C++ - # standard for all compiled sources by setting CMAKE_CXX_STANDARD. - target_compile_features(${_NAME} PUBLIC cxx_std_11) - else() - # Note: This is legacy (before CMake 3.8) behavior. Setting the - # target-level CXX_STANDARD property to ABSL_CXX_STANDARD (which is - # initialized by CMAKE_CXX_STANDARD) should have no real effect, since - # that is the default value anyway. - # - # CXX_STANDARD_REQUIRED does guard against the top-level CMake project - # not having enabled CMAKE_CXX_STANDARD_REQUIRED (which prevents - # "decaying" to an older standard if the requested one isn't available). - set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD}) - set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) - endif() + set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD}) + set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) add_test(NAME ${_NAME} COMMAND ${_NAME}) endfunction() diff --git a/CMake/AbseilInstallDirs.cmake b/CMake/AbseilInstallDirs.cmake new file mode 100644 index 00000000..b67272f8 --- /dev/null +++ b/CMake/AbseilInstallDirs.cmake @@ -0,0 +1,20 @@ +include(GNUInstallDirs) + +# absl_VERSION is only set if we are an LTS release being installed, in which +# case it may be into a system directory and so we need to make subdirectories +# for each installed version of Abseil. This mechanism is implemented in +# Abseil's internal Copybara (https://github.com/google/copybara) workflows and +# isn't visible in the CMake buildsystem itself. + +if(absl_VERSION) + set(ABSL_SUBDIR "${PROJECT_NAME}_${PROJECT_VERSION}") + set(ABSL_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}/${ABSL_SUBDIR}") + set(ABSL_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${ABSL_SUBDIR}") + set(ABSL_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/{ABSL_SUBDIR}") + set(ABSL_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${ABSL_SUBDIR}") +else() + set(ABSL_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}") + set(ABSL_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + set(ABSL_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}") + set(ABSL_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}") +endif()
\ No newline at end of file diff --git a/CMake/Googletest/CMakeLists.txt.in b/CMake/Googletest/CMakeLists.txt.in index 5769e3a9..d60a33e9 100644 --- a/CMake/Googletest/CMakeLists.txt.in +++ b/CMake/Googletest/CMakeLists.txt.in @@ -1,14 +1,15 @@ cmake_minimum_required(VERSION 2.8.2) -project(googletest-external NONE) +project(googletest-download NONE) include(ExternalProject) ExternalProject_Add(googletest - URL "${absl_gtest_download_url}" # May be empty - SOURCE_DIR "${absl_gtest_src_dir}" - BINARY_DIR "${absl_gtest_build_dir}" + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG master + SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src" + BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" TEST_COMMAND "" -) +)
\ No newline at end of file diff --git a/CMake/Googletest/DownloadGTest.cmake b/CMake/Googletest/DownloadGTest.cmake index 9d071c91..8a00b455 100644 --- a/CMake/Googletest/DownloadGTest.cmake +++ b/CMake/Googletest/DownloadGTest.cmake @@ -1,11 +1,10 @@ -# Integrates googletest at configure time. Based on the instructions at -# https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project +# Downloads and unpacks googletest at configure time. Based on the instructions +# at https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project -# Set up the external googletest project, downloading the latest from Github -# master if requested. +# Download the latest googletest from Github master configure_file( ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.in - ${CMAKE_BINARY_DIR}/googletest-external/CMakeLists.txt + ${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt ) set(ABSL_SAVE_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) @@ -15,17 +14,17 @@ if (BUILD_SHARED_LIBS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_CREATE_SHARED_LIBRARY=1") endif() -# Configure and build the googletest source. +# Configure and build the downloaded googletest source execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-external ) + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download ) if(result) message(FATAL_ERROR "CMake step for googletest failed: ${result}") endif() execute_process(COMMAND ${CMAKE_COMMAND} --build . RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-external) + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download) if(result) message(FATAL_ERROR "Build step for googletest failed: ${result}") endif() @@ -38,4 +37,6 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Add googletest directly to our build. This defines the gtest and gtest_main # targets. -add_subdirectory(${absl_gtest_src_dir} ${absl_gtest_build_dir} EXCLUDE_FROM_ALL) +add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src + ${CMAKE_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL) diff --git a/CMake/README.md b/CMake/README.md index f8b27e63..04d5df3a 100644 --- a/CMake/README.md +++ b/CMake/README.md @@ -34,16 +34,15 @@ to include Abseil directly in your CMake project. 4. Add the **absl::** target you wish to use to the [`target_link_libraries()`](https://cmake.org/cmake/help/latest/command/target_link_libraries.html) section of your executable or of your library.<br> -Here is a short CMakeLists.txt example of an application project using Abseil. +Here is a short CMakeLists.txt example of a project file using Abseil. ```cmake -cmake_minimum_required(VERSION 3.8.2) -project(my_app_project) +cmake_minimum_required(VERSION 3.5) +project(my_project) # Pick the C++ standard to compile with. # Abseil currently supports C++11, C++14, and C++17. set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) add_subdirectory(abseil-cpp) @@ -51,47 +50,9 @@ add_executable(my_exe source.cpp) target_link_libraries(my_exe absl::base absl::synchronization absl::strings) ``` -Note that if you are developing a library designed for use by other clients, you -should instead leave `CMAKE_CXX_STANDARD` unset (or only set if being built as -the current top-level CMake project) and configure the minimum required C++ -standard at the target level. If you require a later minimum C++ standard than -Abseil does, it's a good idea to also enforce that `CMAKE_CXX_STANDARD` (which -will control Abseil library targets) is set to at least that minimum. For -example: - -```cmake -cmake_minimum_required(VERSION 3.8.2) -project(my_lib_project) - -# Leave C++ standard up to the root application, so set it only if this is the -# current top-level CMake project. -if(CMAKE_SOURCE_DIR STREQUAL my_lib_project_SOURCE_DIR) - set(CMAKE_CXX_STANDARD 17) - set(CMAKE_CXX_STANDARD_REQUIRED ON) -endif() - -add_subdirectory(abseil-cpp) - -add_library(my_lib source.cpp) -target_link_libraries(my_lib absl::base absl::synchronization absl::strings) - -# Enforce that my_lib requires C++17. Important to document for clients that they -# must set CMAKE_CXX_STANDARD to 17 or higher for proper Abseil ABI compatibility -# (since otherwise, Abseil library targets could be compiled with a lower C++ -# standard than my_lib). -target_compile_features(my_lib PUBLIC cxx_std_17) -if(CMAKE_CXX_STANDARD LESS 17) - message(FATAL_ERROR - "my_lib_project requires CMAKE_CXX_STANDARD >= 17 (got: ${CMAKE_CXX_STANDARD})") -endif() -``` - -Then the top-level application project that uses your library is responsible for -setting a consistent `CMAKE_CXX_STANDARD` that is sufficiently high. - ### Running Abseil Tests with CMake -Use the `-DBUILD_TESTING=ON` flag to run Abseil tests. +Use the `-DABSL_RUN_TESTS=ON` flag to run Abseil tests. Note that if the `-DBUILD_TESTING=OFF` flag is passed then Abseil tests will not be run. You will need to provide Abseil with a Googletest dependency. There are two options for how to do this: @@ -109,7 +70,7 @@ For example, to run just the Abseil tests, you could use this script: cd path/to/abseil-cpp mkdir build cd build -cmake -DBUILD_TESTING=ON -DABSL_USE_GOOGLETEST_HEAD=ON .. +cmake -DABSL_USE_GOOGLETEST_HEAD=ON -DABSL_RUN_TESTS=ON .. make -j ctest ``` @@ -132,54 +93,9 @@ absl::flags absl::memory absl::meta absl::numeric -absl::random_random +absl::random absl::strings absl::synchronization absl::time absl::utility ``` - -## Traditional CMake Set-Up - -For larger projects, it may make sense to use the traditional CMake set-up where you build and install projects separately. - -First, you'd need to build and install Google Test: -``` -cmake -S /source/googletest -B /build/googletest -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/installation/dir -DBUILD_GMOCK=ON -cmake --build /build/googletest --target install -``` - -Then you need to configure and build Abseil. Make sure you enable `ABSL_USE_EXTERNAL_GOOGLETEST` and `ABSL_FIND_GOOGLETEST`. You also need to enable `ABSL_ENABLE_INSTALL` so that you can install Abseil itself. -``` -cmake -S /source/abseil-cpp -B /build/abseil-cpp -DCMAKE_PREFIX_PATH=/installation/dir -DCMAKE_INSTALL_PREFIX=/installation/dir -DABSL_ENABLE_INSTALL=ON -DABSL_USE_EXTERNAL_GOOGLETEST=ON -DABSL_FIND_GOOGLETEST=ON -cmake --build /temporary/build/abseil-cpp -``` - -(`CMAKE_PREFIX_PATH` is where you already have Google Test installed; `CMAKE_INSTALL_PREFIX` is where you want to have Abseil installed; they can be different.) - -Run the tests: -``` -ctest --test-dir /temporary/build/abseil-cpp -``` - -And finally install: -``` -cmake --build /temporary/build/abseil-cpp --target install -``` - -# CMake Option Synposis - -## Enable Standard CMake Installation - -`-DABSL_ENABLE_INSTALL=ON` - -## Google Test Options - -`-DBUILD_TESTING=ON` must be set to enable testing - -- Have Abseil download and build Google Test for you: `-DABSL_USE_EXTERNAL_GOOGLETEST=OFF` (default) - - Download and build latest Google Test: `-DABSL_USE_GOOGLETEST_HEAD=ON` - - Download specific Google Test version (ZIP archive): `-DABSL_GOOGLETEST_DOWNLOAD_URL=https://.../version.zip` - - Use Google Test from specific local directory: `-DABSL_LOCAL_GOOGLETEST_DIR=/path/to/googletest` -- Use Google Test included elsewhere in your project: `-DABSL_USE_EXTERNAL_GOOGLETEST=ON` -- Use standard CMake `find_package(CTest)` to find installed Google Test: `-DABSL_USE_EXTERNAL_GOOGLETEST=ON -DABSL_FIND_GOOGLETEST=ON` diff --git a/CMake/abslConfig.cmake.in b/CMake/abslConfig.cmake.in index 62d246d0..60847fa7 100644 --- a/CMake/abslConfig.cmake.in +++ b/CMake/abslConfig.cmake.in @@ -1,8 +1,7 @@ # absl CMake configuration file. -include(CMakeFindDependencyMacro) -find_dependency(Threads) +include(FindThreads) @PACKAGE_INIT@ -include ("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +include ("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
\ No newline at end of file diff --git a/CMake/install_test_project/CMakeLists.txt b/CMake/install_test_project/CMakeLists.txt index b865b2ec..06b797e9 100644 --- a/CMake/install_test_project/CMakeLists.txt +++ b/CMake/install_test_project/CMakeLists.txt @@ -18,8 +18,10 @@ cmake_minimum_required(VERSION 3.5) project(absl_cmake_testing CXX) +set(CMAKE_CXX_STANDARD 11) + add_executable(simple simple.cc) find_package(absl REQUIRED) -target_link_libraries(simple absl::strings absl::config) +target_link_libraries(simple absl::strings) diff --git a/CMake/install_test_project/simple.cc b/CMake/install_test_project/simple.cc index 7daa7f09..e9e35291 100644 --- a/CMake/install_test_project/simple.cc +++ b/CMake/install_test_project/simple.cc @@ -14,17 +14,8 @@ // limitations under the License. #include <iostream> -#include "absl/base/config.h" #include "absl/strings/substitute.h" -#if !defined(ABSL_LTS_RELEASE_VERSION) || ABSL_LTS_RELEASE_VERSION != 99998877 -#error ABSL_LTS_RELEASE_VERSION is not set correctly. -#endif - -#if !defined(ABSL_LTS_RELEASE_PATCH_LEVEL) || ABSL_LTS_RELEASE_PATCH_LEVEL != 0 -#error ABSL_LTS_RELEASE_PATCH_LEVEL is not set correctly. -#endif - int main(int argc, char** argv) { for (int i = 0; i < argc; ++i) { std::cout << absl::Substitute("Arg $0: $1\n", i, argv[i]); diff --git a/CMake/install_test_project/test.sh b/CMake/install_test_project/test.sh index 5a78c92c..99989b03 100755 --- a/CMake/install_test_project/test.sh +++ b/CMake/install_test_project/test.sh @@ -13,60 +13,70 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# -# Unit and integration tests for Abseil LTS CMake installation + +# "Unit" and integration tests for Absl CMake installation + +# TODO(absl-team): This script isn't fully hermetic because +# -DABSL_USE_GOOGLETEST_HEAD=ON means that this script isn't pinned to a fixed +# version of GoogleTest. This means that an upstream change to GoogleTest could +# break this test. Fix this by allowing this script to pin to a known-good +# version of GoogleTest. # Fail on any error. Treat unset variables an error. Print commands as executed. set -euox pipefail +install_absl() { + pushd "${absl_build_dir}" + if [[ "${#}" -eq 1 ]]; then + cmake -DCMAKE_INSTALL_PREFIX="${1}" "${absl_dir}" + else + cmake "${absl_dir}" + fi + cmake --build . --target install -- -j + popd +} + +uninstall_absl() { + xargs rm < "${absl_build_dir}"/install_manifest.txt + rm -rf "${absl_build_dir}" + mkdir -p "${absl_build_dir}" +} + +lts_install="" + +while getopts ":l" lts; do + case "${lts}" in + l ) + lts_install="true" + ;; + esac +done + absl_dir=/abseil-cpp -absl_build_dir=/buildfs -googletest_builddir=/googletest_builddir +absl_build_dir=/buildfs/absl-build project_dir="${absl_dir}"/CMake/install_test_project project_build_dir=/buildfs/project-build -build_shared_libs="OFF" -if [ "${LINK_TYPE:-}" = "DYNAMIC" ]; then - build_shared_libs="ON" -fi - -# Build and install GoogleTest -mkdir "${googletest_builddir}" -pushd "${googletest_builddir}" -curl -L "${ABSL_GOOGLETEST_DOWNLOAD_URL}" --output "${ABSL_GOOGLETEST_COMMIT}".zip -unzip "${ABSL_GOOGLETEST_COMMIT}".zip -pushd "googletest-${ABSL_GOOGLETEST_COMMIT}" -mkdir build -pushd build -cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS="${build_shared_libs}" .. -make -j $(nproc) -make install -ldconfig -popd -popd -popd +mkdir -p "${absl_build_dir}" +mkdir -p "${project_build_dir}" -# Run the LTS transformations -./create_lts.py 99998877 - -# Build and install Abseil -pushd "${absl_build_dir}" -cmake "${absl_dir}" \ - -DABSL_USE_EXTERNAL_GOOGLETEST=ON \ - -DABSL_FIND_GOOGLETEST=ON \ - -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_TESTING=ON \ - -DBUILD_SHARED_LIBS="${build_shared_libs}" -make -j $(nproc) -ctest -j $(nproc) -make install -ldconfig -popd +if [[ "${lts_install}" ]]; then + install_dir="/usr/local" +else + install_dir="${project_build_dir}"/install +fi +mkdir -p "${install_dir}" -# Test the project against the installed Abseil -mkdir -p "${project_build_dir}" +# Test build, install, and link against installed abseil pushd "${project_build_dir}" -cmake "${project_dir}" +if [[ "${lts_install}" ]]; then + install_absl + cmake "${project_dir}" +else + install_absl "${install_dir}" + cmake "${project_dir}" -DCMAKE_PREFIX_PATH="${install_dir}" +fi + cmake --build . --target simple output="$(${project_build_dir}/simple "printme" 2>&1)" @@ -78,35 +88,57 @@ fi popd -if ! grep absl::strings "/usr/local/lib/cmake/absl/abslTargets.cmake"; then - cat "/usr/local/lib/cmake/absl/abslTargets.cmake" - echo "CMake targets named incorrectly" - exit 1 -fi - -pushd "${HOME}" -cat > hello-abseil.cc << EOF -#include <cstdlib> - -#include "absl/strings/str_format.h" +# Test that we haven't accidentally made absl::abslblah +pushd "${install_dir}" -int main(int argc, char **argv) { - absl::PrintF("Hello Abseil!\n"); - return EXIT_SUCCESS; -} -EOF +# Starting in CMake 3.12 the default install dir is lib$bit_width +if [[ -d lib64 ]]; then + libdir="lib64" +elif [[ -d lib ]]; then + libdir="lib" +else + echo "ls *, */*, */*/*:" + ls * + ls */* + ls */*/* + echo "unknown lib dir" +fi -if [ "${LINK_TYPE:-}" != "DYNAMIC" ]; then - pc_args=($(pkg-config --cflags --libs --static absl_str_format)) - g++ -static -o hello-abseil hello-abseil.cc "${pc_args[@]}" +if [[ "${lts_install}" ]]; then + # LTS versions append the date of the release to the subdir. + # 9999/99/99 is the dummy date used in the local_lts workflow. + absl_subdir="absl_99999999" else - pc_args=($(pkg-config --cflags --libs absl_str_format)) - g++ -o hello-abseil hello-abseil.cc "${pc_args[@]}" + absl_subdir="absl" fi -hello="$(./hello-abseil)" -[[ "${hello}" == "Hello Abseil!" ]] +if ! grep absl::strings "${libdir}/cmake/${absl_subdir}/abslTargets.cmake"; then + cat "${libdir}"/cmake/absl/abslTargets.cmake + echo "CMake targets named incorrectly" + exit 1 +fi + +uninstall_absl popd +if [[ ! "${lts_install}" ]]; then + # Test that we warn if installed without a prefix or a system prefix + output="$(install_absl 2>&1)" + if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then + echo "Install without prefix didn't warn as expected. Output:" + echo "${output}" + exit 1 + fi + uninstall_absl + + output="$(install_absl /usr 2>&1)" + if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then + echo "Install with /usr didn't warn as expected. Output:" + echo "${output}" + exit 1 + fi + uninstall_absl +fi + echo "Install test complete!" exit 0 |