From c84bf55535610481f219c1fcd35b4a7dd1a0a59f Mon Sep 17 00:00:00 2001 From: alin Date: Fri, 7 Feb 2025 15:01:01 +0100 Subject: [PATCH 01/19] Attempt to fix strange modules path resolving Not sure why CPM does not want to include the modules, but this needs to be resolved asap. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f570192..216dbaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,8 +12,8 @@ option(RSP_ENABLE_ANSI "Enable ANSI output" false) # -------------------------------------------------------------------------------------------------------------- # # Append this package's cmake scripts in module path -list(FIND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" hasModulePath) -if(${hasModulePath} STREQUAL "-1") +list(FIND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" has_cmake_scripts_module_path) +if(has_cmake_scripts_module_path EQUAL -1) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") endif() From fb9be5c67a106e6f72bb89bbdf6dfe40ad6d3695 Mon Sep 17 00:00:00 2001 From: alin Date: Fri, 7 Feb 2025 15:01:17 +0100 Subject: [PATCH 02/19] Add how to install guide (incomplete) --- docs/+current/index.md | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/docs/+current/index.md b/docs/+current/index.md index b56d1aa..9f227d4 100644 --- a/docs/+current/index.md +++ b/docs/+current/index.md @@ -17,4 +17,37 @@ author: RSP Systems A/S ## How to install -_TODO: ...incomplete, please review documentation at a later point_ +### Via CPM + +If you are using [CPM](https://github.com/cpm-cmake/CPM.cmake), then you can install "CMake Scripts" using the following: + +```cmake +set(RSP_CMAKE_SCRIPTS_VERSION "0.1.0") + +CPMAddPackage( + NAME "rsp-cmake-scripts" + GIT_TAG "${RSP_CMAKE_SCRIPTS_VERSION}" + GITHUB_REPOSITORY "rsps/cmake-scripts" +) +``` + +### Via Fetch Content + +Alternatively, you can also use cmake's [`FetchContent`](https://cmake.org/cmake/help/latest/module/FetchContent.html) module: + +```cmake +set(RSP_CMAKE_SCRIPTS_VERSION "0.1.0") + +include(FetchContent) +FetchContent_Declare( + rsp-cmake-scripts + GIT_REPOSITORY https://github.com/rsps/cmake-scripts + GIT_TAG ${RSP_CMAKE_SCRIPTS_VERSION} + FIND_PACKAGE_ARGS NAMES rsp-cmake-scripts +) +FetchContent_MakeAvailable(rsp-cmake-scripts) +``` + +!!! note "Note" + "CMake Scripts" depends on [CPM](https://github.com/cpm-cmake/CPM.cmake) for its dependencies. It will + automatically be included, even when you install this project using cmake's `FetchContent` module. From 9e906e81d460ca5c5a615d25a2f8c6f87cb7143b Mon Sep 17 00:00:00 2001 From: alin Date: Sat, 8 Feb 2025 14:42:41 +0100 Subject: [PATCH 03/19] Change messages to VERBOSE mode No need to pollute the console with too many messages. --- dependencies.cmake | 4 ++-- dev-dependencies.cmake | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dependencies.cmake b/dependencies.cmake index 1909088..c1023d3 100644 --- a/dependencies.cmake +++ b/dependencies.cmake @@ -5,13 +5,13 @@ include_guard() function(install_dependencies) - message(STATUS "Installing Dependencies for ${PROJECT_NAME}") + message(VERBOSE "Installing Dependencies for ${PROJECT_NAME}") # Avoid building tests for dependencies... set(BUILD_TESTING off) # Add dependencies here... - message(STATUS " N/A") + message(VERBOSE " N/A") endfunction() safeguard_properties(CALLBACK "install_dependencies" PROPERTIES BUILD_TESTING) diff --git a/dev-dependencies.cmake b/dev-dependencies.cmake index 53fb1ca..3a190fc 100644 --- a/dev-dependencies.cmake +++ b/dev-dependencies.cmake @@ -8,13 +8,13 @@ include_guard() include("dependencies.cmake") function(install_dev_dependencies) - message(STATUS "Installing Development Dependencies for ${PROJECT_NAME}") + message(VERBOSE "Installing Development Dependencies for ${PROJECT_NAME}") # Avoid building tests for dependencies... set(BUILD_TESTING off) # Add dev-dependencies here... - message(STATUS " N/A") + message(VERBOSE " N/A") endfunction() safeguard_properties(CALLBACK "install_dev_dependencies" PROPERTIES BUILD_TESTING) From 0b622e44dc88f4ce9d1bc91e181682f9d8a083f5 Mon Sep 17 00:00:00 2001 From: alin Date: Sat, 8 Feb 2025 15:02:36 +0100 Subject: [PATCH 04/19] Simplify "is top level" checks Didn't know about PROJECT_IS_TOP_LEVEL --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 216dbaf..ed05248 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,8 @@ project(rsp-cmake-scripts ) # Ensure parent project has modules and other properties available. -if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) +#if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) +if(NOT PROJECT_IS_TOP_LEVEL) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) set("${PROJECT_NAME}_VERSION" "${PROJECT_VERSION}" PARENT_SCOPE) set("${PROJECT_NAME}_SEMVER" "${version_SEMVER}" PARENT_SCOPE) @@ -62,7 +63,7 @@ endif() include("dependencies.cmake") -if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) +if(PROJECT_IS_TOP_LEVEL) include("dev-dependencies.cmake") endif() @@ -82,7 +83,7 @@ endif () # Post-dependencies project setup # -------------------------------------------------------------------------------------------------------------- # -if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) +if(PROJECT_IS_TOP_LEVEL) include("rsp/debug") include("rsp/logging") endif() From 4643024453310d820cf48d00000c61d788ac6048 Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 09:31:30 +0100 Subject: [PATCH 05/19] Quote arguments in example --- docs/+current/index.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/+current/index.md b/docs/+current/index.md index 9f227d4..a366f9d 100644 --- a/docs/+current/index.md +++ b/docs/+current/index.md @@ -26,7 +26,7 @@ set(RSP_CMAKE_SCRIPTS_VERSION "0.1.0") CPMAddPackage( NAME "rsp-cmake-scripts" - GIT_TAG "${RSP_CMAKE_SCRIPTS_VERSION}" + VERSION "${RSP_CMAKE_SCRIPTS_VERSION}" GITHUB_REPOSITORY "rsps/cmake-scripts" ) ``` @@ -40,12 +40,11 @@ set(RSP_CMAKE_SCRIPTS_VERSION "0.1.0") include(FetchContent) FetchContent_Declare( - rsp-cmake-scripts - GIT_REPOSITORY https://github.com/rsps/cmake-scripts - GIT_TAG ${RSP_CMAKE_SCRIPTS_VERSION} - FIND_PACKAGE_ARGS NAMES rsp-cmake-scripts + "rsp-cmake-scripts" + GIT_REPOSITORY "https://github.com/rsps/cmake-scripts" + GIT_TAG "${RSP_CMAKE_SCRIPTS_VERSION}" ) -FetchContent_MakeAvailable(rsp-cmake-scripts) +FetchContent_MakeAvailable("rsp-cmake-scripts") ``` !!! note "Note" From d1333013eea201d09289d9f089e522c1d8fc4ac0 Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 09:33:07 +0100 Subject: [PATCH 06/19] Highlight defect area This part simply will not work, when any kind of package installation is wrapped inside a cmake function, due to cmake's variable scope. It is pure luck that our `FetchContent_Declare` example works. --- CMakeLists.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed05248..93b3976 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,9 +50,20 @@ project(rsp-cmake-scripts ) # Ensure parent project has modules and other properties available. -#if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) if(NOT PROJECT_IS_TOP_LEVEL) + # TODO: PROBLEM - works only if FetchContent is done from the top-level + # TODO: CMakeLists.txt file - or this is pure luck, if it works!!! + # When FetchContent_MakeAvailable() is used, in a top-level project, + # this will work fine, for adding this project's module path(s). set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) + + # TODO: But, if CPM is used for obtaining project, then this will sadly + # TODO: not work. + + # TODO: Possible Solution: We need to create pacakge config and version files: + # TODO: @see https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#package-configuration-file + # TODO: @see https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html#command:configure_package_config_file + set("${PROJECT_NAME}_VERSION" "${PROJECT_VERSION}" PARENT_SCOPE) set("${PROJECT_NAME}_SEMVER" "${version_SEMVER}" PARENT_SCOPE) endif() From 16e91264a6020eb20de5180e18355fd4712fecaa Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 10:28:26 +0100 Subject: [PATCH 07/19] Add cmake config template file (incomplete) For now, this acts as a test to see how both cmake's FetchContent module and CPM treats it. --- resources/cmake/rsp-cmake-scripts-config.cmake.in | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 resources/cmake/rsp-cmake-scripts-config.cmake.in diff --git a/resources/cmake/rsp-cmake-scripts-config.cmake.in b/resources/cmake/rsp-cmake-scripts-config.cmake.in new file mode 100644 index 0000000..fa72b4c --- /dev/null +++ b/resources/cmake/rsp-cmake-scripts-config.cmake.in @@ -0,0 +1,6 @@ +@PACKAGE_INIT@ + +message(NOTICE "RSP CMake Scripts Config file...") + +# TODO: Test of variable... +set(RSP_FOO "bar") \ No newline at end of file From 31a17c74ea64b547d6fbc6224ecc733f0a2651c8 Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 10:29:23 +0100 Subject: [PATCH 08/19] Add package config file settings (incomplete) For now, this is a test of the configuration mechanism, to see how cmake's FetchContent module and CPM treats it. --- CMakeLists.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93b3976..f953c63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,3 +114,27 @@ endif () # output_ansi_demo() # dump(CMAKE_MODULE_PATH FOO BAR PROJECT_NAME) + +# -------------------------------------------------------------------------------------------------------------- # +# TODO: Package Configuration +# -------------------------------------------------------------------------------------------------------------- # + +include(CMakePackageConfigHelpers) + +configure_package_config_file( + "resources/cmake/rsp-cmake-scripts-config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/rsp-cmake-scripts-config.cmake" + + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/rsp" + #PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR +) + +# TODO: CMake Version file + +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/rsp-cmake-scripts-config.cmake" + # "${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake" + DESTINATION + "${CMAKE_INSTALL_LIBDIR}/cmake/rsp" +) \ No newline at end of file From 348115915acd29e8c9fe37cf8da53991dd192bda Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 10:45:03 +0100 Subject: [PATCH 09/19] Change location where configuration file is installed --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f953c63..8d5cf8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,7 +123,7 @@ include(CMakePackageConfigHelpers) configure_package_config_file( "resources/cmake/rsp-cmake-scripts-config.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/rsp-cmake-scripts-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/cmake/rsp/rsp-cmake-scripts-config.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/rsp" #PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR @@ -133,7 +133,7 @@ configure_package_config_file( install( FILES - "${CMAKE_CURRENT_BINARY_DIR}/rsp-cmake-scripts-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/cmake/rsp/rsp-cmake-scripts-config.cmake" # "${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/rsp" From 3be550012e3e987ebe769a3c14a681689ab2bc60 Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 11:05:54 +0100 Subject: [PATCH 10/19] Move config template into cmake directory --- {resources/cmake => cmake}/rsp-cmake-scripts-config.cmake.in | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {resources/cmake => cmake}/rsp-cmake-scripts-config.cmake.in (100%) diff --git a/resources/cmake/rsp-cmake-scripts-config.cmake.in b/cmake/rsp-cmake-scripts-config.cmake.in similarity index 100% rename from resources/cmake/rsp-cmake-scripts-config.cmake.in rename to cmake/rsp-cmake-scripts-config.cmake.in From e98348029654b34e6227e71b50700be4749a2645 Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 11:06:10 +0100 Subject: [PATCH 11/19] Attempt to set example var in parent scope --- cmake/rsp-cmake-scripts-config.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/rsp-cmake-scripts-config.cmake.in b/cmake/rsp-cmake-scripts-config.cmake.in index fa72b4c..6e91c92 100644 --- a/cmake/rsp-cmake-scripts-config.cmake.in +++ b/cmake/rsp-cmake-scripts-config.cmake.in @@ -3,4 +3,4 @@ message(NOTICE "RSP CMake Scripts Config file...") # TODO: Test of variable... -set(RSP_FOO "bar") \ No newline at end of file +set(RSP_FOO "bar" PARENT_SCOPE) \ No newline at end of file From 73c65959f1ef69f4d8a18488424aa88ae8097ec3 Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 11:06:38 +0100 Subject: [PATCH 12/19] Attempt different setup for configuration file installation --- CMakeLists.txt | 51 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d5cf8a..ffd1bcf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,20 +121,55 @@ endif () include(CMakePackageConfigHelpers) -configure_package_config_file( - "resources/cmake/rsp-cmake-scripts-config.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/cmake/rsp/rsp-cmake-scripts-config.cmake" +# Introduce variables: +# * CMAKE_INSTALL_LIBDIR +# * CMAKE_INSTALL_BINDIR +# * CMAKE_INSTALL_INCLUDEDIR +include(GNUInstallDirs) + +# Layout. This works for all platforms: +# * /lib*/cmake/ +# * /lib*/ +# * /include/ +set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + +set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}") + +# Configuration +# set(version_config "${generated_dir}/${PROJECT_NAME}-version.cmake") +set(project_config "${generated_dir}/${PROJECT_NAME}-config.cmake") + +#configure_package_config_file( +# "cmake/rsp-cmake-scripts-config.cmake.in" +# "${CMAKE_CURRENT_BINARY_DIR}/cmake/rsp/rsp-cmake-scripts-config.cmake" +# +# INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/rsp" +# #PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR +#) - INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/rsp" - #PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR +configure_package_config_file( + "cmake/${PROJECT_NAME}-config.cmake.in" + "${project_config}" + INSTALL_DESTINATION "${config_install_dir}" ) # TODO: CMake Version file +#install( +# FILES +# "${CMAKE_CURRENT_BINARY_DIR}/cmake/rsp/rsp-cmake-scripts-config.cmake" +# # "${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake" +# DESTINATION +# "${CMAKE_INSTALL_LIBDIR}/cmake/rsp" +#) + +# Config +# * /lib/cmake/Foo/FooConfig.cmake +# * /lib/cmake/Foo/FooConfigVersion.cmake install( FILES - "${CMAKE_CURRENT_BINARY_DIR}/cmake/rsp/rsp-cmake-scripts-config.cmake" - # "${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake" + "${project_config}" + #"${version_config}" DESTINATION - "${CMAKE_INSTALL_LIBDIR}/cmake/rsp" + "${config_install_dir}" ) \ No newline at end of file From 6e0a0ef19498118993ace285ae3ee2c6482e0da6 Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 11:15:41 +0100 Subject: [PATCH 13/19] Enable CXX as project language This is needed or the GNUInstallDirs module isn't going to work as intended. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ffd1bcf..b09b2d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ project(rsp-cmake-scripts VERSION "${version_VERSION}" DESCRIPTION "A collection of CMake scripts for C++ projects" HOMEPAGE_URL "https://github.com/rsps/cmake-scripts" - LANGUAGES NONE + LANGUAGES "CXX" ) # Ensure parent project has modules and other properties available. From 0bfef45923fc93f2d59dc463d9318ddebb072911 Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 11:42:17 +0100 Subject: [PATCH 14/19] Revert "Enable CXX as project language" This reverts commit 6e0a0ef19498118993ace285ae3ee2c6482e0da6. Had no effect on the config file's state of being read by the consuming client project. Thus, the GNUInstallDirs are not needed! --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b09b2d5..ffd1bcf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ project(rsp-cmake-scripts VERSION "${version_VERSION}" DESCRIPTION "A collection of CMake scripts for C++ projects" HOMEPAGE_URL "https://github.com/rsps/cmake-scripts" - LANGUAGES "CXX" + LANGUAGES NONE ) # Ensure parent project has modules and other properties available. From 9b139571c9d5c66b7d44bd89f77c92ed2fe38ce2 Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 11:57:04 +0100 Subject: [PATCH 15/19] Add call to check_required_components() --- cmake/rsp-cmake-scripts-config.cmake.in | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmake/rsp-cmake-scripts-config.cmake.in b/cmake/rsp-cmake-scripts-config.cmake.in index 6e91c92..381ac77 100644 --- a/cmake/rsp-cmake-scripts-config.cmake.in +++ b/cmake/rsp-cmake-scripts-config.cmake.in @@ -3,4 +3,9 @@ message(NOTICE "RSP CMake Scripts Config file...") # TODO: Test of variable... -set(RSP_FOO "bar" PARENT_SCOPE) \ No newline at end of file +set(RSP_FOO "bar" PARENT_SCOPE) + +# "[...] should be called at the end of the package configuration file even if the package does not have any +# components. [...]" +# @see https://cmake.org/cmake/help/git-stage/guide/importing-exporting/index.html#creating-a-package-configuration-file +check_required_components("rsp-cmake-scripts") \ No newline at end of file From 5f8035b5c60f46bdc18d290bbcc0578838c22dd8 Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 12:41:45 +0100 Subject: [PATCH 16/19] Rewrite package config Not sure if this is going to work without the "targets" part, but example code looks more promising that previous. --- CMakeLists.txt | 76 +++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ffd1bcf..573c4ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ project(rsp-cmake-scripts VERSION "${version_VERSION}" DESCRIPTION "A collection of CMake scripts for C++ projects" HOMEPAGE_URL "https://github.com/rsps/cmake-scripts" - LANGUAGES NONE + LANGUAGES "CXX" ) # Ensure parent project has modules and other properties available. @@ -119,57 +119,45 @@ endif () # TODO: Package Configuration # -------------------------------------------------------------------------------------------------------------- # -include(CMakePackageConfigHelpers) - -# Introduce variables: -# * CMAKE_INSTALL_LIBDIR -# * CMAKE_INSTALL_BINDIR -# * CMAKE_INSTALL_INCLUDEDIR include(GNUInstallDirs) +include(CMakePackageConfigHelpers) -# Layout. This works for all platforms: -# * /lib*/cmake/ -# * /lib*/ -# * /include/ -set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") - -set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}") - -# Configuration -# set(version_config "${generated_dir}/${PROJECT_NAME}-version.cmake") -set(project_config "${generated_dir}/${PROJECT_NAME}-config.cmake") - -#configure_package_config_file( -# "cmake/rsp-cmake-scripts-config.cmake.in" -# "${CMAKE_CURRENT_BINARY_DIR}/cmake/rsp/rsp-cmake-scripts-config.cmake" +#install( +# TARGETS "${PROJECT_NAME}" +# EXPORT "${PROJECT_NAME}-export" +## INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} +## RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +## LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +## ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} +#) # -# INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/rsp" -# #PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR +## Export cmake targets +#install( +# EXPORT "${PROJECT_NAME}-export" +# FILE "${PROJECT_NAME}-targets.cmake" +# NAMESPACE "${PROJECT_NAME}::" +# DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" #) -configure_package_config_file( - "cmake/${PROJECT_NAME}-config.cmake.in" - "${project_config}" - INSTALL_DESTINATION "${config_install_dir}" +# Write config-version +write_basic_package_version_file( + ${PROJECT_NAME}-config-version.cmake + VERSION "${PROJECT_VERSION}" + COMPATIBILITY SameMinorVersion ) -# TODO: CMake Version file - -#install( -# FILES -# "${CMAKE_CURRENT_BINARY_DIR}/cmake/rsp/rsp-cmake-scripts-config.cmake" -# # "${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake" -# DESTINATION -# "${CMAKE_INSTALL_LIBDIR}/cmake/rsp" -#) +# Configure installable cmake config +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/rsp/${PROJECT_NAME}" + NO_SET_AND_CHECK_MACRO +) -# Config -# * /lib/cmake/Foo/FooConfig.cmake -# * /lib/cmake/Foo/FooConfigVersion.cmake +# Install config-version and config install( FILES - "${project_config}" - #"${version_config}" - DESTINATION - "${config_install_dir}" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/rsp/${PROJECT_NAME}" ) \ No newline at end of file From b7c74d6651be69a9b0ade94fd5d3e3cbc78156b0 Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 13:18:27 +0100 Subject: [PATCH 17/19] Attempt to install config files in CMAKE_FIND_PACKAGE_REDIRECTS_DIR Not sure about this, but seems that both CPM and find_package() uses this path to search for the configuration files first. --- CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 573c4ae..3b11daf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,9 +155,16 @@ configure_package_config_file( ) # Install config-version and config +#install( +# FILES +# "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" +# "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" +# DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/rsp/${PROJECT_NAME}" +#) + install( - FILES + FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/rsp/${PROJECT_NAME}" + DESTINATION "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}" ) \ No newline at end of file From 40c33672b92fcf83a400a0e3711ef3dc36bfe928 Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 15:14:32 +0100 Subject: [PATCH 18/19] Cleanup and remove *-config attempt This failed, and there seems to be no good way around it. Consuming packages MUST manually append to their CMAKE_MODULE_PATH. --- CMakeLists.txt | 74 ++----------------------- cmake/rsp-cmake-scripts-config.cmake.in | 11 ---- 2 files changed, 5 insertions(+), 80 deletions(-) delete mode 100644 cmake/rsp-cmake-scripts-config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b11daf..d4760f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,26 +46,16 @@ project(rsp-cmake-scripts VERSION "${version_VERSION}" DESCRIPTION "A collection of CMake scripts for C++ projects" HOMEPAGE_URL "https://github.com/rsps/cmake-scripts" - LANGUAGES "CXX" + LANGUAGES NONE ) +set("${PROJECT_NAME}_VERSION" "${PROJECT_VERSION}") +set("${PROJECT_NAME}_SEMVER" "${version_SEMVER}") # Ensure parent project has modules and other properties available. if(NOT PROJECT_IS_TOP_LEVEL) - # TODO: PROBLEM - works only if FetchContent is done from the top-level - # TODO: CMakeLists.txt file - or this is pure luck, if it works!!! - # When FetchContent_MakeAvailable() is used, in a top-level project, - # this will work fine, for adding this project's module path(s). set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) - - # TODO: But, if CPM is used for obtaining project, then this will sadly - # TODO: not work. - - # TODO: Possible Solution: We need to create pacakge config and version files: - # TODO: @see https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#package-configuration-file - # TODO: @see https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html#command:configure_package_config_file - - set("${PROJECT_NAME}_VERSION" "${PROJECT_VERSION}" PARENT_SCOPE) - set("${PROJECT_NAME}_SEMVER" "${version_SEMVER}" PARENT_SCOPE) + set("${PROJECT_NAME}_VERSION" "${${PROJECT_NAME}_VERSION}" PARENT_SCOPE) + set("${PROJECT_NAME}_SEMVER" "${${PROJECT_NAME}_SEMVER}" PARENT_SCOPE) endif() # -------------------------------------------------------------------------------------------------------------- # @@ -114,57 +104,3 @@ endif () # output_ansi_demo() # dump(CMAKE_MODULE_PATH FOO BAR PROJECT_NAME) - -# -------------------------------------------------------------------------------------------------------------- # -# TODO: Package Configuration -# -------------------------------------------------------------------------------------------------------------- # - -include(GNUInstallDirs) -include(CMakePackageConfigHelpers) - -#install( -# TARGETS "${PROJECT_NAME}" -# EXPORT "${PROJECT_NAME}-export" -## INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} -## RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} -## LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} -## ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} -#) -# -## Export cmake targets -#install( -# EXPORT "${PROJECT_NAME}-export" -# FILE "${PROJECT_NAME}-targets.cmake" -# NAMESPACE "${PROJECT_NAME}::" -# DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" -#) - -# Write config-version -write_basic_package_version_file( - ${PROJECT_NAME}-config-version.cmake - VERSION "${PROJECT_VERSION}" - COMPATIBILITY SameMinorVersion -) - -# Configure installable cmake config -configure_package_config_file( - "${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" - INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/rsp/${PROJECT_NAME}" - NO_SET_AND_CHECK_MACRO -) - -# Install config-version and config -#install( -# FILES -# "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" -# "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" -# DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/rsp/${PROJECT_NAME}" -#) - -install( - FILES - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" - DESTINATION "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}" -) \ No newline at end of file diff --git a/cmake/rsp-cmake-scripts-config.cmake.in b/cmake/rsp-cmake-scripts-config.cmake.in deleted file mode 100644 index 381ac77..0000000 --- a/cmake/rsp-cmake-scripts-config.cmake.in +++ /dev/null @@ -1,11 +0,0 @@ -@PACKAGE_INIT@ - -message(NOTICE "RSP CMake Scripts Config file...") - -# TODO: Test of variable... -set(RSP_FOO "bar" PARENT_SCOPE) - -# "[...] should be called at the end of the package configuration file even if the package does not have any -# components. [...]" -# @see https://cmake.org/cmake/help/git-stage/guide/importing-exporting/index.html#creating-a-package-configuration-file -check_required_components("rsp-cmake-scripts") \ No newline at end of file From 5d4829d8c9dcf3a31890d46ebf4bdda8a67770a2 Mon Sep 17 00:00:00 2001 From: alin Date: Mon, 10 Feb 2025 15:39:23 +0100 Subject: [PATCH 19/19] Fix install via CPM example --- docs/+current/index.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/+current/index.md b/docs/+current/index.md index a366f9d..1e5a950 100644 --- a/docs/+current/index.md +++ b/docs/+current/index.md @@ -29,8 +29,16 @@ CPMAddPackage( VERSION "${RSP_CMAKE_SCRIPTS_VERSION}" GITHUB_REPOSITORY "rsps/cmake-scripts" ) + +# IMPORTANT: Enable "rsp/*" modules in your project,... +list(APPEND CMAKE_MODULE_PATH "${rsp-cmake-scripts_SOURCE_DIR}/cmake") ``` +!!! info "`CMAKE_MODULE_PATH`" + At the time of this writing, CPM does not automatically support paths appended to `CMAKE_MODULE_PATH`. + To make use of this package's cmake modules, via CPM, you **MUST** manually append + this package's module path in your top-level `CMakeLists.txt`, as shown in the above install example. + ### Via Fetch Content Alternatively, you can also use cmake's [`FetchContent`](https://cmake.org/cmake/help/latest/module/FetchContent.html) module: