mirror of
https://github.com/Kitware/CMake.git
synced 2026-06-24 08:47:59 +00:00
cmMakefile: Use enumeration for policy scope
Create `cmPolicyScope` to describe whether `ReadDependentFile` creates a policy scope, rather than a bare `bool`. Replace a local enumeration in `cmFindPackageCommand` serving the same purpose with this new, global one.
This commit is contained in:
@@ -1581,7 +1581,7 @@ bool cmFindPackageCommand::FindModule(bool& found)
|
||||
found = true;
|
||||
std::string const var = cmStrCat(this->Name, "_FIND_MODULE");
|
||||
this->Makefile->AddDefinition(var, "1");
|
||||
bool result = this->ReadListFile(mfile, DoPolicyScope);
|
||||
bool result = this->ReadListFile(mfile, cm::PolicyScope::Local);
|
||||
this->Makefile->RemoveDefinition(var);
|
||||
|
||||
std::string const foundVar = cmStrCat(this->Name, "_FOUND");
|
||||
@@ -1705,7 +1705,7 @@ bool cmFindPackageCommand::HandlePackageMode(
|
||||
// The package has been found.
|
||||
found = true;
|
||||
result = this->ReadPackage();
|
||||
} else if (this->ReadListFile(this->FileFound, DoPolicyScope)) {
|
||||
} else if (this->ReadListFile(this->FileFound, cm::PolicyScope::Local)) {
|
||||
// The package has been found.
|
||||
found = true;
|
||||
|
||||
@@ -2071,9 +2071,11 @@ cmFindPackageCommand::AppendixMap cmFindPackageCommand::FindAppendices(
|
||||
}
|
||||
|
||||
bool cmFindPackageCommand::ReadListFile(std::string const& f,
|
||||
PolicyScopeRule const psr)
|
||||
cm::PolicyScope ps)
|
||||
{
|
||||
bool const noPolicyScope = !this->PolicyScope || psr == NoPolicyScope;
|
||||
if (!this->PolicyScope) {
|
||||
ps = cm::PolicyScope::None;
|
||||
}
|
||||
|
||||
using ITScope = cmMakefile::ImportedTargetScope;
|
||||
ITScope scope = this->GlobalScope ? ITScope::Global : ITScope::Local;
|
||||
@@ -2084,7 +2086,7 @@ bool cmFindPackageCommand::ReadListFile(std::string const& f,
|
||||
// This allows child snapshots to inherit the CAN_UNWIND state from us, we'll
|
||||
// reset it immediately after the dependent file is done
|
||||
this->Makefile->GetStateSnapshot().SetUnwindType(cmStateEnums::CAN_UNWIND);
|
||||
bool result = this->Makefile->ReadDependentFile(f, noPolicyScope);
|
||||
bool result = this->Makefile->ReadDependentFile(f, ps);
|
||||
|
||||
this->Makefile->GetStateSnapshot().SetUnwindType(oldUnwind);
|
||||
this->Makefile->GetStateSnapshot().SetUnwindState(
|
||||
@@ -3205,7 +3207,7 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
|
||||
// Load the version check file.
|
||||
// Pass NoPolicyScope because we do our own policy push/pop.
|
||||
bool suitable = false;
|
||||
if (this->ReadListFile(version_file, NoPolicyScope)) {
|
||||
if (this->ReadListFile(version_file, cm::PolicyScope::None)) {
|
||||
// Check the output variables.
|
||||
bool okay = this->Makefile->IsOn("PACKAGE_VERSION_EXACT");
|
||||
bool const unsuitable = this->Makefile->IsOn("PACKAGE_VERSION_UNSUITABLE");
|
||||
|
||||
@@ -32,6 +32,10 @@ namespace std {
|
||||
/* clang-format on */
|
||||
#endif
|
||||
|
||||
namespace cm {
|
||||
enum class PolicyScope : bool;
|
||||
}
|
||||
|
||||
class cmExecutionStatus;
|
||||
class cmPackageState;
|
||||
class cmSearchPath;
|
||||
@@ -139,12 +143,7 @@ private:
|
||||
bool FindFrameworkConfig();
|
||||
bool FindAppBundleConfig();
|
||||
bool FindEnvironmentConfig();
|
||||
enum PolicyScopeRule
|
||||
{
|
||||
NoPolicyScope,
|
||||
DoPolicyScope
|
||||
};
|
||||
bool ReadListFile(std::string const& f, PolicyScopeRule psr);
|
||||
bool ReadListFile(std::string const& f, cm::PolicyScope ps);
|
||||
bool ReadPackage();
|
||||
|
||||
struct Appendix
|
||||
|
||||
@@ -48,7 +48,7 @@ bool cmIncludeCommand(std::vector<std::string> const& args,
|
||||
}
|
||||
|
||||
bool optional = false;
|
||||
bool noPolicyScope = false;
|
||||
cm::PolicyScope policyScope = cm::PolicyScope::Local;
|
||||
std::string fname = args[0];
|
||||
std::string resultVarName;
|
||||
|
||||
@@ -72,7 +72,7 @@ bool cmIncludeCommand(std::vector<std::string> const& args,
|
||||
return false;
|
||||
}
|
||||
} else if (args[i] == "NO_POLICY_SCOPE") {
|
||||
noPolicyScope = true;
|
||||
policyScope = cm::PolicyScope::None;
|
||||
} else if (i > 1) // compat.: in previous cmake versions the second
|
||||
// parameter was ignored if it wasn't "OPTIONAL"
|
||||
{
|
||||
@@ -161,8 +161,7 @@ bool cmIncludeCommand(std::vector<std::string> const& args,
|
||||
}
|
||||
}
|
||||
|
||||
bool readit =
|
||||
status.GetMakefile().ReadDependentFile(listFile, noPolicyScope);
|
||||
bool readit = status.GetMakefile().ReadDependentFile(listFile, policyScope);
|
||||
|
||||
// add the location of the included file if a result variable was given
|
||||
if (!resultVarName.empty()) {
|
||||
|
||||
@@ -620,7 +620,7 @@ class cmMakefile::IncludeScope : public FileScopeBase
|
||||
{
|
||||
public:
|
||||
IncludeScope(cmMakefile* mf, std::string const& filenametoread,
|
||||
bool noPolicyScope);
|
||||
cm::PolicyScope policyScope);
|
||||
~IncludeScope();
|
||||
void Quiet() { this->ReportError = false; }
|
||||
|
||||
@@ -628,15 +628,15 @@ public:
|
||||
IncludeScope& operator=(IncludeScope const&) = delete;
|
||||
|
||||
private:
|
||||
bool NoPolicyScope;
|
||||
cm::PolicyScope PolicyScope;
|
||||
bool ReportError = true;
|
||||
};
|
||||
|
||||
cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf,
|
||||
std::string const& filenametoread,
|
||||
bool noPolicyScope)
|
||||
cm::PolicyScope policyScope)
|
||||
: FileScopeBase(mf)
|
||||
, NoPolicyScope(noPolicyScope)
|
||||
, PolicyScope(policyScope)
|
||||
{
|
||||
this->Makefile->Backtrace = this->Makefile->Backtrace.Push(
|
||||
cmListFileContext::FromListFilePath(filenametoread));
|
||||
@@ -646,7 +646,7 @@ cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf,
|
||||
this->Makefile->StateSnapshot =
|
||||
this->Makefile->GetState()->CreateIncludeFileSnapshot(
|
||||
this->Makefile->StateSnapshot, filenametoread);
|
||||
if (!this->NoPolicyScope) {
|
||||
if (this->PolicyScope == cm::PolicyScope::Local) {
|
||||
this->Makefile->PushPolicy();
|
||||
}
|
||||
this->PushListFileVars(filenametoread);
|
||||
@@ -655,7 +655,7 @@ cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf,
|
||||
cmMakefile::IncludeScope::~IncludeScope()
|
||||
{
|
||||
this->PopListFileVars();
|
||||
if (!this->NoPolicyScope) {
|
||||
if (this->PolicyScope == cm::PolicyScope::Local) {
|
||||
// Pop the scope we pushed for the script.
|
||||
this->Makefile->PopPolicy();
|
||||
}
|
||||
@@ -667,12 +667,12 @@ cmMakefile::IncludeScope::~IncludeScope()
|
||||
}
|
||||
|
||||
bool cmMakefile::ReadDependentFile(std::string const& filename,
|
||||
bool noPolicyScope)
|
||||
cm::PolicyScope policyScope)
|
||||
{
|
||||
std::string filenametoread = cmSystemTools::CollapseFullPath(
|
||||
filename, this->GetCurrentSourceDirectory());
|
||||
|
||||
IncludeScope incScope(this, filenametoread, noPolicyScope);
|
||||
IncludeScope incScope(this, filenametoread, policyScope);
|
||||
|
||||
#ifdef CMake_ENABLE_DEBUGGER
|
||||
if (this->GetCMakeInstance()->GetDebugAdapter()) {
|
||||
|
||||
@@ -64,6 +64,14 @@ class cmTestGenerator;
|
||||
class cmVariableWatch;
|
||||
class cmake;
|
||||
|
||||
namespace cm {
|
||||
enum class PolicyScope : bool
|
||||
{
|
||||
None,
|
||||
Local,
|
||||
};
|
||||
}
|
||||
|
||||
/** A type-safe wrapper for a string representing a directory id. */
|
||||
class cmDirectoryId
|
||||
{
|
||||
@@ -109,7 +117,7 @@ public:
|
||||
std::string const& virtualFileName);
|
||||
|
||||
bool ReadDependentFile(std::string const& filename,
|
||||
bool noPolicyScope = true);
|
||||
cm::PolicyScope policyScope = cm::PolicyScope::None);
|
||||
|
||||
/**
|
||||
* Add a function blocker to this makefile
|
||||
|
||||
Reference in New Issue
Block a user