Skip to content

Commit 09d1074

Browse files
committed
Merge branch 'abseil-mirror' into merge
2 parents b00733d + f75dc2d commit 09d1074

File tree

489 files changed

+14027
-6356
lines changed

Some content is hidden

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

489 files changed

+14027
-6356
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: Google
4+
...

Firestore/third_party/abseil-cpp/CMake/AbseilHelpers.cmake

Lines changed: 131 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# you may not use this file except in compliance with the License.
66
# You may obtain a copy of the License at
77
#
8-
# http://www.apache.org/licenses/LICENSE-2.0
8+
# https://www.apache.org/licenses/LICENSE-2.0
99
#
1010
# Unless required by applicable law or agreed to in writing, software
1111
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,53 +15,16 @@
1515
#
1616

1717
include(CMakeParseArguments)
18+
include(AbseilConfigureCopts)
19+
include(AbseilInstallDirs)
1820

1921
# The IDE folder for Abseil that will be used if Abseil is included in a CMake
2022
# project that sets
2123
# set_property(GLOBAL PROPERTY USE_FOLDERS ON)
2224
# For example, Visual Studio supports folders.
2325
set(ABSL_IDE_FOLDER Abseil)
2426

25-
#
26-
# create a library in the absl namespace
27-
#
28-
# parameters
29-
# SOURCES : sources files for the library
30-
# PUBLIC_LIBRARIES: targets and flags for linking phase
31-
# PRIVATE_COMPILE_FLAGS: compile flags for the library. Will not be exported.
32-
# EXPORT_NAME: export name for the absl:: target export
33-
# TARGET: target name
34-
#
35-
# create a target associated to <NAME>
36-
# libraries are installed under CMAKE_INSTALL_FULL_LIBDIR by default
37-
#
38-
function(absl_library)
39-
cmake_parse_arguments(ABSL_LIB
40-
"DISABLE_INSTALL" # keep that in case we want to support installation one day
41-
"TARGET;EXPORT_NAME"
42-
"SOURCES;PUBLIC_LIBRARIES;PRIVATE_COMPILE_FLAGS"
43-
${ARGN}
44-
)
45-
46-
set(_NAME ${ABSL_LIB_TARGET})
47-
string(TOUPPER ${_NAME} _UPPER_NAME)
48-
49-
add_library(${_NAME} STATIC ${ABSL_LIB_SOURCES})
50-
51-
target_compile_options(${_NAME} PRIVATE ${ABSL_LIB_PRIVATE_COMPILE_FLAGS})
52-
target_link_libraries(${_NAME} PUBLIC ${ABSL_LIB_PUBLIC_LIBRARIES})
53-
target_include_directories(${_NAME}
54-
PUBLIC ${ABSL_COMMON_INCLUDE_DIRS} ${ABSL_LIB_PUBLIC_INCLUDE_DIRS}
55-
PRIVATE ${ABSL_LIB_PRIVATE_INCLUDE_DIRS}
56-
)
57-
# Add all Abseil targets to a a folder in the IDE for organization.
58-
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER})
59-
60-
if(ABSL_LIB_EXPORT_NAME)
61-
add_library(absl::${ABSL_LIB_EXPORT_NAME} ALIAS ${_NAME})
62-
endif()
63-
endfunction()
64-
27+
# absl_cc_library()
6528
#
6629
# CMake function to imitate Bazel's cc_library rule.
6730
#
@@ -73,18 +36,18 @@ endfunction()
7336
# COPTS: List of private compile options
7437
# DEFINES: List of public defines
7538
# LINKOPTS: List of link options
76-
# PUBLIC: Add this so that this library will be exported under absl:: (see Note).
39+
# PUBLIC: Add this so that this library will be exported under absl::
40+
# Also in IDE, target will appear in Abseil folder while non PUBLIC will be in Abseil/internal.
7741
# TESTONLY: When added, this target will only be built if user passes -DABSL_RUN_TESTS=ON to CMake.
7842
#
7943
# Note:
80-
#
81-
# By default, absl_cc_library will always create a library named absl_internal_${NAME},
82-
# which means other targets can only depend this library as absl_internal_${NAME}, not ${NAME}.
44+
# By default, absl_cc_library will always create a library named absl_${NAME},
45+
# and alias target absl::${NAME}. The absl:: form should always be used.
8346
# This is to reduce namespace pollution.
8447
#
8548
# absl_cc_library(
8649
# NAME
87-
# awesome_lib
50+
# awesome
8851
# HDRS
8952
# "a.h"
9053
# SRCS
@@ -96,23 +59,19 @@ endfunction()
9659
# SRCS
9760
# "b.cc"
9861
# DEPS
99-
# absl_internal_awesome_lib # not "awesome_lib"!
62+
# absl::awesome # not "awesome" !
63+
# PUBLIC
10064
# )
10165
#
102-
# If PUBLIC is set, absl_cc_library will instead create a target named
103-
# absl_${NAME} and an alias absl::${NAME}.
104-
#
10566
# absl_cc_library(
10667
# NAME
10768
# main_lib
10869
# ...
109-
# PUBLIC
70+
# DEPS
71+
# absl::fantastic_lib
11072
# )
11173
#
112-
# User can then use the library as absl::main_lib (although absl_main_lib is defined too).
113-
#
11474
# TODO: Implement "ALWAYSLINK"
115-
11675
function(absl_cc_library)
11776
cmake_parse_arguments(ABSL_CC_LIB
11877
"DISABLE_INSTALL;PUBLIC;TESTONLY"
@@ -121,15 +80,24 @@ function(absl_cc_library)
12180
${ARGN}
12281
)
12382

124-
if (NOT ABSL_CC_LIB_TESTONLY OR ABSL_RUN_TESTS)
125-
if (ABSL_CC_LIB_PUBLIC)
126-
set(_NAME "absl_${ABSL_CC_LIB_NAME}")
83+
if(NOT ABSL_CC_LIB_TESTONLY OR ABSL_RUN_TESTS)
84+
if(ABSL_ENABLE_INSTALL)
85+
set(_NAME "${ABSL_CC_LIB_NAME}")
12786
else()
128-
set(_NAME "absl_internal_${ABSL_CC_LIB_NAME}")
87+
set(_NAME "absl_${ABSL_CC_LIB_NAME}")
12988
endif()
13089

13190
# Check if this is a header-only library
132-
if ("${ABSL_CC_LIB_SRCS}" STREQUAL "")
91+
# Note that as of February 2019, many popular OS's (for example, Ubuntu
92+
# 16.04 LTS) only come with cmake 3.5 by default. For this reason, we can't
93+
# use list(FILTER...)
94+
set(ABSL_CC_SRCS "${ABSL_CC_LIB_SRCS}")
95+
foreach(src_file IN LISTS ABSL_CC_SRCS)
96+
if(${src_file} MATCHES ".*\\.(h|inc)")
97+
list(REMOVE_ITEM ABSL_CC_SRCS "${src_file}")
98+
endif()
99+
endforeach()
100+
if("${ABSL_CC_SRCS}" STREQUAL "")
133101
set(ABSL_CC_LIB_IS_INTERFACE 1)
134102
else()
135103
set(ABSL_CC_LIB_IS_INTERFACE 0)
@@ -139,134 +107,149 @@ function(absl_cc_library)
139107
add_library(${_NAME} STATIC "")
140108
target_sources(${_NAME} PRIVATE ${ABSL_CC_LIB_SRCS} ${ABSL_CC_LIB_HDRS})
141109
target_include_directories(${_NAME}
142-
PUBLIC ${ABSL_COMMON_INCLUDE_DIRS})
110+
PUBLIC
111+
$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>
112+
$<INSTALL_INTERFACE:${ABSL_INSTALL_INCLUDEDIR}>
113+
)
143114
target_compile_options(${_NAME}
144115
PRIVATE ${ABSL_CC_LIB_COPTS})
145116
target_link_libraries(${_NAME}
146117
PUBLIC ${ABSL_CC_LIB_DEPS}
147-
PRIVATE ${ABSL_CC_LIB_LINKOPTS}
118+
PRIVATE
119+
${ABSL_CC_LIB_LINKOPTS}
120+
${ABSL_DEFAULT_LINKOPTS}
148121
)
149122
target_compile_definitions(${_NAME} PUBLIC ${ABSL_CC_LIB_DEFINES})
150123

151124
# Add all Abseil targets to a a folder in the IDE for organization.
152-
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER})
125+
if(ABSL_CC_LIB_PUBLIC)
126+
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER})
127+
elseif(ABSL_CC_LIB_TESTONLY)
128+
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER}/test)
129+
else()
130+
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER}/internal)
131+
endif()
132+
133+
# INTERFACE libraries can't have the CXX_STANDARD property set
134+
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD})
135+
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
136+
137+
# When being installed, we lose the absl_ prefix. We want to put it back
138+
# to have properly named lib files. This is a no-op when we are not being
139+
# installed.
140+
set_target_properties(${_NAME} PROPERTIES
141+
OUTPUT_NAME "absl_${_NAME}"
142+
)
153143
else()
154144
# Generating header-only library
155145
add_library(${_NAME} INTERFACE)
156-
target_include_directories(${_NAME} INTERFACE ${ABSL_COMMON_INCLUDE_DIRS})
146+
target_include_directories(${_NAME}
147+
INTERFACE
148+
$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>
149+
$<INSTALL_INTERFACE:${ABSL_INSTALL_INCLUDEDIR}>
150+
)
157151
target_link_libraries(${_NAME}
158-
INTERFACE ${ABSL_CC_LIB_DEPS} ${ABSL_CC_LIB_LINKOPTS}
152+
INTERFACE
153+
${ABSL_CC_LIB_DEPS}
154+
${ABSL_CC_LIB_LINKOPTS}
155+
${ABSL_DEFAULT_LINKOPTS}
159156
)
160157
target_compile_definitions(${_NAME} INTERFACE ${ABSL_CC_LIB_DEFINES})
161158
endif()
162159

163-
if(ABSL_CC_LIB_PUBLIC)
164-
add_library(absl::${ABSL_CC_LIB_NAME} ALIAS ${_NAME})
160+
# TODO currently we don't install googletest alongside abseil sources, so
161+
# installed abseil can't be tested.
162+
if(NOT ABSL_CC_LIB_TESTONLY AND ABSL_ENABLE_INSTALL)
163+
install(TARGETS ${_NAME} EXPORT ${PROJECT_NAME}Targets
164+
RUNTIME DESTINATION ${ABSL_INSTALL_BINDIR}
165+
LIBRARY DESTINATION ${ABSL_INSTALL_LIBDIR}
166+
ARCHIVE DESTINATION ${ABSL_INSTALL_LIBDIR}
167+
)
165168
endif()
166-
endif()
167-
endfunction()
168-
169-
#
170-
# header only virtual target creation
171-
#
172-
function(absl_header_library)
173-
cmake_parse_arguments(ABSL_HO_LIB
174-
"DISABLE_INSTALL"
175-
"EXPORT_NAME;TARGET"
176-
"PUBLIC_LIBRARIES;PRIVATE_COMPILE_FLAGS;PUBLIC_INCLUDE_DIRS;PRIVATE_INCLUDE_DIRS"
177-
${ARGN}
178-
)
179-
180-
set(_NAME ${ABSL_HO_LIB_TARGET})
181-
182-
set(__dummy_header_only_lib_file "${CMAKE_CURRENT_BINARY_DIR}/${_NAME}_header_only_dummy.cc")
183-
184-
if(NOT EXISTS ${__dummy_header_only_lib_file})
185-
file(WRITE ${__dummy_header_only_lib_file}
186-
"/* generated file for header-only cmake target */
187-
188-
namespace absl {
189-
190-
// single meaningless symbol
191-
void ${_NAME}__header_fakesym() {}
192-
} // namespace absl
193-
"
194-
)
195-
endif()
196-
197169

198-
add_library(${_NAME} ${__dummy_header_only_lib_file})
199-
target_link_libraries(${_NAME} PUBLIC ${ABSL_HO_LIB_PUBLIC_LIBRARIES})
200-
target_include_directories(${_NAME}
201-
PUBLIC ${ABSL_COMMON_INCLUDE_DIRS} ${ABSL_HO_LIB_PUBLIC_INCLUDE_DIRS}
202-
PRIVATE ${ABSL_HO_LIB_PRIVATE_INCLUDE_DIRS}
203-
)
204-
205-
# Add all Abseil targets to a a folder in the IDE for organization.
206-
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER})
207-
208-
if(ABSL_HO_LIB_EXPORT_NAME)
209-
add_library(absl::${ABSL_HO_LIB_EXPORT_NAME} ALIAS ${_NAME})
170+
add_library(absl::${ABSL_CC_LIB_NAME} ALIAS ${_NAME})
210171
endif()
211-
212172
endfunction()
213173

214-
215-
#
216-
# create an abseil unit_test and add it to the executed test list
174+
# absl_cc_test()
217175
#
218-
# parameters
219-
# TARGET: target name prefix
220-
# SOURCES: sources files for the tests
221-
# PUBLIC_LIBRARIES: targets and flags for linking phase.
222-
# PRIVATE_COMPILE_FLAGS: compile flags for the test. Will not be exported.
176+
# CMake function to imitate Bazel's cc_test rule.
223177
#
224-
# create a target associated to <NAME>_bin
178+
# Parameters:
179+
# NAME: name of target (see Usage below)
180+
# SRCS: List of source files for the binary
181+
# DEPS: List of other libraries to be linked in to the binary targets
182+
# COPTS: List of private compile options
183+
# DEFINES: List of public defines
184+
# LINKOPTS: List of link options
225185
#
226-
# all tests will be register for execution with add_test()
186+
# Note:
187+
# By default, absl_cc_test will always create a binary named absl_${NAME}.
188+
# This will also add it to ctest list as absl_${NAME}.
227189
#
228-
# test compilation and execution is disable when ABSL_RUN_TESTS=OFF
190+
# Usage:
191+
# absl_cc_library(
192+
# NAME
193+
# awesome
194+
# HDRS
195+
# "a.h"
196+
# SRCS
197+
# "a.cc"
198+
# PUBLIC
199+
# )
229200
#
230-
function(absl_test)
201+
# absl_cc_test(
202+
# NAME
203+
# awesome_test
204+
# SRCS
205+
# "awesome_test.cc"
206+
# DEPS
207+
# absl::awesome
208+
# gmock
209+
# gtest_main
210+
# )
211+
function(absl_cc_test)
212+
if(NOT ABSL_RUN_TESTS)
213+
return()
214+
endif()
231215

232-
cmake_parse_arguments(ABSL_TEST
216+
cmake_parse_arguments(ABSL_CC_TEST
233217
""
234-
"TARGET"
235-
"SOURCES;PUBLIC_LIBRARIES;PRIVATE_COMPILE_FLAGS;PUBLIC_INCLUDE_DIRS"
218+
"NAME"
219+
"SRCS;COPTS;DEFINES;LINKOPTS;DEPS"
236220
${ARGN}
237221
)
238222

223+
set(_NAME "absl_${ABSL_CC_TEST_NAME}")
224+
add_executable(${_NAME} "")
225+
target_sources(${_NAME} PRIVATE ${ABSL_CC_TEST_SRCS})
226+
target_include_directories(${_NAME}
227+
PUBLIC ${ABSL_COMMON_INCLUDE_DIRS}
228+
PRIVATE ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}
229+
)
230+
target_compile_definitions(${_NAME}
231+
PUBLIC ${ABSL_CC_TEST_DEFINES}
232+
)
233+
target_compile_options(${_NAME}
234+
PRIVATE ${ABSL_CC_TEST_COPTS}
235+
)
236+
target_link_libraries(${_NAME}
237+
PUBLIC ${ABSL_CC_TEST_DEPS}
238+
PRIVATE ${ABSL_CC_TEST_LINKOPTS}
239+
)
240+
# Add all Abseil targets to a a folder in the IDE for organization.
241+
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER}/test)
239242

240-
if(ABSL_RUN_TESTS)
241-
242-
set(_NAME ${ABSL_TEST_TARGET})
243-
string(TOUPPER ${_NAME} _UPPER_NAME)
244-
245-
add_executable(${_NAME}_bin ${ABSL_TEST_SOURCES})
246-
247-
target_compile_options(${_NAME}_bin PRIVATE ${ABSL_TEST_PRIVATE_COMPILE_FLAGS})
248-
target_link_libraries(${_NAME}_bin PUBLIC ${ABSL_TEST_PUBLIC_LIBRARIES} ${ABSL_TEST_COMMON_LIBRARIES})
249-
target_include_directories(${_NAME}_bin
250-
PUBLIC ${ABSL_COMMON_INCLUDE_DIRS} ${ABSL_TEST_PUBLIC_INCLUDE_DIRS}
251-
PRIVATE ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}
252-
)
253-
254-
# Add all Abseil targets to a a folder in the IDE for organization.
255-
set_property(TARGET ${_NAME}_bin PROPERTY FOLDER ${ABSL_IDE_FOLDER})
256-
257-
add_test(${_NAME} ${_NAME}_bin)
258-
endif(ABSL_RUN_TESTS)
243+
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD})
244+
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
259245

246+
add_test(NAME ${_NAME} COMMAND ${_NAME})
260247
endfunction()
261248

262249

263-
264-
265250
function(check_target my_target)
266-
267251
if(NOT TARGET ${my_target})
268252
message(FATAL_ERROR " ABSL: compiling absl requires a ${my_target} CMake target in your project,
269253
see CMake/README.md for more details")
270254
endif(NOT TARGET ${my_target})
271-
272255
endfunction()

0 commit comments

Comments
 (0)