summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-02-14 16:00:00 (GMT)
committerBrad King <brad.king@kitware.com>2023-02-23 14:12:28 (GMT)
commitc0fcd07e6f0928ae666c5f6fe1f8ad6c306e67ba (patch)
treef4951bad8f4ea943b176c43a2f6a172173e72d46
parentacd9636d9d5ccc81d07b2cc65fa39dbc02fff436 (diff)
downloadCMake-c0fcd07e6f0928ae666c5f6fe1f8ad6c306e67ba.zip
CMake-c0fcd07e6f0928ae666c5f6fe1f8ad6c306e67ba.tar.gz
CMake-c0fcd07e6f0928ae666c5f6fe1f8ad6c306e67ba.tar.bz2
cmFindPackageCommand: Factor out methods for package root stack management
-rw-r--r--Source/cmFindPackageCommand.cxx69
-rw-r--r--Source/cmFindPackageCommand.h3
2 files changed, 41 insertions, 31 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index c1b82ab..16e0986 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,42 @@ 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.
+ 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;
+ }
+}
+
+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();