Merge pull request #136 from rongjiecomputer/cc_library
[CMake] Implement absl_cc_library as Bazel's cc_library
This commit is contained in:
commit
5fbde92571
7 changed files with 159 additions and 70 deletions
|
@ -62,7 +62,110 @@ 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
|
||||||
|
# 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 -DABSL_RUN_TESTS=ON to CMake.
|
||||||
|
#
|
||||||
|
# Note:
|
||||||
|
#
|
||||||
|
# By default, absl_cc_library will always create a library named absl_internal_${NAME},
|
||||||
|
# which means other targets can only depend this library as absl_internal_${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_internal_awesome_lib # not "awesome_lib"!
|
||||||
|
# )
|
||||||
|
#
|
||||||
|
# If PUBLIC is set, absl_cc_library will instead create a target named
|
||||||
|
# absl_${NAME} and an alias absl::${NAME}.
|
||||||
|
#
|
||||||
|
# absl_cc_library(
|
||||||
|
# NAME
|
||||||
|
# main_lib
|
||||||
|
# ...
|
||||||
|
# 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;PUBLIC;TESTONLY"
|
||||||
|
"NAME"
|
||||||
|
"HDRS;SRCS;COPTS;DEFINES;LINKOPTS;DEPS"
|
||||||
|
${ARGN}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (NOT ABSL_CC_LIB_TESTONLY OR ABSL_RUN_TESTS)
|
||||||
|
if (ABSL_CC_LIB_PUBLIC)
|
||||||
|
set(_NAME "absl_${ABSL_CC_LIB_NAME}")
|
||||||
|
else()
|
||||||
|
set(_NAME "absl_internal_${ABSL_CC_LIB_NAME}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Check if this is a header-only library
|
||||||
|
if ("${ABSL_CC_LIB_SRCS}" STREQUAL "")
|
||||||
|
set(ABSL_CC_LIB_IS_INTERFACE 1)
|
||||||
|
else()
|
||||||
|
set(ABSL_CC_LIB_IS_INTERFACE 0)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT ABSL_CC_LIB_IS_INTERFACE)
|
||||||
|
add_library(${_NAME} STATIC "")
|
||||||
|
target_sources(${_NAME} PRIVATE ${ABSL_CC_LIB_SRCS} ${ABSL_CC_LIB_HDRS})
|
||||||
|
target_include_directories(${_NAME}
|
||||||
|
PUBLIC ${ABSL_COMMON_INCLUDE_DIRS})
|
||||||
|
# TODO(rongjiecomputer): Revisit ABSL_COMPILE_CXXFLAGS when fixing GH#123
|
||||||
|
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})
|
||||||
|
|
||||||
|
# Add all Abseil targets to a a folder in the IDE for organization.
|
||||||
|
set_property(TARGET ${_NAME} PROPERTY FOLDER ${ABSL_IDE_FOLDER})
|
||||||
|
else()
|
||||||
|
# Generating header-only library
|
||||||
|
add_library(${_NAME} INTERFACE)
|
||||||
|
target_include_directories(${_NAME} INTERFACE ${ABSL_COMMON_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(${_NAME}
|
||||||
|
INTERFACE ${ABSL_CC_LIB_DEPS} ${ABSL_CC_LIB_LINKOPTS}
|
||||||
|
)
|
||||||
|
target_compile_definitions(${_NAME} INTERFACE ${ABSL_CC_LIB_DEFINES})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ABSL_CC_LIB_PUBLIC)
|
||||||
|
add_library(absl::${ABSL_CC_LIB_NAME} ALIAS ${_NAME})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
#
|
#
|
||||||
# header only virtual target creation
|
# header only virtual target creation
|
||||||
|
|
|
@ -78,55 +78,45 @@ absl_library(
|
||||||
${BASE_SRC}
|
${BASE_SRC}
|
||||||
PUBLIC_LIBRARIES
|
PUBLIC_LIBRARIES
|
||||||
absl_dynamic_annotations
|
absl_dynamic_annotations
|
||||||
absl_spinlock_wait
|
absl_internal_spinlock_wait
|
||||||
EXPORT_NAME
|
EXPORT_NAME
|
||||||
base
|
base
|
||||||
)
|
)
|
||||||
|
|
||||||
# throw delegate library
|
absl_cc_library(
|
||||||
set(THROW_DELEGATE_SRC "internal/throw_delegate.cc")
|
NAME
|
||||||
|
|
||||||
absl_library(
|
|
||||||
TARGET
|
|
||||||
absl_throw_delegate
|
|
||||||
SOURCES
|
|
||||||
${THROW_DELEGATE_SRC}
|
|
||||||
PUBLIC_LIBRARIES
|
|
||||||
${THROW_DELEGATE_PUBLIC_LIBRARIES}
|
|
||||||
PRIVATE_COMPILE_FLAGS
|
|
||||||
${ABSL_EXCEPTIONS_FLAG}
|
|
||||||
EXPORT_NAME
|
|
||||||
throw_delegate
|
throw_delegate
|
||||||
|
SRCS
|
||||||
|
"internal/throw_delegate.cc"
|
||||||
|
HDRS
|
||||||
|
"internal/throw_delegate.h"
|
||||||
|
COPTS
|
||||||
|
${ABSL_EXCEPTIONS_FLAG}
|
||||||
|
DEPS
|
||||||
|
absl::base
|
||||||
)
|
)
|
||||||
|
|
||||||
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
|
||||||
set(DYNAMIC_ANNOTATIONS_SRC "dynamic_annotations.cc")
|
set(DYNAMIC_ANNOTATIONS_SRC "dynamic_annotations.cc")
|
||||||
|
@ -138,29 +128,25 @@ absl_library(
|
||||||
${DYNAMIC_ANNOTATIONS_SRC}
|
${DYNAMIC_ANNOTATIONS_SRC}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
absl_cc_library(
|
||||||
# spinlock_wait library
|
NAME
|
||||||
set(SPINLOCK_WAIT_SRC "internal/spinlock_wait.cc")
|
spinlock_wait
|
||||||
|
SRCS
|
||||||
absl_library(
|
"internal/spinlock_wait.cc"
|
||||||
TARGET
|
HDRS
|
||||||
absl_spinlock_wait
|
"internal/scheduling_mode.h"
|
||||||
SOURCES
|
"internal/spinlock_wait.h"
|
||||||
${SPINLOCK_WAIT_SRC}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
absl_cc_library(
|
||||||
# malloc_internal library
|
NAME
|
||||||
list(APPEND MALLOC_INTERNAL_SRC
|
malloc_internal
|
||||||
|
SRCS
|
||||||
"internal/low_level_alloc.cc"
|
"internal/low_level_alloc.cc"
|
||||||
)
|
HDRS
|
||||||
|
"internal/direct_mmap.h"
|
||||||
absl_library(
|
"internal/low_level_alloc.h"
|
||||||
TARGET
|
DEPS
|
||||||
absl_malloc_internal
|
|
||||||
SOURCES
|
|
||||||
${MALLOC_INTERNAL_SRC}
|
|
||||||
PUBLIC_LIBRARIES
|
|
||||||
absl_dynamic_annotations
|
absl_dynamic_annotations
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -211,7 +197,7 @@ absl_test(
|
||||||
|
|
||||||
# test absl_throw_delegate_test
|
# test absl_throw_delegate_test
|
||||||
set(THROW_DELEGATE_TEST_SRC "throw_delegate_test.cc")
|
set(THROW_DELEGATE_TEST_SRC "throw_delegate_test.cc")
|
||||||
set(THROW_DELEGATE_TEST_PUBLIC_LIBRARIES absl::base absl_throw_delegate)
|
set(THROW_DELEGATE_TEST_PUBLIC_LIBRARIES absl::base absl_internal_throw_delegate)
|
||||||
|
|
||||||
absl_test(
|
absl_test(
|
||||||
TARGET
|
TARGET
|
||||||
|
@ -368,7 +354,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_internal_exception_safety_testing
|
||||||
absl::memory
|
absl::memory
|
||||||
absl::meta
|
absl::meta
|
||||||
absl::strings
|
absl::strings
|
||||||
|
|
|
@ -82,7 +82,7 @@ absl_library(
|
||||||
|
|
||||||
# test fixed_array_test
|
# test fixed_array_test
|
||||||
set(FIXED_ARRAY_TEST_SRC "fixed_array_test.cc")
|
set(FIXED_ARRAY_TEST_SRC "fixed_array_test.cc")
|
||||||
set(FIXED_ARRAY_TEST_PUBLIC_LIBRARIES absl::base absl_throw_delegate test_instance_tracker_lib)
|
set(FIXED_ARRAY_TEST_PUBLIC_LIBRARIES absl::base absl_internal_throw_delegate test_instance_tracker_lib)
|
||||||
|
|
||||||
absl_test(
|
absl_test(
|
||||||
TARGET
|
TARGET
|
||||||
|
@ -111,7 +111,7 @@ absl_test(
|
||||||
set(FIXED_ARRAY_EXCEPTION_SAFETY_TEST_SRC "fixed_array_exception_safety_test.cc")
|
set(FIXED_ARRAY_EXCEPTION_SAFETY_TEST_SRC "fixed_array_exception_safety_test.cc")
|
||||||
set(FIXED_ARRAY_EXCEPTION_SAFETY_TEST_PUBLIC_LIBRARIES
|
set(FIXED_ARRAY_EXCEPTION_SAFETY_TEST_PUBLIC_LIBRARIES
|
||||||
absl::container
|
absl::container
|
||||||
absl_base_internal_exception_safety_testing
|
absl_internal_exception_safety_testing
|
||||||
)
|
)
|
||||||
|
|
||||||
absl_test(
|
absl_test(
|
||||||
|
@ -128,7 +128,7 @@ absl_test(
|
||||||
|
|
||||||
# test inlined_vector_test
|
# test inlined_vector_test
|
||||||
set(INLINED_VECTOR_TEST_SRC "inlined_vector_test.cc")
|
set(INLINED_VECTOR_TEST_SRC "inlined_vector_test.cc")
|
||||||
set(INLINED_VECTOR_TEST_PUBLIC_LIBRARIES absl::base absl_throw_delegate test_instance_tracker_lib)
|
set(INLINED_VECTOR_TEST_PUBLIC_LIBRARIES absl::base absl_internal_throw_delegate test_instance_tracker_lib)
|
||||||
|
|
||||||
absl_test(
|
absl_test(
|
||||||
TARGET
|
TARGET
|
||||||
|
@ -153,7 +153,7 @@ absl_test(
|
||||||
|
|
||||||
# test test_instance_tracker_test
|
# test test_instance_tracker_test
|
||||||
set(TEST_INSTANCE_TRACKER_TEST_SRC "internal/test_instance_tracker_test.cc")
|
set(TEST_INSTANCE_TRACKER_TEST_SRC "internal/test_instance_tracker_test.cc")
|
||||||
set(TEST_INSTANCE_TRACKER_TEST_PUBLIC_LIBRARIES absl::base absl_throw_delegate test_instance_tracker_lib)
|
set(TEST_INSTANCE_TRACKER_TEST_PUBLIC_LIBRARIES absl::base absl_internal_throw_delegate test_instance_tracker_lib)
|
||||||
|
|
||||||
|
|
||||||
absl_test(
|
absl_test(
|
||||||
|
|
|
@ -85,7 +85,7 @@ absl_library(
|
||||||
${SYMBOLIZE_SRC}
|
${SYMBOLIZE_SRC}
|
||||||
PUBLIC_LIBRARIES
|
PUBLIC_LIBRARIES
|
||||||
absl::base
|
absl::base
|
||||||
absl_malloc_internal
|
absl_internal_malloc_internal
|
||||||
EXPORT_NAME
|
EXPORT_NAME
|
||||||
symbolize
|
symbolize
|
||||||
)
|
)
|
||||||
|
|
|
@ -53,7 +53,7 @@ absl_test(
|
||||||
set(MEMORY_EXCEPTION_SAFETY_TEST_SRC "memory_exception_safety_test.cc")
|
set(MEMORY_EXCEPTION_SAFETY_TEST_SRC "memory_exception_safety_test.cc")
|
||||||
set(MEMORY_EXCEPTION_SAFETY_TEST_PUBLIC_LIBRARIES
|
set(MEMORY_EXCEPTION_SAFETY_TEST_PUBLIC_LIBRARIES
|
||||||
absl::memory
|
absl::memory
|
||||||
absl_base_internal_exception_safety_testing
|
absl_internal_exception_safety_testing
|
||||||
)
|
)
|
||||||
|
|
||||||
absl_test(
|
absl_test(
|
||||||
|
|
|
@ -67,7 +67,7 @@ list(APPEND STRINGS_SRC
|
||||||
${STRINGS_PUBLIC_HEADERS}
|
${STRINGS_PUBLIC_HEADERS}
|
||||||
${STRINGS_INTERNAL_HEADERS}
|
${STRINGS_INTERNAL_HEADERS}
|
||||||
)
|
)
|
||||||
set(STRINGS_PUBLIC_LIBRARIES absl::base absl_throw_delegate)
|
set(STRINGS_PUBLIC_LIBRARIES absl::base absl_internal_throw_delegate)
|
||||||
|
|
||||||
absl_library(
|
absl_library(
|
||||||
TARGET
|
TARGET
|
||||||
|
@ -207,7 +207,7 @@ absl_test(
|
||||||
|
|
||||||
# test string_view_test
|
# test string_view_test
|
||||||
set(STRING_VIEW_TEST_SRC "string_view_test.cc")
|
set(STRING_VIEW_TEST_SRC "string_view_test.cc")
|
||||||
set(STRING_VIEW_TEST_PUBLIC_LIBRARIES absl::strings absl_throw_delegate absl::base)
|
set(STRING_VIEW_TEST_PUBLIC_LIBRARIES absl::strings absl_internal_throw_delegate absl::base)
|
||||||
|
|
||||||
absl_test(
|
absl_test(
|
||||||
TARGET
|
TARGET
|
||||||
|
@ -235,7 +235,7 @@ absl_test(
|
||||||
|
|
||||||
# test str_replace_test
|
# test str_replace_test
|
||||||
set(STR_REPLACE_TEST_SRC "str_replace_test.cc")
|
set(STR_REPLACE_TEST_SRC "str_replace_test.cc")
|
||||||
set(STR_REPLACE_TEST_PUBLIC_LIBRARIES absl::strings absl::base absl_throw_delegate)
|
set(STR_REPLACE_TEST_PUBLIC_LIBRARIES absl::strings absl::base absl_internal_throw_delegate)
|
||||||
|
|
||||||
absl_test(
|
absl_test(
|
||||||
TARGET
|
TARGET
|
||||||
|
@ -249,7 +249,7 @@ absl_test(
|
||||||
|
|
||||||
# test str_split_test
|
# test str_split_test
|
||||||
set(STR_SPLIT_TEST_SRC "str_split_test.cc")
|
set(STR_SPLIT_TEST_SRC "str_split_test.cc")
|
||||||
set(STR_SPLIT_TEST_PUBLIC_LIBRARIES absl::strings absl::base absl_throw_delegate)
|
set(STR_SPLIT_TEST_PUBLIC_LIBRARIES absl::strings absl::base absl_internal_throw_delegate)
|
||||||
|
|
||||||
absl_test(
|
absl_test(
|
||||||
TARGET
|
TARGET
|
||||||
|
|
|
@ -123,7 +123,7 @@ absl_library(
|
||||||
|
|
||||||
# test any_test
|
# test any_test
|
||||||
set(ANY_TEST_SRC "any_test.cc")
|
set(ANY_TEST_SRC "any_test.cc")
|
||||||
set(ANY_TEST_PUBLIC_LIBRARIES absl::base absl::throw_delegate absl::any absl::bad_any_cast test_instance_tracker_lib)
|
set(ANY_TEST_PUBLIC_LIBRARIES absl::base absl_internal_throw_delegate absl::any absl::bad_any_cast test_instance_tracker_lib)
|
||||||
|
|
||||||
absl_test(
|
absl_test(
|
||||||
TARGET
|
TARGET
|
||||||
|
@ -152,7 +152,7 @@ set(ANY_EXCEPTION_SAFETY_TEST_SRC "any_exception_safety_test.cc")
|
||||||
set(ANY_EXCEPTION_SAFETY_TEST_PUBLIC_LIBRARIES
|
set(ANY_EXCEPTION_SAFETY_TEST_PUBLIC_LIBRARIES
|
||||||
absl::any
|
absl::any
|
||||||
absl::base
|
absl::base
|
||||||
absl_base_internal_exception_safety_testing
|
absl_internal_exception_safety_testing
|
||||||
)
|
)
|
||||||
|
|
||||||
absl_test(
|
absl_test(
|
||||||
|
@ -169,7 +169,7 @@ absl_test(
|
||||||
|
|
||||||
# test span_test
|
# test span_test
|
||||||
set(SPAN_TEST_SRC "span_test.cc")
|
set(SPAN_TEST_SRC "span_test.cc")
|
||||||
set(SPAN_TEST_PUBLIC_LIBRARIES absl::base absl::strings absl::throw_delegate absl::span test_instance_tracker_lib)
|
set(SPAN_TEST_PUBLIC_LIBRARIES absl::base absl::strings absl_internal_throw_delegate absl::span test_instance_tracker_lib)
|
||||||
|
|
||||||
absl_test(
|
absl_test(
|
||||||
TARGET
|
TARGET
|
||||||
|
@ -197,7 +197,7 @@ absl_test(
|
||||||
|
|
||||||
# test optional_test
|
# test optional_test
|
||||||
set(OPTIONAL_TEST_SRC "optional_test.cc")
|
set(OPTIONAL_TEST_SRC "optional_test.cc")
|
||||||
set(OPTIONAL_TEST_PUBLIC_LIBRARIES absl::base absl::throw_delegate absl::optional absl_bad_optional_access)
|
set(OPTIONAL_TEST_PUBLIC_LIBRARIES absl::base absl_internal_throw_delegate absl::optional absl_bad_optional_access)
|
||||||
|
|
||||||
absl_test(
|
absl_test(
|
||||||
TARGET
|
TARGET
|
||||||
|
@ -213,7 +213,7 @@ absl_test(
|
||||||
set(OPTIONAL_EXCEPTION_SAFETY_TEST_SRC "optional_exception_safety_test.cc")
|
set(OPTIONAL_EXCEPTION_SAFETY_TEST_SRC "optional_exception_safety_test.cc")
|
||||||
set(OPTIONAL_EXCEPTION_SAFETY_TEST_PUBLIC_LIBRARIES
|
set(OPTIONAL_EXCEPTION_SAFETY_TEST_PUBLIC_LIBRARIES
|
||||||
absl::optional
|
absl::optional
|
||||||
absl_base_internal_exception_safety_testing
|
absl_internal_exception_safety_testing
|
||||||
)
|
)
|
||||||
|
|
||||||
absl_test(
|
absl_test(
|
||||||
|
|
Loading…
Reference in a new issue