Skip to content

Commit

Permalink
Don't set <externalPkg>_DIR when using a find module (TriBITSPub#299)
Browse files Browse the repository at this point in the history
When find_package(<externalPkg>) uses a find module Find<exteranlPkg>.cmake
instead of a package config file <externalPkg>Config.cmake, the variable.
<externalPkg>_DIR is not set.  Therefore, it is best to not set
<externalPkg>_DIR in the TriBITS-geneated <tplName>Config.cmake file since
that is just confusing.

NOTE: This is only a situation that comes up when a TriBITS
FindTPL<tplName>.cmake module calls find_package(<externalPkg>).
  • Loading branch information
bartlettroscoe committed Oct 2, 2022
1 parent 7dbff5f commit 3bed9df
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@ function(tribits_extpkg_create_package_config_file_with_imported_targets
# Create <tplName>Config.cmake file
set(configFileStr "")
string(APPEND configFileStr
"include(CMakeFindDependencyMacro)\n"
"set(${externalPkg}_DIR \"${${externalPkg}_DIR}\")\n"
"include(CMakeFindDependencyMacro)\n" )
if (${externalPkg}_DIR)
string(APPEND configFileStr
"set(${externalPkg}_DIR \"${${externalPkg}_DIR}\")\n" )
endif()
string(APPEND configFileStr
"find_dependency(${externalPkg})\n"
"add_library(${tplName}::all_libs INTERFACE IMPORTED GLOBAL)\n"
)
Expand All @@ -130,3 +134,9 @@ function(tribits_extpkg_create_package_config_file_with_imported_targets
file(WRITE "${tplConfigFile}" "${configFileStr}")

endfunction()
#
# NOTE: Above, ${externalPkg}_DIR is only set when
# find_package(${externalPkg}) finds a package configure file
# ${externalPkg}Config.cmake and **not** when it uses a
# Find${externalPkg}.cmake module. Therefore, there is no reason to set
# ${externalPkg}_DIR i this file if it will not be used.

0 comments on commit 3bed9df

Please sign in to comment.