Skip to content

Commit 7a251f6

Browse files
committed
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 <name>_FOUND variable to true at the start of the file, because "find_dependency" sets the variable only if something could not be found.
1 parent 38a761c commit 7a251f6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
{% if pm %}include(CMakeFindDependencyMacro)
1+
{% if pm %}set({= name =}_FOUND YES)
2+
3+
include(CMakeFindDependencyMacro)
24
find_dependency({% if c %}json-c{% else %}fmt{% end %})
35

4-
if({% if c %}json-c{% else %}fmt{% end %}_FOUND)
6+
if({= name =}_FOUND)
57
{% end %}include("${CMAKE_CURRENT_LIST_DIR}/{= name =}Targets.cmake"){% if pm %}
68
endif(){% end %}

cmake-init/templates/common/cmake/install-rules.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ set(CMAKE_INSTALL_LIBDIR lib CACHE PATH ""){% end %}
1212
include(CMakePackageConfigHelpers)
1313
include(GNUInstallDirs)
1414

15-
# find_package(<package>) call for consumers to find this project
15+
# find_package(<package>) call for consumers to find this project{% if pm %}
16+
# should match the name of variable set in the install-config.cmake script{% end %}
1617
set(package {= name =})
1718

1819
install(

0 commit comments

Comments
 (0)