summaryrefslogtreecommitdiffstats
path: root/Source/cmFindPackageCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-02-21 21:00:24 (GMT)
committerBrad King <brad.king@kitware.com>2023-02-23 14:15:14 (GMT)
commitdf9c4b18720c6c8263c13641bc0a6452138d6fba (patch)
tree4301ddaee071056517ef6a0964d34e2627738987 /Source/cmFindPackageCommand.cxx
parent4da27a73bd10665e753194a4a14323c9069e9289 (diff)
downloadCMake-df9c4b18720c6c8263c13641bc0a6452138d6fba.zip
CMake-df9c4b18720c6c8263c13641bc0a6452138d6fba.tar.gz
CMake-df9c4b18720c6c8263c13641bc0a6452138d6fba.tar.bz2
find_package: Use <PACKAGENAME>_ROOT variables as search prefixes
Extend commit eb35d8884b (find_package: Use PackageName_ROOT variables as search prefixes, 2018-03-15, v3.12.0-rc1~349^2) to also check upper-case `<PACKAGENAME>_ROOT` variables. Add policy `CMP0144` to enable the behavior in a compatible way. Fixes: #24403
Diffstat (limited to 'Source/cmFindPackageCommand.cxx')
-rw-r--r--Source/cmFindPackageCommand.cxx43
1 files changed, 43 insertions, 0 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index dd00419..5f1a2c5 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -1841,13 +1841,56 @@ void cmFindPackageCommand::PushFindPackageRootPathStack()
} break;
}
+ // Add root paths from <PACKAGENAME>_ROOT CMake and environment variables,
+ // if they are different than <PackageName>_ROOT, and subject to CMP0144.
+ std::string const rootVAR = cmSystemTools::UpperCase(rootVar);
+ cmValue rootDEF;
+ cm::optional<std::string> rootENV;
+ if (rootVAR != rootVar) {
+ rootDEF = this->Makefile->GetDefinition(rootVAR);
+ if (rootDEF && (rootDEF.IsEmpty() || rootDEF == rootDef)) {
+ rootDEF = nullptr;
+ }
+ rootENV = cmSystemTools::GetEnvVar(rootVAR);
+ if (rootENV && (rootENV->empty() || rootENV == rootEnv)) {
+ rootENV = cm::nullopt;
+ }
+ }
+
+ switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0144)) {
+ case cmPolicies::WARN:
+ this->Makefile->MaybeWarnCMP0144(rootVAR, rootDEF, rootENV);
+ CM_FALLTHROUGH;
+ case cmPolicies::OLD:
+ // OLD behavior is to ignore the <PACKAGENAME>_ROOT variables.
+ rootDEF = nullptr;
+ rootENV = cm::nullopt;
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0144));
+ return;
+ case cmPolicies::NEW: {
+ // NEW behavior is to honor the <PACKAGENAME>_ROOT variables.
+ } break;
+ }
+
if (rootDef) {
cmExpandList(*rootDef, rootPaths);
}
+ if (rootDEF) {
+ cmExpandList(*rootDEF, rootPaths);
+ }
if (rootEnv) {
std::vector<std::string> p = cmSystemTools::SplitEnvPath(*rootEnv);
std::move(p.begin(), p.end(), std::back_inserter(rootPaths));
}
+ if (rootENV) {
+ std::vector<std::string> p = cmSystemTools::SplitEnvPath(*rootENV);
+ std::move(p.begin(), p.end(), std::back_inserter(rootPaths));
+ }
}
void cmFindPackageCommand::PopFindPackageRootPathStack()