Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
abseil-cpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
abseil-cpp
Commits
ac533e18
Commit
ac533e18
authored
Jun 29, 2018
by
Loo Rong Jie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CMake] Implement absl_cc_library as Bazel's cc_library
cc_library
parent
48cd2c3f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
151 additions
and
67 deletions
+151
-67
CMake/AbseilHelpers.cmake
+107
-0
absl/base/CMakeLists.txt
+12
-19
absl/strings/CMakeLists.txt
+32
-48
No files found.
CMake/AbseilHelpers.cmake
View file @
ac533e18
...
@@ -62,7 +62,114 @@ function(absl_library)
...
@@ -62,7 +62,114 @@ function(absl_library)
endif
()
endif
()
endfunction
()
endfunction
()
#
# CMake function to imitate Bazel's cc_library rule.
#
# Parameters:
# NAME: name of target (see Note)
# HDRS: List of public header files for the library
# SRCS: List of source files for the library
# DEPS: List of other libraries to be linked in to the binary targets
# COPTS: List of private compile options
# DEFINES: List of public defines
# LINKOPTS: List of link options
# VISIBILITY_PUBLIC: Add this so that this library will be exported under absl:: (see Note).
# TESTONLY: When added, this target will only be built if user passes -DBUILD_TESTING=ON to CMake.
#
# Note:
#
# By default, absl_cc_library will always create a library named absl_${NAME},
# which means other targets can only depend this library as absl_${NAME}, not ${NAME}.
# This is to reduce namespace pollution.
#
# absl_cc_library(
# NAME
# awesome_lib
# HDRS
# "a.h"
# SRCS
# "a.cc"
# )
# absl_cc_library(
# NAME
# fantastic_lib
# SRCS
# "b.cc"
# DEPS
# absl_awesome_lib # not "awesome_lib"!
# )
#
# If VISIBILITY_PUBLIC is set, absl_cc_library will also create an alias absl::${NAME}
# for public use.
#
# absl_cc_library(
# NAME
# main_lib
# ...
# VISIBILITY_PUBLIC
# )
#
# User can then use the library as absl::main_lib (although absl_main_lib is defined too).
#
# TODO: Implement "ALWAYSLINK"
function
(
absl_cc_library
)
cmake_parse_arguments
(
ABSL_CC_LIB
"DISABLE_INSTALL;VISIBILITY_PUBLIC;TESTONLY"
"NAME"
"HDRS;SRCS;COPTS;DEFINES;LINKOPTS;DEPS"
${
ARGN
}
)
if
(
NOT ABSL_CC_LIB_TESTONLY OR BUILD_TESTING
)
set
(
_NAME
"absl_
${
ABSL_CC_LIB_NAME
}
"
)
string
(
TOUPPER
${
_NAME
}
_UPPER_NAME
)
# Check if this is a header-only library
if
(
ABSL_CC_LIB_SRCS
)
set
(
_SRCS
${
ABSL_CC_LIB_SRCS
}
)
list
(
FILTER _SRCS INCLUDE REGEX
"\.cc$"
)
list
(
LENGTH _SRCS ABSL_CC_LIB_SRCS_LEN
)
else
()
set
(
ABSL_CC_LIB_SRCS_LEN 0
)
endif
()
if
(
ABSL_CC_LIB_SRCS_LEN
)
add_library
(
${
_NAME
}
STATIC
${
ABSL_CC_LIB_SRCS
}
${
ABSL_CC_LIB_HDRS
}
)
else
()
set
(
__dummy_header_only_lib_file
"
${
CMAKE_CURRENT_BINARY_DIR
}
/
${
_NAME
}
_header_only_dummy.cc"
)
if
(
NOT EXISTS
${
__dummy_header_only_lib_file
}
)
file
(
WRITE
${
__dummy_header_only_lib_file
}
"/* generated file for header-only cmake target */
namespace absl {
// single meaningless symbol
void
${
_NAME
}
__header_fakesym() {}
} // namespace absl"
)
endif
()
add_library
(
${
_NAME
}
${
__dummy_header_only_lib_file
}
${
ABSL_CC_LIB_HDRS
}
)
endif
()
target_compile_options
(
${
_NAME
}
PRIVATE
${
ABSL_COMPILE_CXXFLAGS
}
${
ABSL_CC_LIB_COPTS
}
)
target_link_libraries
(
${
_NAME
}
PUBLIC
${
ABSL_CC_LIB_DEPS
}
PRIVATE
${
ABSL_CC_LIB_LINKOPTS
}
)
target_compile_definitions
(
${
_NAME
}
PUBLIC
${
ABSL_CC_LIB_DEFINES
}
)
target_include_directories
(
${
_NAME
}
PUBLIC
${
ABSL_COMMON_INCLUDE_DIRS
}
)
# Add all Abseil targets to a a folder in the IDE for organization.
set_property
(
TARGET
${
_NAME
}
PROPERTY FOLDER
${
ABSL_IDE_FOLDER
}
)
if
(
ABSL_CC_LIB_VISIBILITY_PUBLIC
)
add_library
(
absl::
${
ABSL_CC_LIB_NAME
}
ALIAS
${
_NAME
}
)
endif
()
endif
()
endfunction
()
#
#
# header only virtual target creation
# header only virtual target creation
...
...
absl/base/CMakeLists.txt
View file @
ac533e18
...
@@ -99,33 +99,26 @@ absl_library(
...
@@ -99,33 +99,26 @@ absl_library(
throw_delegate
throw_delegate
)
)
if
(
BUILD_TESTING
)
# exception-safety testing library
# exception-safety testing library
set
(
EXCEPTION_SAFETY_TESTING_SRC
absl_cc_library
(
NAME
exception_safety_testing
HDRS
"internal/exception_safety_testing.h"
"internal/exception_safety_testing.h"
SRCS
"internal/exception_safety_testing.cc"
"internal/exception_safety_testing.cc"
)
COPTS
set
(
EXCEPTION_SAFETY_TESTING_PUBLIC_LIBRARIES
${
ABSL_EXCEPTIONS_FLAG
}
${
ABSL_TEST_COMMON_LIBRARIES
}
DEPS
absl::base
absl::base
absl::memory
absl::memory
absl::meta
absl::meta
absl::strings
absl::strings
absl::optional
absl::optional
gtest
gtest
)
TESTONLY
absl_library
(
TARGET
absl_base_internal_exception_safety_testing
SOURCES
${
EXCEPTION_SAFETY_TESTING_SRC
}
PUBLIC_LIBRARIES
${
EXCEPTION_SAFETY_TESTING_PUBLIC_LIBRARIES
}
PRIVATE_COMPILE_FLAGS
${
ABSL_EXCEPTIONS_FLAG
}
)
)
endif
()
# dynamic_annotations library
# dynamic_annotations library
...
@@ -368,7 +361,7 @@ absl_test(
...
@@ -368,7 +361,7 @@ absl_test(
set
(
EXCEPTION_SAFETY_TESTING_TEST_SRC
"exception_safety_testing_test.cc"
)
set
(
EXCEPTION_SAFETY_TESTING_TEST_SRC
"exception_safety_testing_test.cc"
)
set
(
EXCEPTION_SAFETY_TESTING_TEST_PUBLIC_LIBRARIES
set
(
EXCEPTION_SAFETY_TESTING_TEST_PUBLIC_LIBRARIES
absl::base
absl::base
absl_
base_internal_
exception_safety_testing
absl_exception_safety_testing
absl::memory
absl::memory
absl::meta
absl::meta
absl::strings
absl::strings
...
...
absl/strings/CMakeLists.txt
View file @
ac533e18
...
@@ -14,8 +14,10 @@
...
@@ -14,8 +14,10 @@
# limitations under the License.
# limitations under the License.
#
#
absl_cc_library
(
list
(
APPEND STRINGS_PUBLIC_HEADERS
NAME
strings
HDRS
"ascii.h"
"ascii.h"
"charconv.h"
"charconv.h"
"escaping.h"
"escaping.h"
...
@@ -28,35 +30,26 @@ list(APPEND STRINGS_PUBLIC_HEADERS
...
@@ -28,35 +30,26 @@ list(APPEND STRINGS_PUBLIC_HEADERS
"str_replace.h"
"str_replace.h"
"str_split.h"
"str_split.h"
"substitute.h"
"substitute.h"
)
SRCS
"ascii.cc"
"charconv.cc"
list
(
APPEND STRINGS_INTERNAL_HEADERS
"escaping.cc"
"internal/bits.h"
"internal/char_map.h"
"internal/char_map.h"
"internal/charconv_bigint.cc"
"internal/charconv_bigint.h"
"internal/charconv_bigint.h"
"internal/charconv_parse.cc"
"internal/charconv_parse.h"
"internal/charconv_parse.h"
"internal/memutil.cc"
"internal/memutil.h"
"internal/memutil.h"
"internal/ostringstream.cc"
"internal/ostringstream.h"
"internal/ostringstream.h"
"internal/resize_uninitialized.h"
"internal/resize_uninitialized.h"
"internal/stl_type_traits.h"
"internal/stl_type_traits.h"
"internal/str_join_internal.h"
"internal/str_join_internal.h"
"internal/str_split_internal.h"
"internal/str_split_internal.h"
"internal/utf8.h"
)
# add string library
list
(
APPEND STRINGS_SRC
"ascii.cc"
"charconv.cc"
"escaping.cc"
"internal/charconv_bigint.cc"
"internal/charconv_parse.cc"
"internal/memutil.cc"
"internal/memutil.h"
"internal/utf8.cc"
"internal/utf8.cc"
"internal/ostringstream.cc
"
"internal/utf8.h
"
"match.cc"
"match.cc"
"numbers.cc"
"numbers.cc"
"str_cat.cc"
"str_cat.cc"
...
@@ -64,37 +57,28 @@ list(APPEND STRINGS_SRC
...
@@ -64,37 +57,28 @@ list(APPEND STRINGS_SRC
"str_split.cc"
"str_split.cc"
"string_view.cc"
"string_view.cc"
"substitute.cc"
"substitute.cc"
${
STRINGS_PUBLIC_HEADERS
}
DEPS
${
STRINGS_INTERNAL_HEADERS
}
absl::base
)
absl_throw_delegate
set
(
STRINGS_PUBLIC_LIBRARIES absl::base absl_throw_delegate
)
VISIBILITY_PUBLIC
absl_library
(
TARGET
absl_strings
SOURCES
${
STRINGS_SRC
}
PUBLIC_LIBRARIES
${
STRINGS_PUBLIC_LIBRARIES
}
EXPORT_NAME
strings
)
)
# add str_format library
# add str_format library
absl_header_library
(
absl_cc_library
(
TARGET
NAME
absl_str_format
PUBLIC_LIBRARIES
str_format_internal
EXPORT_NAME
str_format
str_format
HDRS
"str_format.h"
DEPS
absl_str_format_internal
VISIBILITY_PUBLIC
)
)
# str_format_internal
# str_format_internal
absl_library
(
absl_
cc_
library
(
TARGET
NAME
str_format_internal
str_format_internal
S
OURCE
S
S
RC
S
"internal/str_format/arg.cc"
"internal/str_format/arg.cc"
"internal/str_format/bind.cc"
"internal/str_format/bind.cc"
"internal/str_format/extension.cc"
"internal/str_format/extension.cc"
...
@@ -108,7 +92,7 @@ absl_library(
...
@@ -108,7 +92,7 @@ absl_library(
"internal/str_format/float_conversion.h"
"internal/str_format/float_conversion.h"
"internal/str_format/output.h"
"internal/str_format/output.h"
"internal/str_format/parser.h"
"internal/str_format/parser.h"
PUBLIC_LIBRARIE
S
DEP
S
str_format_extension_internal
str_format_extension_internal
absl::strings
absl::strings
absl::base
absl::base
...
@@ -415,7 +399,7 @@ absl_test(
...
@@ -415,7 +399,7 @@ absl_test(
SOURCES
SOURCES
"internal/str_format/bind_test.cc"
"internal/str_format/bind_test.cc"
PUBLIC_LIBRARIES
PUBLIC_LIBRARIES
str_format_internal
absl_
str_format_internal
)
)
# test str_format_checker_test
# test str_format_checker_test
...
@@ -435,7 +419,7 @@ absl_test(
...
@@ -435,7 +419,7 @@ absl_test(
SOURCES
SOURCES
"internal/str_format/convert_test.cc"
"internal/str_format/convert_test.cc"
PUBLIC_LIBRARIES
PUBLIC_LIBRARIES
str_format_internal
absl_
str_format_internal
absl::numeric
absl::numeric
)
)
...
@@ -456,7 +440,7 @@ absl_test(
...
@@ -456,7 +440,7 @@ absl_test(
SOURCES
SOURCES
"internal/str_format/parser_test.cc"
"internal/str_format/parser_test.cc"
PUBLIC_LIBRARIES
PUBLIC_LIBRARIES
str_format_internal
absl_
str_format_internal
absl::base
absl::base
)
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment