cmFindPackageCommand: Factor out methods for package root stack management

This commit is contained in:
Brad King
2023-02-14 11:00:00 -05:00
parent acd9636d9d
commit c0fcd07e6f
2 changed files with 41 additions and 31 deletions

View File

@@ -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();

View File

@@ -125,6 +125,9 @@ private:
void StoreVersionFound();
void SetConfigDirCacheVariable(const std::string& value);
void PushFindPackageRootPathStack();
void PopFindPackageRootPathStack();
void ComputePrefixes();
void FillPrefixesPackageRedirect();
void FillPrefixesPackageRoot();