@@ -26,6 +26,12 @@ 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+
2935# absl_cc_library()
3036#
3137# CMake function to imitate Bazel's cc_library rule.
@@ -83,8 +89,9 @@ function(absl_cc_library)
8389 ${ARGN}
8490 )
8591
86- if (NOT ABSL_CC_LIB_PUBLIC AND ABSL_CC_LIB_TESTONLY AND
87- NOT (BUILD_TESTING AND ABSL_BUILD_TESTING))
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)))
8895 return ()
8996 endif ()
9097
@@ -125,10 +132,12 @@ function(absl_cc_library)
125132 if (${ABSL_BUILD_DLL} )
126133 if (ABSL_ENABLE_INSTALL)
127134 absl_internal_dll_contains(TARGET ${_NAME} OUTPUT _in_dll)
135+ absl_internal_test_dll_contains(TARGET ${_NAME} OUTPUT _in_test_dll)
128136 else ()
129137 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)
130139 endif ()
131- if (${_in_dll} )
140+ if (${_in_dll} OR ${_in_test_dll} )
132141 # This target should be replaced by the DLL
133142 set (_build_type "dll" )
134143 set (ABSL_CC_LIB_IS_INTERFACE 1)
@@ -143,35 +152,55 @@ function(absl_cc_library)
143152 endif ()
144153
145154 # Generate a pkg-config file for every library:
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.
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.
157182 if (PC_DEPS)
158183 set (PC_DEPS "${PC_DEPS} ," )
159184 endif ()
160185 set (PC_DEPS "${PC_DEPS} absl_${CMAKE_MATCH_1} = ${PC_VERSION} " )
161186 endif ()
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 "\
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 "\
175204prefix=${CMAKE_INSTALL_PREFIX} \n\
176205exec_prefix=\$ {prefix}\n\
177206libdir=${CMAKE_INSTALL_FULL_LIBDIR} \n\
@@ -182,11 +211,10 @@ Description: Abseil ${_NAME} library\n\
182211URL: https://abseil.io/\n\
183212Version: ${PC_VERSION} \n\
184213Requires:${PC_DEPS} \n\
185- Libs: -L\$ {libdir} ${PC_LINKOPTS} $ <$<NOT:$<BOOL:${ABSL_CC_LIB_IS_INTERFACE} >>:-labsl_ ${_NAME} > \n\
214+ Libs: -L\$ {libdir} $<$<NOT:$<BOOL:${ABSL_CC_LIB_IS_INTERFACE} >>:${LNK_LIB} > ${PC_LINKOPTS} \n\
186215Cflags: -I\$ {includedir}${PC_CFLAGS} \n " )
187- INSTALL (FILES "${CMAKE_BINARY_DIR} /lib/pkgconfig/absl_${_NAME} .pc"
188- DESTINATION "${CMAKE_INSTALL_LIBDIR} /pkgconfig" )
189- endif ()
216+ INSTALL (FILES "${CMAKE_BINARY_DIR} /lib/pkgconfig/absl_${_NAME} .pc"
217+ DESTINATION "${CMAKE_INSTALL_LIBDIR} /pkgconfig" )
190218 endif ()
191219
192220 if (NOT ABSL_CC_LIB_IS_INTERFACE)
@@ -239,7 +267,7 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
239267 # unconditionally.
240268 set_property (TARGET ${_NAME} PROPERTY LINKER_LANGUAGE "CXX" )
241269
242- target_include_directories (${_NAME}
270+ target_include_directories (${_NAME} ${ABSL_INTERNAL_INCLUDE_WARNING_GUARD}
243271 PUBLIC
244272 "$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS} >"
245273 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
@@ -258,21 +286,10 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
258286 endif ()
259287
260288 if (ABSL_PROPAGATE_CXX_STD)
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 )
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} )
276293 endif ()
277294
278295 # When being installed, we lose the absl_ prefix. We want to put it back
@@ -281,13 +298,13 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
281298 if (ABSL_ENABLE_INSTALL)
282299 set_target_properties (${_NAME} PROPERTIES
283300 OUTPUT_NAME "absl_${_NAME} "
284- SOVERSION "2206 .0.0"
301+ SOVERSION "2308 .0.0"
285302 )
286303 endif ()
287304 else ()
288305 # Generating header-only library
289306 add_library (${_NAME} INTERFACE )
290- target_include_directories (${_NAME}
307+ target_include_directories (${_NAME} ${ABSL_INTERNAL_INCLUDE_WARNING_GUARD}
291308 INTERFACE
292309 "$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS} >"
293310 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
@@ -306,19 +323,14 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
306323 target_compile_definitions (${_NAME} INTERFACE ${ABSL_CC_LIB_DEFINES} )
307324
308325 if (ABSL_PROPAGATE_CXX_STD)
309- # Abseil libraries require C++11 as the current minimum standard.
326+ # Abseil libraries require C++14 as the current minimum standard.
310327 # Top-level application CMake projects should ensure a consistent C++
311328 # standard for all compiled sources by setting CMAKE_CXX_STANDARD.
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).
329+ target_compile_features (${_NAME} INTERFACE ${ABSL_INTERNAL_CXX_STD_FEATURE} )
316330 endif ()
317331 endif ()
318332
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)
333+ if (ABSL_ENABLE_INSTALL)
322334 install (TARGETS ${_NAME} EXPORT ${PROJECT_NAME} Targets
323335 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
324336 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -384,14 +396,15 @@ function(absl_cc_test)
384396 target_sources (${_NAME} PRIVATE ${ABSL_CC_TEST_SRCS} )
385397 target_include_directories (${_NAME}
386398 PUBLIC ${ABSL_COMMON_INCLUDE_DIRS}
387- PRIVATE ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}
399+ PRIVATE ${absl_gtest_src_dir} /googletest/ include ${absl_gtest_src_dir} /googlemock/ include
388400 )
389401
390402 if (${ABSL_BUILD_DLL} )
391403 target_compile_definitions (${_NAME}
392404 PUBLIC
393405 ${ABSL_CC_TEST_DEFINES}
394406 ABSL_CONSUME_DLL
407+ ABSL_CONSUME_TEST_DLL
395408 GTEST_LINKED_AS_SHARED_LIBRARY=1
396409 )
397410
@@ -400,6 +413,10 @@ function(absl_cc_test)
400413 DEPS ${ABSL_CC_TEST_DEPS}
401414 OUTPUT ABSL_CC_TEST_DEPS
402415 )
416+ absl_internal_dll_targets(
417+ DEPS ${ABSL_CC_TEST_LINKOPTS}
418+ OUTPUT ABSL_CC_TEST_LINKOPTS
419+ )
403420 else ()
404421 target_compile_definitions (${_NAME}
405422 PUBLIC
@@ -418,30 +435,11 @@ function(absl_cc_test)
418435 set_property (TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER} /test )
419436
420437 if (ABSL_PROPAGATE_CXX_STD)
421- # Abseil libraries require C++11 as the current minimum standard.
438+ # Abseil libraries require C++14 as the current minimum standard.
422439 # Top-level application CMake projects should ensure a consistent C++
423440 # standard for all compiled sources by setting CMAKE_CXX_STANDARD.
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 )
441+ target_compile_features (${_NAME} PUBLIC ${ABSL_INTERNAL_CXX_STD_FEATURE} )
436442 endif ()
437443
438444 add_test (NAME ${_NAME} COMMAND ${_NAME} )
439445endfunction ()
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