mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-22 06:59:01 -06:00
cmFindPackageCommand: Factor out methods for package root stack management
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -125,6 +125,9 @@ private:
|
||||
void StoreVersionFound();
|
||||
void SetConfigDirCacheVariable(const std::string& value);
|
||||
|
||||
void PushFindPackageRootPathStack();
|
||||
void PopFindPackageRootPathStack();
|
||||
|
||||
void ComputePrefixes();
|
||||
void FillPrefixesPackageRedirect();
|
||||
void FillPrefixesPackageRoot();
|
||||
|
||||
Reference in New Issue
Block a user