Commit 10d1edd8 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

cmake: improvements to the installed package config file

Summary:
- Use CMakePackageConfigHelpers to help generate the file
- Print a message about where folly was found if not using QUIET
- Make the include, lib, and cmake installation directories configurable

Reviewed By: wez

Differential Revision: D7479058

fbshipit-source-id: 2548acc9d6de90d11da02ac576a58ce5ca939766
parent abcdcd81
......@@ -147,7 +147,8 @@ function(auto_install_files rootName rootDir)
if (rIdx EQUAL 0)
math(EXPR filePathLength "${filePathLength} - ${rootDirLength}")
string(SUBSTRING "${filePath}" ${rootDirLength} ${filePathLength} fileGroup)
install(FILES ${fil} DESTINATION include/${rootName}${fileGroup})
install(FILES ${fil}
DESTINATION ${INCLUDE_INSTALL_DIR}/${rootName}${fileGroup})
endif()
endforeach()
endfunction()
......
# CMake configuration file for folly
# It defines the following variables
#
# This provides the Folly::folly target, which you can depend on by adding it
# to your target_link_libraries().
#
# It also defines the following variables, although using these directly is not
# necessary if you use the Folly::folly target instead.
# FOLLY_INCLUDE_DIRS
# FOLLY_LIBRARIES
@PACKAGE_INIT@
# Compute paths
get_filename_component(FOLLY_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(
FOLLY_INCLUDE_DIRS
"${FOLLY_CMAKE_DIR}/../../include"
ABSOLUTE)
set_and_check(FOLLY_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(FOLLY_CMAKE_DIR "@PACKAGE_CMAKE_INSTALL_DIR@")
# Include the folly-targets.cmake file, which is generated from our CMake rules
if(NOT TARGET Folly::folly)
if (NOT TARGET Folly::folly)
include("${FOLLY_CMAKE_DIR}/folly-targets.cmake")
endif()
# Set FOLLY_LIBRARIES from our Folly::folly target
set(FOLLY_LIBRARIES Folly::folly)
if (NOT folly_FIND_QUIETLY)
message(STATUS "Found folly: ${PACKAGE_PREFIX_DIR}")
endif()
......@@ -24,6 +24,15 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
project(${PACKAGE_NAME} CXX C)
set(INCLUDE_INSTALL_DIR include CACHE STRING
"The subdirectory where header files should be installed")
set(LIB_INSTALL_DIR lib CACHE STRING
"The subdirectory where libraries should be installed")
set(BIN_INSTALL_DIR bin CACHE STRING
"The subdirectory where binaries should be installed")
set(CMAKE_INSTALL_DIR share/folly CACHE STRING
"The subdirectory where CMake package config files should be installed")
option(BUILD_SHARED_LIBS
"If enabled, build folly as a shared library. \
This is generally discouraged, since folly does not commit to having \
......@@ -285,8 +294,8 @@ target_include_directories(folly
install(TARGETS folly
EXPORT folly
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
auto_install_files(folly ${FOLLY_DIR}
${hfiles}
${FOLLY_DIR}/Fingerprint.h
......@@ -295,26 +304,30 @@ auto_install_files(folly ${FOLLY_DIR}
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/folly/folly-config.h
DESTINATION include/folly
DESTINATION ${INCLUDE_INSTALL_DIR}/folly
COMPONENT dev
)
# Generate the folly-config.cmake file for installation so that
# downstream projects that use on folly can easily depend on it in their CMake
# files using "find_package(folly CONFIG)"
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/CMake/folly-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/folly-config.cmake
@ONLY
include(CMakePackageConfigHelpers)
configure_package_config_file(
CMake/folly-config.cmake.in
folly-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_DIR}
PATH_VARS
INCLUDE_INSTALL_DIR
CMAKE_INSTALL_DIR
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/folly-config.cmake
DESTINATION share/folly
DESTINATION ${CMAKE_INSTALL_DIR}
COMPONENT dev
)
install(
EXPORT folly
DESTINATION share/folly
DESTINATION ${CMAKE_INSTALL_DIR}
NAMESPACE Folly::
FILE folly-targets.cmake
COMPONENT dev
......
......@@ -4,10 +4,12 @@ add_library(
)
target_link_libraries(follybenchmark PUBLIC folly)
apply_folly_compile_options_to_target(follybenchmark)
install(TARGETS follybenchmark
install(
TARGETS follybenchmark
EXPORT folly
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
RUNTIME DESTINATION ${BIN_INSTALL_DIR}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
)
add_subdirectory(experimental/exception_tracer)
......@@ -13,13 +13,6 @@ if (FOLLY_USE_SYMBOLIZER)
folly_exception_tracer_base
PUBLIC folly ${FOLLY_LINK_LIBRARIES}
)
install(
TARGETS folly_exception_tracer_base
EXPORT folly_exception_tracer
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
add_library(
folly_exception_tracer
......@@ -35,13 +28,6 @@ if (FOLLY_USE_SYMBOLIZER)
folly_exception_tracer
PUBLIC folly_exception_tracer_base
)
install(
TARGETS folly_exception_tracer
EXPORT folly_exception_tracer
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
add_library(
folly_exception_counter
......@@ -56,13 +42,6 @@ if (FOLLY_USE_SYMBOLIZER)
folly_exception_counter
PUBLIC folly_exception_tracer
)
install(
TARGETS folly_exception_counter
EXPORT folly_exception_tracer
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
install(
FILES
......@@ -72,11 +51,21 @@ if (FOLLY_USE_SYMBOLIZER)
ExceptionTracerLib.h
StackTrace.h
DESTINATION
include/folly/experimental/exception_tracer
${INCLUDE_INSTALL_DIR}/folly/experimental/exception_tracer
)
install(
TARGETS
folly_exception_tracer_base
folly_exception_tracer
folly_exception_counter
EXPORT folly
RUNTIME DESTINATION ${BIN_INSTALL_DIR}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
)
install(
EXPORT folly_exception_tracer
DESTINATION share/folly
DESTINATION ${CMAKE_INSTALL_DIR}
NAMESPACE Folly::
FILE folly-exception-tracer-targets.cmake
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment