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) ...@@ -147,7 +147,8 @@ function(auto_install_files rootName rootDir)
if (rIdx EQUAL 0) if (rIdx EQUAL 0)
math(EXPR filePathLength "${filePathLength} - ${rootDirLength}") math(EXPR filePathLength "${filePathLength} - ${rootDirLength}")
string(SUBSTRING "${filePath}" ${rootDirLength} ${filePathLength} fileGroup) string(SUBSTRING "${filePath}" ${rootDirLength} ${filePathLength} fileGroup)
install(FILES ${fil} DESTINATION include/${rootName}${fileGroup}) install(FILES ${fil}
DESTINATION ${INCLUDE_INSTALL_DIR}/${rootName}${fileGroup})
endif() endif()
endforeach() endforeach()
endfunction() endfunction()
......
# CMake configuration file for folly # 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_INCLUDE_DIRS
# FOLLY_LIBRARIES # FOLLY_LIBRARIES
@PACKAGE_INIT@
# Compute paths set_and_check(FOLLY_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
get_filename_component(FOLLY_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) set_and_check(FOLLY_CMAKE_DIR "@PACKAGE_CMAKE_INSTALL_DIR@")
get_filename_component(
FOLLY_INCLUDE_DIRS
"${FOLLY_CMAKE_DIR}/../../include"
ABSOLUTE)
# Include the folly-targets.cmake file, which is generated from our CMake rules # 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") include("${FOLLY_CMAKE_DIR}/folly-targets.cmake")
endif() endif()
# Set FOLLY_LIBRARIES from our Folly::folly target # Set FOLLY_LIBRARIES from our Folly::folly target
set(FOLLY_LIBRARIES Folly::folly) 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) ...@@ -24,6 +24,15 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
project(${PACKAGE_NAME} CXX C) 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 option(BUILD_SHARED_LIBS
"If enabled, build folly as a shared library. \ "If enabled, build folly as a shared library. \
This is generally discouraged, since folly does not commit to having \ This is generally discouraged, since folly does not commit to having \
...@@ -285,8 +294,8 @@ target_include_directories(folly ...@@ -285,8 +294,8 @@ target_include_directories(folly
install(TARGETS folly install(TARGETS folly
EXPORT folly EXPORT folly
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
LIBRARY DESTINATION lib LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION lib) ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
auto_install_files(folly ${FOLLY_DIR} auto_install_files(folly ${FOLLY_DIR}
${hfiles} ${hfiles}
${FOLLY_DIR}/Fingerprint.h ${FOLLY_DIR}/Fingerprint.h
...@@ -295,26 +304,30 @@ auto_install_files(folly ${FOLLY_DIR} ...@@ -295,26 +304,30 @@ auto_install_files(folly ${FOLLY_DIR}
) )
install( install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/folly/folly-config.h FILES ${CMAKE_CURRENT_BINARY_DIR}/folly/folly-config.h
DESTINATION include/folly DESTINATION ${INCLUDE_INSTALL_DIR}/folly
COMPONENT dev COMPONENT dev
) )
# Generate the folly-config.cmake file for installation so that # Generate the folly-config.cmake file for installation so that
# downstream projects that use on folly can easily depend on it in their CMake # downstream projects that use on folly can easily depend on it in their CMake
# files using "find_package(folly CONFIG)" # files using "find_package(folly CONFIG)"
configure_file( include(CMakePackageConfigHelpers)
${CMAKE_CURRENT_SOURCE_DIR}/CMake/folly-config.cmake.in configure_package_config_file(
${CMAKE_CURRENT_BINARY_DIR}/folly-config.cmake CMake/folly-config.cmake.in
@ONLY folly-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_DIR}
PATH_VARS
INCLUDE_INSTALL_DIR
CMAKE_INSTALL_DIR
) )
install( install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/folly-config.cmake FILES ${CMAKE_CURRENT_BINARY_DIR}/folly-config.cmake
DESTINATION share/folly DESTINATION ${CMAKE_INSTALL_DIR}
COMPONENT dev COMPONENT dev
) )
install( install(
EXPORT folly EXPORT folly
DESTINATION share/folly DESTINATION ${CMAKE_INSTALL_DIR}
NAMESPACE Folly:: NAMESPACE Folly::
FILE folly-targets.cmake FILE folly-targets.cmake
COMPONENT dev COMPONENT dev
......
...@@ -4,10 +4,12 @@ add_library( ...@@ -4,10 +4,12 @@ add_library(
) )
target_link_libraries(follybenchmark PUBLIC folly) target_link_libraries(follybenchmark PUBLIC folly)
apply_folly_compile_options_to_target(follybenchmark) apply_folly_compile_options_to_target(follybenchmark)
install(TARGETS follybenchmark install(
TARGETS follybenchmark
EXPORT folly EXPORT folly
RUNTIME DESTINATION bin RUNTIME DESTINATION ${BIN_INSTALL_DIR}
LIBRARY DESTINATION lib LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION lib) ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
)
add_subdirectory(experimental/exception_tracer) add_subdirectory(experimental/exception_tracer)
...@@ -13,13 +13,6 @@ if (FOLLY_USE_SYMBOLIZER) ...@@ -13,13 +13,6 @@ if (FOLLY_USE_SYMBOLIZER)
folly_exception_tracer_base folly_exception_tracer_base
PUBLIC folly ${FOLLY_LINK_LIBRARIES} 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( add_library(
folly_exception_tracer folly_exception_tracer
...@@ -35,13 +28,6 @@ if (FOLLY_USE_SYMBOLIZER) ...@@ -35,13 +28,6 @@ if (FOLLY_USE_SYMBOLIZER)
folly_exception_tracer folly_exception_tracer
PUBLIC folly_exception_tracer_base 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( add_library(
folly_exception_counter folly_exception_counter
...@@ -56,13 +42,6 @@ if (FOLLY_USE_SYMBOLIZER) ...@@ -56,13 +42,6 @@ if (FOLLY_USE_SYMBOLIZER)
folly_exception_counter folly_exception_counter
PUBLIC folly_exception_tracer PUBLIC folly_exception_tracer
) )
install(
TARGETS folly_exception_counter
EXPORT folly_exception_tracer
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
install( install(
FILES FILES
...@@ -72,11 +51,21 @@ if (FOLLY_USE_SYMBOLIZER) ...@@ -72,11 +51,21 @@ if (FOLLY_USE_SYMBOLIZER)
ExceptionTracerLib.h ExceptionTracerLib.h
StackTrace.h StackTrace.h
DESTINATION 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( install(
EXPORT folly_exception_tracer EXPORT folly_exception_tracer
DESTINATION share/folly DESTINATION ${CMAKE_INSTALL_DIR}
NAMESPACE Folly:: NAMESPACE Folly::
FILE folly-exception-tracer-targets.cmake 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