diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeVersion.cmake | 2 | ||||
-rw-r--r-- | Source/cmFindPackageCommand.cxx | 126 | ||||
-rw-r--r-- | Source/cmFindPackageCommand.h | 3 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 47 | ||||
-rw-r--r-- | Source/cmMakefile.h | 6 | ||||
-rw-r--r-- | Source/cmPolicies.h | 5 | ||||
-rw-r--r-- | Source/cmSystemTools.cxx | 26 | ||||
-rw-r--r-- | Source/cmSystemTools.h | 3 |
8 files changed, 168 insertions, 50 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index efc7d87..0a8d6ac 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,7 +1,7 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 26) -set(CMake_VERSION_PATCH 20230221) +set(CMake_VERSION_PATCH 20230224) #set(CMake_VERSION_RC 0) set(CMake_VERSION_IS_DIRTY 0) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index c1b82ab..5f1a2c5 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -975,35 +975,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args) } } - { - // Allocate a PACKAGE_ROOT_PATH for the current find_package call. - this->Makefile->FindPackageRootPathStack.emplace_back(); - std::vector<std::string>& rootPaths = - this->Makefile->FindPackageRootPathStack.back(); - - // Add root paths from <PackageName>_ROOT CMake and environment variables, - // subject to CMP0074. - switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0074)) { - case cmPolicies::WARN: - this->Makefile->MaybeWarnCMP0074(this->Name); - CM_FALLTHROUGH; - case cmPolicies::OLD: - // OLD behavior is to ignore the <pkg>_ROOT variables. - break; - case cmPolicies::REQUIRED_IF_USED: - case cmPolicies::REQUIRED_ALWAYS: - this->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0074)); - break; - case cmPolicies::NEW: { - // NEW behavior is to honor the <pkg>_ROOT variables. - std::string const rootVar = this->Name + "_ROOT"; - this->Makefile->GetDefExpandList(rootVar, rootPaths, false); - cmSystemTools::GetPath(rootPaths, rootVar.c_str()); - } break; - } - } + this->PushFindPackageRootPathStack(); this->SetModuleVariables(components, componentVarDefs); @@ -1129,8 +1101,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args) // Restore original state of "_FIND_" variables set in SetModuleVariables() this->RestoreFindDefinitions(); - // Pop the package stack - this->Makefile->FindPackageRootPathStack.pop_back(); + this->PopFindPackageRootPathStack(); if (!this->DebugBuffer.empty()) { this->DebugMessage(this->DebugBuffer); @@ -1834,6 +1805,99 @@ void cmFindPackageCommand::AppendSuccessInformation() } } +void cmFindPackageCommand::PushFindPackageRootPathStack() +{ + // Allocate a PACKAGE_ROOT_PATH for the current find_package call. + this->Makefile->FindPackageRootPathStack.emplace_back(); + std::vector<std::string>& rootPaths = + this->Makefile->FindPackageRootPathStack.back(); + + // Add root paths from <PackageName>_ROOT CMake and environment variables, + // subject to CMP0074. + std::string const rootVar = this->Name + "_ROOT"; + cmValue rootDef = this->Makefile->GetDefinition(rootVar); + if (rootDef && rootDef.IsEmpty()) { + rootDef = nullptr; + } + cm::optional<std::string> rootEnv = cmSystemTools::GetEnvVar(rootVar); + if (rootEnv && rootEnv->empty()) { + rootEnv = cm::nullopt; + } + switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0074)) { + case cmPolicies::WARN: + this->Makefile->MaybeWarnCMP0074(rootVar, rootDef, rootEnv); + CM_FALLTHROUGH; + case cmPolicies::OLD: + // OLD behavior is to ignore the <PackageName>_ROOT variables. + return; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0074)); + return; + case cmPolicies::NEW: { + // NEW behavior is to honor the <PackageName>_ROOT variables. + } 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() +{ + this->Makefile->FindPackageRootPathStack.pop_back(); +} + void cmFindPackageCommand::ComputePrefixes() { this->FillPrefixesPackageRedirect(); diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index 28e00a1..18684c9 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -125,6 +125,9 @@ private: void StoreVersionFound(); void SetConfigDirCacheVariable(const std::string& value); + void PushFindPackageRootPathStack(); + void PopFindPackageRootPathStack(); + void ComputePrefixes(); void FillPrefixesPackageRedirect(); void FillPrefixesPackageRoot(); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index d963a5a..2fc2974 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -208,32 +208,47 @@ bool cmMakefile::CheckCMP0037(std::string const& targetName, return true; } -void cmMakefile::MaybeWarnCMP0074(std::string const& pkg) +void cmMakefile::MaybeWarnCMP0074(std::string const& rootVar, cmValue rootDef, + cm::optional<std::string> const& rootEnv) { - // Warn if a <pkg>_ROOT variable we may use is set. - std::string const varName = pkg + "_ROOT"; - cmValue var = this->GetDefinition(varName); - std::string env; - cmSystemTools::GetEnv(varName, env); - - bool const haveVar = cmNonempty(var); - bool const haveEnv = !env.empty(); - if ((haveVar || haveEnv) && this->WarnedCMP0074.insert(varName).second) { + // Warn if a <PackageName>_ROOT variable we may use is set. + if ((rootDef || rootEnv) && this->WarnedCMP0074.insert(rootVar).second) { std::ostringstream w; w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0074) << "\n"; - if (haveVar) { - w << "CMake variable " << varName << " is set to:\n" - << " " << *var << "\n"; + if (rootDef) { + w << "CMake variable " << rootVar << " is set to:\n" + << " " << *rootDef << "\n"; } - if (haveEnv) { - w << "Environment variable " << varName << " is set to:\n" - << " " << env << "\n"; + if (rootEnv) { + w << "Environment variable " << rootVar << " is set to:\n" + << " " << *rootEnv << "\n"; } w << "For compatibility, CMake is ignoring the variable."; this->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); } } +void cmMakefile::MaybeWarnCMP0144(std::string const& rootVAR, cmValue rootDEF, + cm::optional<std::string> const& rootENV) +{ + // Warn if a <PACKAGENAME>_ROOT variable we may use is set. + if ((rootDEF || rootENV) && this->WarnedCMP0144.insert(rootVAR).second) { + std::ostringstream w; + w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0144) << "\n"; + if (rootDEF) { + w << "CMake variable " << rootVAR << " is set to:\n" + << " " << *rootDEF << "\n"; + } + if (rootENV) { + w << "Environment variable " << rootVAR << " is set to:\n" + << " " << *rootENV << "\n"; + } + w << "For compatibility, find_package is ignoring the variable, but " + "code in a .cmake module might still use it."; + this->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); + } +} + cmBTStringRange cmMakefile::GetIncludeDirectoriesEntries() const { return this->StateSnapshot.GetDirectory().GetIncludeDirectoriesEntries(); diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 7b19c97..3cf6e61 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -1011,7 +1011,10 @@ public: bool GetDebugFindPkgMode() const; - void MaybeWarnCMP0074(std::string const& pkg); + void MaybeWarnCMP0074(std::string const& rootVar, cmValue rootDef, + cm::optional<std::string> const& rootEnv); + void MaybeWarnCMP0144(std::string const& rootVAR, cmValue rootDEF, + cm::optional<std::string> const& rootENV); void MaybeWarnUninitialized(std::string const& variable, const char* sourceFilename) const; bool IsProjectFile(const char* filename) const; @@ -1189,6 +1192,7 @@ private: bool CheckSystemVars; bool CheckCMP0000; std::set<std::string> WarnedCMP0074; + std::set<std::string> WarnedCMP0144; bool IsSourceFileTryCompile; mutable bool SuppressSideEffects; ImportedTargetScope CurrentImportedTargetScope = ImportedTargetScope::Local; diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 568eca3..1eca586 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -434,7 +434,10 @@ class cmMakefile; 3, 25, 0, cmPolicies::WARN) \ SELECT(POLICY, CMP0143, \ "Global property USE_FOLDERS treated as ON by default", 3, 26, 0, \ - cmPolicies::WARN) + cmPolicies::WARN) \ + SELECT(POLICY, CMP0144, \ + "find_package uses upper-case <PACKAGENAME>_ROOT variables.", 3, 27, \ + 0, cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 3d61270..1fb0079 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1648,6 +1648,32 @@ std::string cmSystemTools::RelativeIfUnder(std::string const& top, return out; } +cm::optional<std::string> cmSystemTools::GetEnvVar(std::string const& var) +{ + cm::optional<std::string> result; + { + std::string value; + if (cmSystemTools::GetEnv(var, value)) { + result = std::move(value); + } + } + return result; +} + +std::vector<std::string> cmSystemTools::SplitEnvPath(std::string const& value) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + static cm::string_view sep = ";"_s; +#else + static cm::string_view sep = ":"_s; +#endif + std::vector<std::string> paths = cmTokenize(value, sep); + for (std::string& p : paths) { + SystemTools::ConvertToUnixSlashes(p); + } + return paths; +} + #ifndef CMAKE_BOOTSTRAP bool cmSystemTools::UnsetEnv(const char* value) { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 09f2bf0..7d55d4b 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -399,6 +399,9 @@ public: static std::string RelativeIfUnder(std::string const& top, std::string const& in); + static cm::optional<std::string> GetEnvVar(std::string const& var); + static std::vector<std::string> SplitEnvPath(std::string const& value); + #ifndef CMAKE_BOOTSTRAP /** Remove an environment variable */ static bool UnsetEnv(const char* value); |