@@ -26,12 +26,6 @@ if(NOT DEFINED ABSL_IDE_FOLDER)
2626 set (ABSL_IDE_FOLDER Abseil)
2727endif ()
2828
29- if (ABSL_USE_SYSTEM_INCLUDES)
30- set (ABSL_INTERNAL_INCLUDE_WARNING_GUARD SYSTEM )
31- else ()
32- set (ABSL_INTERNAL_INCLUDE_WARNING_GUARD "" )
33- endif ()
34-
3529# absl_cc_library()
3630#
3731# CMake function to imitate Bazel's cc_library rule.
@@ -89,9 +83,8 @@ function(absl_cc_library)
8983 ${ARGN}
9084 )
9185
92- if (ABSL_CC_LIB_TESTONLY AND
93- NOT ((BUILD_TESTING AND ABSL_BUILD_TESTING) OR
94- (ABSL_BUILD_TEST_HELPERS AND ABSL_CC_LIB_PUBLIC)))
86+ if (NOT ABSL_CC_LIB_PUBLIC AND ABSL_CC_LIB_TESTONLY AND
87+ NOT (BUILD_TESTING AND ABSL_BUILD_TESTING))
9588 return ()
9689 endif ()
9790
@@ -132,12 +125,10 @@ function(absl_cc_library)
132125 if (${ABSL_BUILD_DLL} )
133126 if (ABSL_ENABLE_INSTALL)
134127 absl_internal_dll_contains(TARGET ${_NAME} OUTPUT _in_dll)
135- absl_internal_test_dll_contains(TARGET ${_NAME} OUTPUT _in_test_dll)
136128 else ()
137129 absl_internal_dll_contains(TARGET ${ABSL_CC_LIB_NAME} OUTPUT _in_dll)
138- absl_internal_test_dll_contains(TARGET ${ABSL_CC_LIB_NAME} OUTPUT _in_test_dll)
139130 endif ()
140- if (${_in_dll} OR ${_in_test_dll} )
131+ if (${_in_dll} )
141132 # This target should be replaced by the DLL
142133 set (_build_type "dll" )
143134 set (ABSL_CC_LIB_IS_INTERFACE 1)
@@ -152,55 +143,35 @@ function(absl_cc_library)
152143 endif ()
153144
154145 # Generate a pkg-config file for every library:
155- if (ABSL_ENABLE_INSTALL)
156- if (absl_VERSION)
157- set (PC_VERSION "${absl_VERSION} " )
158- else ()
159- set (PC_VERSION "head" )
160- endif ()
161- if (NOT _build_type STREQUAL "dll" )
162- set (LNK_LIB "${LNK_LIB} -labsl_${_NAME} " )
163- endif ()
164- foreach (dep ${ABSL_CC_LIB_DEPS} )
165- if (${dep} MATCHES "^absl::(.*)" )
166- # for DLL builds many libs are not created, but add
167- # the pkgconfigs nevertheless, pointing to the dll.
168- if (_build_type STREQUAL "dll" )
169- # hide this MATCHES in an if-clause so it doesn't overwrite
170- # the CMAKE_MATCH_1 from (${dep} MATCHES "^absl::(.*)")
171- if (NOT PC_DEPS MATCHES "abseil_dll" )
172- # Join deps with commas.
173- if (PC_DEPS)
174- set (PC_DEPS "${PC_DEPS} ," )
175- endif ()
176- # don't duplicate dll-dep if it exists already
177- set (PC_DEPS "${PC_DEPS} abseil_dll = ${PC_VERSION} " )
178- set (LNK_LIB "${LNK_LIB} -labseil_dll" )
179- endif ()
180- else ()
181- # Join deps with commas.
146+ if ((_build_type STREQUAL "static" OR _build_type STREQUAL "shared" )
147+ AND ABSL_ENABLE_INSTALL)
148+ if (NOT ABSL_CC_LIB_TESTONLY)
149+ if (absl_VERSION)
150+ set (PC_VERSION "${absl_VERSION} " )
151+ else ()
152+ set (PC_VERSION "head" )
153+ endif ()
154+ foreach (dep ${ABSL_CC_LIB_DEPS} )
155+ if (${dep} MATCHES "^absl::(.*)" )
156+ # Join deps with commas.
182157 if (PC_DEPS)
183158 set (PC_DEPS "${PC_DEPS} ," )
184159 endif ()
185160 set (PC_DEPS "${PC_DEPS} absl_${CMAKE_MATCH_1} = ${PC_VERSION} " )
186161 endif ()
187- endif ()
188- endforeach ()
189- foreach (cflag ${ABSL_CC_LIB_COPTS} )
190- if (${cflag} MATCHES "^(-Wno|/wd)" )
191- # These flags are needed to suppress warnings that might fire in our headers.
192- set (PC_CFLAGS "${PC_CFLAGS} ${cflag} " )
193- elseif (${cflag} MATCHES "^(-W|/w[1234eo])" )
194- # Don't impose our warnings on others.
195- elseif (${cflag} MATCHES "^-m" )
196- # Don't impose CPU instruction requirements on others, as
197- # the code performs feature detection on runtime.
198- else ()
199- set (PC_CFLAGS "${PC_CFLAGS} ${cflag} " )
200- endif ()
201- endforeach ()
202- string (REPLACE ";" " " PC_LINKOPTS "${ABSL_CC_LIB_LINKOPTS} " )
203- FILE (GENERATE OUTPUT "${CMAKE_BINARY_DIR} /lib/pkgconfig/absl_${_NAME} .pc" CONTENT "\
162+ endforeach ()
163+ foreach (cflag ${ABSL_CC_LIB_COPTS} )
164+ if (${cflag} MATCHES "^(-Wno|/wd)" )
165+ # These flags are needed to suppress warnings that might fire in our headers.
166+ set (PC_CFLAGS "${PC_CFLAGS} ${cflag} " )
167+ elseif (${cflag} MATCHES "^(-W|/w[1234eo])" )
168+ # Don't impose our warnings on others.
169+ else ()
170+ set (PC_CFLAGS "${PC_CFLAGS} ${cflag} " )
171+ endif ()
172+ endforeach ()
173+ string (REPLACE ";" " " PC_LINKOPTS "${ABSL_CC_LIB_LINKOPTS} " )
174+ FILE (GENERATE OUTPUT "${CMAKE_BINARY_DIR} /lib/pkgconfig/absl_${_NAME} .pc" CONTENT "\
204175prefix=${CMAKE_INSTALL_PREFIX} \n\
205176exec_prefix=\$ {prefix}\n\
206177libdir=${CMAKE_INSTALL_FULL_LIBDIR} \n\
@@ -211,10 +182,11 @@ Description: Abseil ${_NAME} library\n\
211182URL: https://abseil.io/\n\
212183Version: ${PC_VERSION} \n\
213184Requires:${PC_DEPS} \n\
214- Libs: -L\$ {libdir} $<$<NOT:$<BOOL:${ABSL_CC_LIB_IS_INTERFACE} >>:${LNK_LIB} > ${PC_LINKOPTS} \n\
185+ Libs: -L\$ {libdir} ${PC_LINKOPTS} $ <$<NOT:$<BOOL:${ABSL_CC_LIB_IS_INTERFACE} >>:-labsl_ ${_NAME} > \n\
215186Cflags: -I\$ {includedir}${PC_CFLAGS} \n " )
216- INSTALL (FILES "${CMAKE_BINARY_DIR} /lib/pkgconfig/absl_${_NAME} .pc"
217- DESTINATION "${CMAKE_INSTALL_LIBDIR} /pkgconfig" )
187+ INSTALL (FILES "${CMAKE_BINARY_DIR} /lib/pkgconfig/absl_${_NAME} .pc"
188+ DESTINATION "${CMAKE_INSTALL_LIBDIR} /pkgconfig" )
189+ endif ()
218190 endif ()
219191
220192 if (NOT ABSL_CC_LIB_IS_INTERFACE)
@@ -267,7 +239,7 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
267239 # unconditionally.
268240 set_property (TARGET ${_NAME} PROPERTY LINKER_LANGUAGE "CXX" )
269241
270- target_include_directories (${_NAME} ${ABSL_INTERNAL_INCLUDE_WARNING_GUARD}
242+ target_include_directories (${_NAME}
271243 PUBLIC
272244 "$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS} >"
273245 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
@@ -286,10 +258,21 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
286258 endif ()
287259
288260 if (ABSL_PROPAGATE_CXX_STD)
289- # Abseil libraries require C++14 as the current minimum standard. When
290- # compiled with C++17 (either because it is the compiler's default or
291- # explicitly requested), then Abseil requires C++17.
292- target_compile_features (${_NAME} PUBLIC ${ABSL_INTERNAL_CXX_STD_FEATURE} )
261+ # Abseil libraries require C++11 as the current minimum standard.
262+ # Top-level application CMake projects should ensure a consistent C++
263+ # standard for all compiled sources by setting CMAKE_CXX_STANDARD.
264+ target_compile_features (${_NAME} PUBLIC cxx_std_11)
265+ else ()
266+ # Note: This is legacy (before CMake 3.8) behavior. Setting the
267+ # target-level CXX_STANDARD property to ABSL_CXX_STANDARD (which is
268+ # initialized by CMAKE_CXX_STANDARD) should have no real effect, since
269+ # that is the default value anyway.
270+ #
271+ # CXX_STANDARD_REQUIRED does guard against the top-level CMake project
272+ # not having enabled CMAKE_CXX_STANDARD_REQUIRED (which prevents
273+ # "decaying" to an older standard if the requested one isn't available).
274+ set_property (TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD} )
275+ set_property (TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON )
293276 endif ()
294277
295278 # When being installed, we lose the absl_ prefix. We want to put it back
@@ -298,13 +281,13 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
298281 if (ABSL_ENABLE_INSTALL)
299282 set_target_properties (${_NAME} PROPERTIES
300283 OUTPUT_NAME "absl_${_NAME} "
301- SOVERSION "2308 .0.0"
284+ SOVERSION "2206 .0.0"
302285 )
303286 endif ()
304287 else ()
305288 # Generating header-only library
306289 add_library (${_NAME} INTERFACE )
307- target_include_directories (${_NAME} ${ABSL_INTERNAL_INCLUDE_WARNING_GUARD}
290+ target_include_directories (${_NAME}
308291 INTERFACE
309292 "$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS} >"
310293 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
@@ -323,14 +306,19 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
323306 target_compile_definitions (${_NAME} INTERFACE ${ABSL_CC_LIB_DEFINES} )
324307
325308 if (ABSL_PROPAGATE_CXX_STD)
326- # Abseil libraries require C++14 as the current minimum standard.
309+ # Abseil libraries require C++11 as the current minimum standard.
327310 # Top-level application CMake projects should ensure a consistent C++
328311 # standard for all compiled sources by setting CMAKE_CXX_STANDARD.
329- target_compile_features (${_NAME} INTERFACE ${ABSL_INTERNAL_CXX_STD_FEATURE} )
312+ target_compile_features (${_NAME} INTERFACE cxx_std_11)
313+
314+ # (INTERFACE libraries can't have the CXX_STANDARD property set, so there
315+ # is no legacy behavior else case).
330316 endif ()
331317 endif ()
332318
333- if (ABSL_ENABLE_INSTALL)
319+ # TODO currently we don't install googletest alongside abseil sources, so
320+ # installed abseil can't be tested.
321+ if (NOT ABSL_CC_LIB_TESTONLY AND ABSL_ENABLE_INSTALL)
334322 install (TARGETS ${_NAME} EXPORT ${PROJECT_NAME} Targets
335323 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
336324 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -396,15 +384,14 @@ function(absl_cc_test)
396384 target_sources (${_NAME} PRIVATE ${ABSL_CC_TEST_SRCS} )
397385 target_include_directories (${_NAME}
398386 PUBLIC ${ABSL_COMMON_INCLUDE_DIRS}
399- PRIVATE ${absl_gtest_src_dir} /googletest/ include ${absl_gtest_src_dir} /googlemock/ include
387+ PRIVATE ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}
400388 )
401389
402390 if (${ABSL_BUILD_DLL} )
403391 target_compile_definitions (${_NAME}
404392 PUBLIC
405393 ${ABSL_CC_TEST_DEFINES}
406394 ABSL_CONSUME_DLL
407- ABSL_CONSUME_TEST_DLL
408395 GTEST_LINKED_AS_SHARED_LIBRARY=1
409396 )
410397
@@ -413,10 +400,6 @@ function(absl_cc_test)
413400 DEPS ${ABSL_CC_TEST_DEPS}
414401 OUTPUT ABSL_CC_TEST_DEPS
415402 )
416- absl_internal_dll_targets(
417- DEPS ${ABSL_CC_TEST_LINKOPTS}
418- OUTPUT ABSL_CC_TEST_LINKOPTS
419- )
420403 else ()
421404 target_compile_definitions (${_NAME}
422405 PUBLIC
@@ -435,11 +418,30 @@ function(absl_cc_test)
435418 set_property (TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER} /test )
436419
437420 if (ABSL_PROPAGATE_CXX_STD)
438- # Abseil libraries require C++14 as the current minimum standard.
421+ # Abseil libraries require C++11 as the current minimum standard.
439422 # Top-level application CMake projects should ensure a consistent C++
440423 # standard for all compiled sources by setting CMAKE_CXX_STANDARD.
441- target_compile_features (${_NAME} PUBLIC ${ABSL_INTERNAL_CXX_STD_FEATURE} )
424+ target_compile_features (${_NAME} PUBLIC cxx_std_11)
425+ else ()
426+ # Note: This is legacy (before CMake 3.8) behavior. Setting the
427+ # target-level CXX_STANDARD property to ABSL_CXX_STANDARD (which is
428+ # initialized by CMAKE_CXX_STANDARD) should have no real effect, since
429+ # that is the default value anyway.
430+ #
431+ # CXX_STANDARD_REQUIRED does guard against the top-level CMake project
432+ # not having enabled CMAKE_CXX_STANDARD_REQUIRED (which prevents
433+ # "decaying" to an older standard if the requested one isn't available).
434+ set_property (TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD} )
435+ set_property (TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON )
442436 endif ()
443437
444438 add_test (NAME ${_NAME} COMMAND ${_NAME} )
445439endfunction ()
440+
441+
442+ function (check_target my_target)
443+ if (NOT TARGET ${my_target} )
444+ message (FATAL_ERROR " ABSL: compiling absl requires a ${my_target} CMake target in your project,
445+ see CMake/README.md for more details" )
446+ endif (NOT TARGET ${my_target} )
447+ endfunction ()
0 commit comments