Skip to content

Commit

Permalink
Use package's found variable in the config script
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
friendlyanon committed Sep 13, 2024
1 parent 38a761c commit 7a251f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions cmake-init/templates/common/cmake/install-config.cmake
Original file line number Diff line number Diff line change
@@ -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 %}
3 changes: 2 additions & 1 deletion cmake-init/templates/common/cmake/install-rules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ set(CMAKE_INSTALL_LIBDIR lib CACHE PATH ""){% end %}
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

# find_package(<package>) call for consumers to find this project
# find_package(<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(
Expand Down

0 comments on commit 7a251f6

Please sign in to comment.