From 7a251f6182eca2a7ea2464e8d50e74b59ec01daf Mon Sep 17 00:00:00 2001 From: friendlyanon Date: Fri, 13 Sep 2024 18:05:47 +0200 Subject: [PATCH] Use package's found variable in the config script Since "find_dependency" sets the found variable to false, this can be used to conveniently check at the end before including the export set whether all dependencies were found in a non-REQUIRED call. This requires setting the _FOUND variable to true at the start of the file, because "find_dependency" sets the variable only if something could not be found. --- cmake-init/templates/common/cmake/install-config.cmake | 6 ++++-- cmake-init/templates/common/cmake/install-rules.cmake | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmake-init/templates/common/cmake/install-config.cmake b/cmake-init/templates/common/cmake/install-config.cmake index a966dfd..0a96ba5 100644 --- a/cmake-init/templates/common/cmake/install-config.cmake +++ b/cmake-init/templates/common/cmake/install-config.cmake @@ -1,6 +1,8 @@ -{% if pm %}include(CMakeFindDependencyMacro) +{% if pm %}set({= name =}_FOUND YES) + +include(CMakeFindDependencyMacro) find_dependency({% if c %}json-c{% else %}fmt{% end %}) -if({% if c %}json-c{% else %}fmt{% end %}_FOUND) +if({= name =}_FOUND) {% end %}include("${CMAKE_CURRENT_LIST_DIR}/{= name =}Targets.cmake"){% if pm %} endif(){% end %} diff --git a/cmake-init/templates/common/cmake/install-rules.cmake b/cmake-init/templates/common/cmake/install-rules.cmake index 5d4ae8c..17c837f 100644 --- a/cmake-init/templates/common/cmake/install-rules.cmake +++ b/cmake-init/templates/common/cmake/install-rules.cmake @@ -12,7 +12,8 @@ set(CMAKE_INSTALL_LIBDIR lib CACHE PATH ""){% end %} include(CMakePackageConfigHelpers) include(GNUInstallDirs) -# find_package() call for consumers to find this project +# find_package() call for consumers to find this project{% if pm %} +# should match the name of variable set in the install-config.cmake script{% end %} set(package {= name =}) install(