Skip to content

Commit fd12fac

Browse files
authored
Update to abseil-cpp source tag 20211102.0 (#8)
1 parent fffc3c2 commit fd12fac

File tree

1,149 files changed

+32026
-89816
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,149 files changed

+32026
-89816
lines changed

CMakeLists.txt

Lines changed: 84 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,36 @@
2222
cmake_minimum_required(VERSION 3.5)
2323

2424
# Compiler id for Apple Clang is now AppleClang.
25-
cmake_policy(SET CMP0025 NEW)
25+
if (POLICY CMP0025)
26+
cmake_policy(SET CMP0025 NEW)
27+
endif (POLICY CMP0025)
2628

2729
# if command can use IN_LIST
28-
cmake_policy(SET CMP0057 NEW)
30+
if (POLICY CMP0057)
31+
cmake_policy(SET CMP0057 NEW)
32+
endif (POLICY CMP0057)
2933

3034
# Project version variables are the empty string if version is unspecified
31-
cmake_policy(SET CMP0048 NEW)
35+
if (POLICY CMP0048)
36+
cmake_policy(SET CMP0048 NEW)
37+
endif (POLICY CMP0048)
3238

33-
project(absl CXX)
39+
# option() honor variables
40+
if (POLICY CMP0077)
41+
cmake_policy(SET CMP0077 NEW)
42+
endif (POLICY CMP0077)
43+
44+
# Allow the user to specify the MSVC runtime
45+
if (POLICY CMP0091)
46+
cmake_policy(SET CMP0091 NEW)
47+
endif (POLICY CMP0091)
48+
49+
# Set BUILD_TESTING to OFF by default.
50+
# This must come before the project() and include(CTest) lines.
51+
OPTION(BUILD_TESTING "Build tests" OFF)
52+
53+
project(absl LANGUAGES CXX VERSION 20211102)
54+
include(CTest)
3455

3556
# Output directory is correct by default for most build setups. However, when
3657
# building Abseil as a DLL, it is important to have the DLL in the same
@@ -40,19 +61,26 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
4061

4162
# when absl is included as subproject (i.e. using add_subdirectory(abseil-cpp))
4263
# in the source tree of a project that uses it, install rules are disabled.
43-
if(NOT "^${CMAKE_SOURCE_DIR}$" STREQUAL "^${PROJECT_SOURCE_DIR}$")
44-
set(ABSL_ENABLE_INSTALL FALSE)
64+
if(NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
65+
option(ABSL_ENABLE_INSTALL "Enable install rule" OFF)
4566
else()
46-
set(ABSL_ENABLE_INSTALL TRUE)
67+
option(ABSL_ENABLE_INSTALL "Enable install rule" ON)
68+
endif()
69+
70+
option(ABSL_PROPAGATE_CXX_STD
71+
"Use CMake C++ standard meta features (e.g. cxx_std_11) that propagate to targets that link to Abseil"
72+
OFF) # TODO: Default to ON for CMake 3.8 and greater.
73+
if((${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.8) AND (NOT ABSL_PROPAGATE_CXX_STD))
74+
message(WARNING "A future Abseil release will default ABSL_PROPAGATE_CXX_STD to ON for CMake 3.8 and up. We recommend enabling this option to ensure your project still builds correctly.")
4775
endif()
4876

4977
list(APPEND CMAKE_MODULE_PATH
5078
${CMAKE_CURRENT_LIST_DIR}/CMake
5179
${CMAKE_CURRENT_LIST_DIR}/absl/copts
5280
)
5381

54-
include(AbseilInstallDirs)
5582
include(CMakePackageConfigHelpers)
83+
include(GNUInstallDirs)
5684
include(AbseilDll)
5785
include(AbseilHelpers)
5886

@@ -81,75 +109,87 @@ endif()
81109
## pthread
82110
find_package(Threads REQUIRED)
83111

112+
include(CMakeDependentOption)
113+
84114
option(ABSL_USE_EXTERNAL_GOOGLETEST
85115
"If ON, Abseil will assume that the targets for GoogleTest are already provided by the including project. This makes sense when Abseil is used with add_subproject." OFF)
86116

117+
cmake_dependent_option(ABSL_FIND_GOOGLETEST
118+
"If ON, Abseil will use find_package(GTest) rather than assuming that GoogleTest is already provided by the including project."
119+
ON
120+
"ABSL_USE_EXTERNAL_GOOGLETEST"
121+
OFF)
122+
87123

88124
option(ABSL_USE_GOOGLETEST_HEAD
89-
"If ON, abseil will download HEAD from googletest at config time." OFF)
125+
"If ON, abseil will download HEAD from GoogleTest at config time." OFF)
126+
127+
set(ABSL_GOOGLETEST_DOWNLOAD_URL "" CACHE STRING "If set, download GoogleTest from this URL")
90128

91129
set(ABSL_LOCAL_GOOGLETEST_DIR "/usr/src/googletest" CACHE PATH
92-
"If ABSL_USE_GOOGLETEST_HEAD is OFF, specifies the directory of a local googletest checkout."
130+
"If ABSL_USE_GOOGLETEST_HEAD is OFF and ABSL_GOOGLETEST_URL is not set, specifies the directory of a local GoogleTest checkout."
93131
)
94132

95-
option(ABSL_RUN_TESTS "If ON, Abseil tests will be run." OFF)
96-
97-
if(${ABSL_RUN_TESTS})
98-
# enable CTest. This will set BUILD_TESTING to ON unless otherwise specified
99-
# on the command line
100-
include(CTest)
101-
133+
if(BUILD_TESTING)
102134
## check targets
103-
if (NOT ABSL_USE_EXTERNAL_GOOGLETEST)
135+
if (ABSL_USE_EXTERNAL_GOOGLETEST)
136+
if (ABSL_FIND_GOOGLETEST)
137+
find_package(GTest REQUIRED)
138+
else()
139+
if (NOT TARGET gtest AND NOT TARGET GTest::gtest)
140+
message(FATAL_ERROR "ABSL_USE_EXTERNAL_GOOGLETEST is ON and ABSL_FIND_GOOGLETEST is OFF, which means that the top-level project must build the Google Test project. However, the target gtest was not found.")
141+
endif()
142+
endif()
143+
else()
104144
set(absl_gtest_build_dir ${CMAKE_BINARY_DIR}/googletest-build)
105-
if(${ABSL_USE_GOOGLETEST_HEAD})
145+
if(ABSL_USE_GOOGLETEST_HEAD AND ABSL_GOOGLETEST_DOWNLOAD_URL)
146+
message(FATAL_ERROR "Do not set both ABSL_USE_GOOGLETEST_HEAD and ABSL_GOOGLETEST_DOWNLOAD_URL")
147+
endif()
148+
if(ABSL_USE_GOOGLETEST_HEAD)
149+
set(absl_gtest_download_url "https://github.com/google/googletest/archive/master.zip")
150+
elseif(ABSL_GOOGLETEST_DOWNLOAD_URL)
151+
set(absl_gtest_download_url ${ABSL_GOOGLETEST_DOWNLOAD_URL})
152+
endif()
153+
if(absl_gtest_download_url)
106154
set(absl_gtest_src_dir ${CMAKE_BINARY_DIR}/googletest-src)
107155
else()
108156
set(absl_gtest_src_dir ${ABSL_LOCAL_GOOGLETEST_DIR})
109157
endif()
110158
include(CMake/Googletest/DownloadGTest.cmake)
111159
endif()
112160

113-
check_target(gtest)
114-
check_target(gtest_main)
115-
check_target(gmock)
161+
if (NOT ABSL_FIND_GOOGLETEST)
162+
# When Google Test is included directly rather than through find_package, the aliases are missing.
163+
add_library(GTest::gtest ALIAS gtest)
164+
add_library(GTest::gtest_main ALIAS gtest_main)
165+
add_library(GTest::gmock ALIAS gmock)
166+
add_library(GTest::gmock_main ALIAS gmock_main)
167+
endif()
116168

117-
list(APPEND ABSL_TEST_COMMON_LIBRARIES
118-
gtest_main
119-
gtest
120-
gmock
121-
${CMAKE_THREAD_LIBS_INIT}
122-
)
169+
check_target(GTest::gtest)
170+
check_target(GTest::gtest_main)
171+
check_target(GTest::gmock)
172+
check_target(GTest::gmock_main)
123173
endif()
124174

125175
add_subdirectory(absl)
126176

127177
if(ABSL_ENABLE_INSTALL)
128-
# absl:lts-remove-begin(system installation is supported for LTS releases)
129-
# We don't support system-wide installation
130-
list(APPEND SYSTEM_INSTALL_DIRS "/usr/local" "/usr" "/opt/" "/opt/local" "c:/Program Files/${PROJECT_NAME}")
131-
if(NOT DEFINED CMAKE_INSTALL_PREFIX OR CMAKE_INSTALL_PREFIX IN_LIST SYSTEM_INSTALL_DIRS)
132-
message(WARNING "\
133-
The default and system-level install directories are unsupported except in LTS \
134-
releases of Abseil. Please set CMAKE_INSTALL_PREFIX to install Abseil in your \
135-
source or build tree directly.\
136-
")
137-
endif()
138-
# absl:lts-remove-end
178+
139179

140180
# install as a subdirectory only
141181
install(EXPORT ${PROJECT_NAME}Targets
142182
NAMESPACE absl::
143-
DESTINATION "${ABSL_INSTALL_CONFIGDIR}"
183+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
144184
)
145185

146186
configure_package_config_file(
147187
CMake/abslConfig.cmake.in
148188
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
149-
INSTALL_DESTINATION "${ABSL_INSTALL_CONFIGDIR}"
189+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
150190
)
151191
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
152-
DESTINATION "${ABSL_INSTALL_CONFIGDIR}"
192+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
153193
)
154194

155195
# Abseil only has a version in LTS releases. This mechanism is accomplished
@@ -162,12 +202,12 @@ if(ABSL_ENABLE_INSTALL)
162202
)
163203

164204
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
165-
DESTINATION ${ABSL_INSTALL_CONFIGDIR}
205+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
166206
)
167207
endif() # absl_VERSION
168208

169209
install(DIRECTORY absl
170-
DESTINATION ${ABSL_INSTALL_INCLUDEDIR}
210+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
171211
FILES_MATCHING
172212
PATTERN "*.inc"
173213
PATTERN "*.h"

FAQ.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ compiler, there several ways to do this:
2727
file](https://docs.bazel.build/versions/master/guide.html#bazelrc)
2828

2929
If you are using CMake as the build system, you'll need to add a line like
30-
`set(CMAKE_CXX_STANDARD 17)` to your top level `CMakeLists.txt` file. See the
30+
`set(CMAKE_CXX_STANDARD 17)` to your top level `CMakeLists.txt` file. If you
31+
are developing a library designed to be used by other clients, you should
32+
instead leave `CMAKE_CXX_STANDARD` unset and configure the minimum C++ standard
33+
required by each of your library targets via `target_compile_features`. See the
3134
[CMake build
3235
instructions](https://github.com/abseil/abseil-cpp/blob/master/CMake/README.md)
3336
for more information.

0 commit comments

Comments
 (0)