As mentioned in https://github.com/TriBITSPub/TriBITS/issues/63#issuecomment-1420845228 and discussed in more detail in CMake Issue #24378 there is a problem with building, packaging, and installing from a binary package, and then downstream CMake projects using the installed CMake packages using find_package(<Package>). The problem is that the <Package>Config.cmake files will not easily know where to find their upstream dependencies.
Add new var <Project>_SUPER_INSTALL_PREFIX (in addition to <Project>_SET_GROUP_AND_PERMISSIONS_ON_INSTALL_BASE_DIR as they have different purposes) ...
Have TriBITS-generated <Package>Config.cmake files use set(<ExternalPackage>_DIR "???") and find_dependency(<ExternalPackage>) (where <ExternalPackage>_DIR is either set to a relative or absolute path as described below).
Add new var <ExternalPackage>_USE_RELATIVE_PATH:
If <ExternalPackage>_USE_RELATIVE_PATH is empty, then set to TRUE if <ExternalPackage>_DIR returned from find_package(<ExternalPackage>) (or <Package>_TRIBITS_COMPLIANT_PACKAGE_CONFIG_FILE_DIR if <ExternalPackage>_DIR is not set) is a subdir of <Project>_SUPER_INSTALL_PREFIX
If <ExternalPackage>_USE_RELATIVE_PATH is TRUE, then use a relative path from the TriBITS-generated installed <Package>Config.cmake file to <ExternalPackage>_DIR (or <Package>_TRIBITS_COMPLIANT_PACKAGE_CONFIG_FILE_DIR if <ExternalPackage>_DIR is not set)
If <ExternalPackage>_USE_RELATIVE_PATH is FALSE, then use the absolute path to <ExternalPackage>_DIR (or <Package>_TRIBITS_COMPLIANT_PACKAGE_CONFIG_FILE_DIR if <ExternalPackage>_DIR is not set)
Change TriBITS-generated <Package>Config.cmake files to call find_dependency(<ExternalPackage> CONFIG REQUIRED) on all upstream dependencies and find a way for that to not interfere with inner find_dependency(<ExternalPackage) calls that find non-TriBITS-compliant external packages. (Idea: pass in TRIBITS_COMPLIANT as the version to find_package() or find_dependency() and make the TriBITS-generated <ExternalPackage>ConfigVersion.cmake file look for that instead of the current hack based on the variable TRIBITS_FINDING_RAW_<tplName>_PACKAGE_FIRST.)
The above proposed implementation would solve the Spack binary install use case by setting <Project>_SUPER_INSTALL_PREFIX to the base Spack package install dir and then all paths would be relative to that directory as well.
NOTE: We would have to also make all library paths relative as well according to the above process (i.e. based on the values of <ExternalPackage>_USE_RELATIVE_PATH and <Project>_SUPER_INSTALL_PREFIX).
Parent Issue:
63
Description
As mentioned in https://github.com/TriBITSPub/TriBITS/issues/63#issuecomment-1420845228 and discussed in more detail in CMake Issue #24378 there is a problem with building, packaging, and installing from a binary package, and then downstream CMake projects using the installed CMake packages using
find_package(<Package>)
. The problem is that the<Package>Config.cmake
files will not easily know where to find their upstream dependencies.Proposed implementation
The proposed solution to this problem discussed in CMake Issue #24378 comment is outlined below:
Add new var
<Project>_SUPER_INSTALL_PREFIX
(in addition to<Project>_SET_GROUP_AND_PERMISSIONS_ON_INSTALL_BASE_DIR
as they have different purposes) ...Have TriBITS-generated
<Package>Config.cmake
files useset(<ExternalPackage>_DIR "???")
andfind_dependency(<ExternalPackage>)
(where<ExternalPackage>_DIR
is either set to a relative or absolute path as described below).Add new var
<ExternalPackage>_USE_RELATIVE_PATH
:If
<ExternalPackage>_USE_RELATIVE_PATH
is empty, then set toTRUE
if<ExternalPackage>_DIR
returned fromfind_package(<ExternalPackage>)
(or<Package>_TRIBITS_COMPLIANT_PACKAGE_CONFIG_FILE_DIR
if<ExternalPackage>_DIR
is not set) is a subdir of<Project>_SUPER_INSTALL_PREFIX
If
<ExternalPackage>_USE_RELATIVE_PATH
isTRUE
, then use a relative path from the TriBITS-generated installed<Package>Config.cmake
file to<ExternalPackage>_DIR
(or<Package>_TRIBITS_COMPLIANT_PACKAGE_CONFIG_FILE_DIR
if<ExternalPackage>_DIR
is not set)If
<ExternalPackage>_USE_RELATIVE_PATH
isFALSE
, then use the absolute path to<ExternalPackage>_DIR
(or<Package>_TRIBITS_COMPLIANT_PACKAGE_CONFIG_FILE_DIR
if<ExternalPackage>_DIR
is not set)Change TriBITS-generated
<Package>Config.cmake
files to callfind_dependency(<ExternalPackage> CONFIG REQUIRED)
on all upstream dependencies and find a way for that to not interfere with innerfind_dependency(<ExternalPackage)
calls that find non-TriBITS-compliant external packages. (Idea: pass inTRIBITS_COMPLIANT
as the version tofind_package()
orfind_dependency()
and make the TriBITS-generated<ExternalPackage>ConfigVersion.cmake
file look for that instead of the current hack based on the variableTRIBITS_FINDING_RAW_<tplName>_PACKAGE_FIRST
.)The above proposed implementation would solve the Spack binary install use case by setting
<Project>_SUPER_INSTALL_PREFIX
to the base Spack package install dir and then all paths would be relative to that directory as well.NOTE: We would have to also make all library paths relative as well according to the above process (i.e. based on the values of
<ExternalPackage>_USE_RELATIVE_PATH
and<Project>_SUPER_INSTALL_PREFIX
).