Skip to content

Commit

Permalink
Add CMake Install rules (abseil#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Oct 24, 2018
1 parent de63061 commit cf4e749
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
29 changes: 24 additions & 5 deletions CMake/AbseilHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ 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}
)

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
Expand All @@ -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
$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:include>
)
# TODO(rongjiecomputer): Revisit ABSL_COMPILE_CXXFLAGS when fixing GH#123
target_compile_options(${_NAME}
PRIVATE ${ABSL_COMPILE_CXXFLAGS} ${ABSL_CC_LIB_COPTS})
Expand All @@ -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
$<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(${_NAME}
INTERFACE ${ABSL_CC_LIB_DEPS} ${ABSL_CC_LIB_LINKOPTS}
)
Expand All @@ -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()

Expand Down
1 change: 1 addition & 0 deletions CMake/absl-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/absl-targets.cmake"
19 changes: 17 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

0 comments on commit cf4e749

Please sign in to comment.