From 5cc8349f1d24ce7b81a619511819ec631c921642 Mon Sep 17 00:00:00 2001 From: Luca Schlecker Date: Sun, 29 Aug 2021 16:20:45 +0200 Subject: [PATCH] add find_package support. --- CMakeLists.txt | 25 ++++++++++++++++++++++++- cmake/CrowConfig.cmake.in | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 cmake/CrowConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 2759db0da..f667c5124 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,12 @@ option(CROW_INSTALL "Add install step for Crow" ON ) ##################################### add_library(Crow INTERFACE) add_library(Crow::Crow ALIAS Crow) -target_include_directories(Crow INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) + +target_include_directories(Crow + INTERFACE + $ + $ +) find_package(Boost 1.64 COMPONENTS system date_time REQUIRED) find_package(Threads REQUIRED) @@ -81,7 +86,25 @@ endif() # Install Files ##################################### if(CROW_INSTALL) + install(TARGETS Crow EXPORT CrowTargets) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include) + + install(EXPORT CrowTargets + FILE CrowTargets.cmake + NAMESPACE Crow:: + DESTINATION lib/cmake/Crow + ) + + include(CMakePackageConfigHelpers) + configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CrowConfig.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/CrowConfig.cmake" + INSTALL_DESTINATION lib/cmake/Crow + ) + install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/CrowConfig.cmake" + DESTINATION lib/cmake/Crow + ) endif() set(CPACK_GENERATOR "DEB") diff --git a/cmake/CrowConfig.cmake.in b/cmake/CrowConfig.cmake.in new file mode 100644 index 000000000..4b4485dd7 --- /dev/null +++ b/cmake/CrowConfig.cmake.in @@ -0,0 +1,24 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) +find_dependency(Boost 1.64 COMPONENTS system date_time) +find_dependency(Threads) +find_dependency(ZLIB) +find_dependency(OpenSSL) + +include("${CMAKE_CURRENT_LIST_DIR}/CrowTargets.cmake") +check_required_components("@PROJECT_NAME@") + +set(CROW_DEPLIBS Boost::boost Boost::system Boost::date_time Threads::Threads) + +if(OPENSSL_FOUND) + list(APPEND CROW_DEPLIBS OpenSSL::SSL) +endif() + +if(ZLIB_FOUND) + list(APPEND CROW_DEPLIBS ZLIB::ZLIB) +endif() + +set_target_properties(Crow::Crow PROPERTIES + INTERFACE_LINK_LIBRARIES "${CROW_DEPLIBS}" +)