From ffaba93aabdf50f20133473cebfb19f3a65560ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rimas=20Misevi=C4=8Dius?= Date: Sun, 24 Sep 2023 19:56:43 +0300 Subject: [PATCH] Add export configuration to CMakeLists.txt More info: * https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Export%20Configuration.html * https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html * https://stackoverflow.com/a/25681179 --- CMakeLists.txt | 43 +++++++++++++++++++++++++++++++++--- cmake/upaurl-config.cmake.in | 3 +++ 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 cmake/upaurl-config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index f91c19b..fb24942 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ if(POLICY CMP0074) endif() # Project settings -project(upa_url LANGUAGES CXX) +project(upa_url VERSION 0.0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard") # Options @@ -99,8 +99,9 @@ if (URL_USE_LIBS) src/url_percent_encode.cpp src/url_search_params.cpp src/url_utf.cpp) - target_include_directories(upaurl - PUBLIC include) + target_include_directories(upaurl PUBLIC + $ + $) endif() add_library(upa::url ALIAS upaurl) target_include_directories(upaurl PRIVATE ${ICU_INCLUDE_DIR}) @@ -190,6 +191,7 @@ endif() # Install include(GNUInstallDirs) +include(CMakePackageConfigHelpers) install( DIRECTORY include/upa @@ -198,5 +200,40 @@ install( install( TARGETS upaurl + EXPORT upaurl-targets DESTINATION ${CMAKE_INSTALL_LIBDIR} ) + +install( + EXPORT upaurl-targets + FILE upaurl-targets.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/upaurl +) + +# generate the config file that includes the exports +configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/upaurl-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/upaurl-config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/upaurl + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) +# generate the version file for the config file +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/upaurl-config-version.cmake + COMPATIBILITY SameMinorVersion +) + +# install the generated configuration files +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/upaurl-config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/upaurl-config-version.cmake + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/upaurl" +) + +# generate the export targets for the build tree +# needs to be after the install(TARGETS) command +export( + EXPORT upaurl-targets + FILE ${CMAKE_CURRENT_BINARY_DIR}/upaurl-targets.cmake +) diff --git a/cmake/upaurl-config.cmake.in b/cmake/upaurl-config.cmake.in new file mode 100644 index 0000000..b02e042 --- /dev/null +++ b/cmake/upaurl-config.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/upaurl-targets.cmake")