Skip to content

Commit

Permalink
Add CrowConfig.cmake and related files
Browse files Browse the repository at this point in the history
This patch allows downstream projects to use Crow simply by
including the following lines in their CMakeLists.txt:

    find_package(Crow CONFIG REQUIRED)
    target_link_libraries(myProject Crow::crow)

All transitive dependencies for the project are then managed
internally, not requiring downstream projects to change their
source when upgrading to newer versions of Crow.
  • Loading branch information
AmateurECE committed Jun 13, 2021
1 parent fc27f73 commit b35041e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
21 changes: 20 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/crow_all.h
# Amalgamation
add_custom_target(amalgamation ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/crow_all.h)

add_library(crow INTERFACE)
add_dependencies(crow amalgamation)
target_include_directories(crow INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>)

# Examples
if(BUILD_EXAMPLES)
add_subdirectory(examples)
Expand All @@ -74,4 +80,17 @@ endif()
#####################################
# Install Files
#####################################
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/crow_all.h DESTINATION include)
# Install the library (fake, it doesn't have any library files--just used to create the export)
install(TARGETS crow EXPORT CrowConfigTargets)

# Install the header file
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/crow_all.h" DESTINATION include)

# Install the export file
install(EXPORT CrowConfigTargets FILE CrowConfigTargets.cmake NAMESPACE Crow:: DESTINATION lib/cmake/Crow)

# Write and install Config*.cmake files
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)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/CrowConfigVersion.cmake" VERSION 0.2 COMPATIBILITY AnyNewerVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/CrowConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/CrowConfigVersion.cmake" DESTINATION lib/cmake/Crow)
19 changes: 19 additions & 0 deletions cmake/CrowConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(Threads)
find_dependency(ZLIB)
if (MSVC)
set(Boost_USE_STATIC_LIBS ON)
find_dependency(Boost 1.64.0 COMPONENTS system thread regex)
else()
find_dependency(Boost 1.64.0 COMPONENTS system thread)
endif()

find_dependency(OpenSSL)

include("${CMAKE_CURRENT_LIST_DIR}/CrowConfigTargets.cmake")
check_required_components("@PROJECT_NAME@")
set(@PROJECT_NAME@_LIBRARIES ZLIB::ZLIB ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${OpenSSL_LIBRARIES})
set_target_properties(Crow::crow PROPERTIES
INTERFACE_LINK_LIBRARIES "${@PROJECT_NAME@_LIBRARIES}")

0 comments on commit b35041e

Please sign in to comment.