@@ -26,12 +26,6 @@ if(NOT DEFINED ABSL_IDE_FOLDER)
26
26
set (ABSL_IDE_FOLDER Abseil )
27
27
endif ()
28
28
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
-
35
29
# absl_cc_library()
36
30
#
37
31
# CMake function to imitate Bazel's cc_library rule.
@@ -89,9 +83,8 @@ function(absl_cc_library)
89
83
${ARGN}
90
84
)
91
85
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 ))
95
88
return ()
96
89
endif ()
97
90
@@ -132,12 +125,10 @@ function(absl_cc_library)
132
125
if (${ABSL_BUILD_DLL} )
133
126
if (ABSL_ENABLE_INSTALL )
134
127
absl_internal_dll_contains (TARGET ${_NAME} OUTPUT _in_dll )
135
- absl_internal_test_dll_contains (TARGET ${_NAME} OUTPUT _in_test_dll )
136
128
else ()
137
129
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 )
139
130
endif ()
140
- if (${_in_dll} OR ${_in_test_dll} )
131
+ if (${_in_dll} )
141
132
# This target should be replaced by the DLL
142
133
set (_build_type "dll" )
143
134
set (ABSL_CC_LIB_IS_INTERFACE 1 )
@@ -152,55 +143,35 @@ function(absl_cc_library)
152
143
endif ()
153
144
154
145
# 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.
182
157
if (PC_DEPS )
183
158
set (PC_DEPS "${PC_DEPS} ," )
184
159
endif ()
185
160
set (PC_DEPS "${PC_DEPS} absl_${CMAKE_MATCH_1} = ${PC_VERSION} " )
186
161
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 "\
204
175
prefix=${CMAKE_INSTALL_PREFIX} \n\
205
176
exec_prefix=\$ {prefix}\n\
206
177
libdir=${CMAKE_INSTALL_FULL_LIBDIR} \n\
@@ -211,10 +182,11 @@ Description: Abseil ${_NAME} library\n\
211
182
URL: https://abseil.io/\n\
212
183
Version: ${PC_VERSION} \n\
213
184
Requires:${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\
215
186
Cflags: -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 ()
218
190
endif ()
219
191
220
192
if (NOT ABSL_CC_LIB_IS_INTERFACE )
@@ -267,7 +239,7 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
267
239
# unconditionally.
268
240
set_property (TARGET ${_NAME} PROPERTY LINKER_LANGUAGE "CXX" )
269
241
270
- target_include_directories (${_NAME} ${ABSL_INTERNAL_INCLUDE_WARNING_GUARD}
242
+ target_include_directories (${_NAME}
271
243
PUBLIC
272
244
"$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS} >"
273
245
$< INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
@@ -286,10 +258,21 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
286
258
endif ()
287
259
288
260
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 )
293
276
endif ()
294
277
295
278
# When being installed, we lose the absl_ prefix. We want to put it back
@@ -298,13 +281,13 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
298
281
if (ABSL_ENABLE_INSTALL )
299
282
set_target_properties (${_NAME} PROPERTIES
300
283
OUTPUT_NAME "absl_${_NAME} "
301
- SOVERSION "2308 .0.0"
284
+ SOVERSION "2206 .0.0"
302
285
)
303
286
endif ()
304
287
else ()
305
288
# Generating header-only library
306
289
add_library (${_NAME} INTERFACE )
307
- target_include_directories (${_NAME} ${ABSL_INTERNAL_INCLUDE_WARNING_GUARD}
290
+ target_include_directories (${_NAME}
308
291
INTERFACE
309
292
"$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS} >"
310
293
$< INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
@@ -323,14 +306,19 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
323
306
target_compile_definitions (${_NAME} INTERFACE ${ABSL_CC_LIB_DEFINES} )
324
307
325
308
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.
327
310
# Top-level application CMake projects should ensure a consistent C++
328
311
# 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).
330
316
endif ()
331
317
endif ()
332
318
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 )
334
322
install (TARGETS ${_NAME} EXPORT ${PROJECT_NAME} Targets
335
323
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
336
324
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
@@ -396,15 +384,14 @@ function(absl_cc_test)
396
384
target_sources (${_NAME} PRIVATE ${ABSL_CC_TEST_SRCS} )
397
385
target_include_directories (${_NAME}
398
386
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}
400
388
)
401
389
402
390
if (${ABSL_BUILD_DLL} )
403
391
target_compile_definitions (${_NAME}
404
392
PUBLIC
405
393
${ABSL_CC_TEST_DEFINES}
406
394
ABSL_CONSUME_DLL
407
- ABSL_CONSUME_TEST_DLL
408
395
GTEST_LINKED_AS_SHARED_LIBRARY=1
409
396
)
410
397
@@ -413,10 +400,6 @@ function(absl_cc_test)
413
400
DEPS ${ABSL_CC_TEST_DEPS}
414
401
OUTPUT ABSL_CC_TEST_DEPS
415
402
)
416
- absl_internal_dll_targets (
417
- DEPS ${ABSL_CC_TEST_LINKOPTS}
418
- OUTPUT ABSL_CC_TEST_LINKOPTS
419
- )
420
403
else ()
421
404
target_compile_definitions (${_NAME}
422
405
PUBLIC
@@ -435,11 +418,30 @@ function(absl_cc_test)
435
418
set_property (TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER} /test )
436
419
437
420
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.
439
422
# Top-level application CMake projects should ensure a consistent C++
440
423
# 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 )
442
436
endif ()
443
437
444
438
add_test (NAME ${_NAME} COMMAND ${_NAME} )
445
439
endfunction ()
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