diff --git a/CMake/AbseilHelpers.cmake b/CMake/AbseilHelpers.cmake index 08bcf13e231..7a416bdd0dc 100644 --- a/CMake/AbseilHelpers.cmake +++ b/CMake/AbseilHelpers.cmake @@ -66,7 +66,7 @@ set(ABSL_IDE_FOLDER Abseil) # TODO: Implement "ALWAYSLINK" function(absl_cc_library) cmake_parse_arguments(ABSL_CC_LIB - "DISABLE_INSTALL;PUBLIC;TESTONLY" + "PUBLIC;TESTONLY" "NAME" "HDRS;SRCS;COPTS;DEFINES;LINKOPTS;DEPS" ${ARGN} @@ -74,9 +74,9 @@ function(absl_cc_library) if (NOT ABSL_CC_LIB_TESTONLY OR ABSL_RUN_TESTS) if (ABSL_CC_LIB_PUBLIC) - set(_NAME "absl_${ABSL_CC_LIB_NAME}") + set(_NAME "${ABSL_CC_LIB_NAME}") else() - set(_NAME "absl_internal_${ABSL_CC_LIB_NAME}") + set(_NAME "${ABSL_CC_LIB_NAME}_") endif() # Check if this is a header-only library @@ -88,9 +88,15 @@ function(absl_cc_library) if(NOT ABSL_CC_LIB_IS_INTERFACE) add_library(${_NAME} STATIC "") + set_target_properties(${_NAME} PROPERTIES + OUTPUT_NAME "absl_${_NAME}" + ) target_sources(${_NAME} PRIVATE ${ABSL_CC_LIB_SRCS} ${ABSL_CC_LIB_HDRS}) target_include_directories(${_NAME} - PUBLIC ${ABSL_COMMON_INCLUDE_DIRS}) + PUBLIC + $ + $ + ) # TODO(rongjiecomputer): Revisit ABSL_COMPILE_CXXFLAGS when fixing GH#123 target_compile_options(${_NAME} PRIVATE ${ABSL_COMPILE_CXXFLAGS} ${ABSL_CC_LIB_COPTS}) @@ -106,7 +112,10 @@ function(absl_cc_library) # Generating header-only library add_library(${_NAME} INTERFACE) target_include_directories(${_NAME} - INTERFACE ${ABSL_COMMON_INCLUDE_DIRS}) + INTERFACE + $ + $ + ) target_link_libraries(${_NAME} INTERFACE ${ABSL_CC_LIB_DEPS} ${ABSL_CC_LIB_LINKOPTS} ) @@ -116,6 +125,16 @@ function(absl_cc_library) if(ABSL_CC_LIB_PUBLIC OR ABSL_CC_LIB_TESTONLY) add_library(absl::${ABSL_CC_LIB_NAME} ALIAS ${_NAME}) endif() + + # Install rules + if(NOT ABSL_DISABLE_INSTALL AND ABSL_CC_LIB_PUBLIC) + install(TARGETS ${ABSL_CC_LIB_NAME} + EXPORT ${PROJECT_NAME}-targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) + endif() + endif() endfunction() diff --git a/CMake/absl-config.cmake b/CMake/absl-config.cmake new file mode 100644 index 00000000000..c6f539c92bc --- /dev/null +++ b/CMake/absl-config.cmake @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/absl-targets.cmake" diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e65d566b9f..d7d73a70ae5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,9 +21,13 @@ project(absl) list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake) -include(GNUInstallDirs) -include(AbseilHelpers) +option(ABSL_DISABLE_INSTALL "If ON, Abseil disable install rules." OFF) + +if(NOT ABSL_DISABLE_INSTALL) + include(GNUInstallDirs) +endif() +include(AbseilHelpers) # config options if (MSVC) @@ -103,3 +107,14 @@ if(BUILD_TESTING) endif() add_subdirectory(absl) + +if(NOT ABSL_DISABLE_INSTALL) + set(CMAKE_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) + install(EXPORT ${PROJECT_NAME}-targets + NAMESPACE absl:: + DESTINATION ${CMAKE_INSTALL_CONFIGDIR} + ) + install(FILES CMake/${PROJECT_NAME}-config.cmake + DESTINATION ${CMAKE_INSTALL_CONFIGDIR} + ) +endif()