diff options
author | Abseil Team <absl-team@google.com> | 2018-10-22 11:04:58 -0700 |
---|---|---|
committer | Ashley Hedberg <ahedberg@google.com> | 2018-10-22 15:01:16 -0400 |
commit | c16d5557cd05119b5b7b1318ef778ebe3195b4a1 (patch) | |
tree | 35963478ea62b7d35bd1f72eb8cd81ca35677106 /CMake/AbseilHelpers.cmake | |
parent | 45221ccc4ed643e4209b0cc5798e97203f108fa8 (diff) |
Export of internal Abseil changes.
--
4e043a11b4c10a24e84046827ee16f47e11e35cc by Abseil Team <absl-team@google.com>:
Merge of https://github.com/abseil/abseil-cpp/pull/136
PiperOrigin-RevId: 218197648
--
e61f06e1e601061a443feaa8c5207c52437bd641 by Abseil Team <absl-team@google.com>:
Don't include <iostream> into int128, it's wasteful
Including iostream emits a global constructor for initializing std::cout and
friends, which isn't actually used by this file.
PiperOrigin-RevId: 218156386
--
8a6c82396e4c956be7f285328aec131cb4965f16 by Xiaoyi Zhang <zhangxy@google.com>:
Fix MSVC compiler warnings on discarding return values of functions with 'nodiscard'
attribute.
PiperOrigin-RevId: 217883401
--
abf3e3a0f22bc4070df9dbc9a4ef4d883ed686bf by Tom Manshreck <shreck@google.com>:
Update public README to add new libraries
PiperOrigin-RevId: 217879399
--
43b3b420a4e861711abbfbd497b8f2b3de17ec8c by Abseil Team <absl-team@google.com>:
Import of CCTZ from GitHub.
PiperOrigin-RevId: 217780963
--
1c8831947ca6a65a63842e6bd5f37a7c102a4e1b by Abseil Team <absl-team@google.com>:
Fix typo in a comment (missing comma in usage example).
PiperOrigin-RevId: 217776645
GitOrigin-RevId: 4e043a11b4c10a24e84046827ee16f47e11e35cc
Change-Id: I8999ae928da7a0030b4ecfd8d13da8522fdd013a
Diffstat (limited to 'CMake/AbseilHelpers.cmake')
-rw-r--r-- | CMake/AbseilHelpers.cmake | 99 |
1 files changed, 98 insertions, 1 deletions
diff --git a/CMake/AbseilHelpers.cmake b/CMake/AbseilHelpers.cmake index 0c934174..94d10778 100644 --- a/CMake/AbseilHelpers.cmake +++ b/CMake/AbseilHelpers.cmake @@ -62,7 +62,104 @@ function(absl_library) endif() 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 |