From c0fcd07e6f0928ae666c5f6fe1f8ad6c306e67ba Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 14 Feb 2023 11:00:00 -0500 Subject: cmFindPackageCommand: Factor out methods for package root stack management --- Source/cmFindPackageCommand.cxx | 69 +++++++++++++++++++++++------------------ Source/cmFindPackageCommand.h | 3 ++ 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 const& args) } } - { - // Allocate a PACKAGE_ROOT_PATH for the current find_package call. - this->Makefile->FindPackageRootPathStack.emplace_back(); - std::vector& rootPaths = - this->Makefile->FindPackageRootPathStack.back(); - - // Add root paths from _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 _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 _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 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& rootPaths = + this->Makefile->FindPackageRootPathStack.back(); + + // Add root paths from _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 _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 _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(); -- cgit v0.12