diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2021-05-20 13:14:30 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2021-05-20 15:50:13 (GMT) |
commit | d96eb5528276a19d79116d842389f3ea165ef21b (patch) | |
tree | d9b7bebf4ced2582efba39187c41476171508384 /Source | |
parent | 34f9a551ce5631baef159076c697dd8f86daa8b8 (diff) | |
download | CMake-d96eb5528276a19d79116d842389f3ea165ef21b.zip CMake-d96eb5528276a19d79116d842389f3ea165ef21b.tar.gz CMake-d96eb5528276a19d79116d842389f3ea165ef21b.tar.bz2 |
set(CACHE): do not remove normal variable
Fixes: #22038
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmFindBase.cxx | 35 | ||||
-rw-r--r-- | Source/cmFindPackageCommand.cxx | 5 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 8 | ||||
-rw-r--r-- | Source/cmOptionCommand.cxx | 7 | ||||
-rw-r--r-- | Source/cmPolicies.h | 5 |
5 files changed, 50 insertions, 10 deletions
diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index 6296d06..c1281e3 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -357,11 +357,17 @@ void cmFindBase::NormalizeFindResult() this->Makefile->GetCMakeInstance()->AddCacheEntry( this->VariableName, value.c_str(), this->VariableDocumentation.c_str(), this->VariableType); - // if there was a definition then remove it - // This is required to ensure same behavior as - // cmMakefile::AddCacheDefinition. - // See #22038 for problems raised by this behavior. - this->Makefile->RemoveDefinition(this->VariableName); + if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) == + cmPolicies::NEW) { + if (this->Makefile->IsNormalDefinitionSet(this->VariableName)) { + this->Makefile->AddDefinition(this->VariableName, value); + } + } else { + // if there was a definition then remove it + // This is required to ensure same behavior as + // cmMakefile::AddCacheDefinition. + this->Makefile->RemoveDefinition(this->VariableName); + } } } else { // If the user specifies the entry on the command line without a @@ -371,6 +377,14 @@ void cmFindBase::NormalizeFindResult() this->Makefile->AddCacheDefinition(this->VariableName, "", this->VariableDocumentation.c_str(), this->VariableType); + if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) == + cmPolicies::NEW && + this->Makefile->IsNormalDefinitionSet(this->VariableName)) { + this->Makefile->AddDefinition( + this->VariableName, + *this->Makefile->GetCMakeInstance()->GetCacheDefinition( + this->VariableName)); + } } } } @@ -379,17 +393,28 @@ void cmFindBase::StoreFindResult(const std::string& value) { bool force = this->Makefile->GetPolicyStatus(cmPolicies::CMP0125) == cmPolicies::NEW; + bool updateNormalVariable = + this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) == cmPolicies::NEW; if (!value.empty()) { this->Makefile->AddCacheDefinition(this->VariableName, value, this->VariableDocumentation.c_str(), this->VariableType, force); + if (updateNormalVariable && + this->Makefile->IsNormalDefinitionSet(this->VariableName)) { + this->Makefile->AddDefinition(this->VariableName, value); + } return; } this->Makefile->AddCacheDefinition( this->VariableName, cmStrCat(this->VariableName, "-NOTFOUND"), this->VariableDocumentation.c_str(), this->VariableType, force); + if (updateNormalVariable && + this->Makefile->IsNormalDefinitionSet(this->VariableName)) { + this->Makefile->AddDefinition(this->VariableName, + cmStrCat(this->VariableName, "-NOTFOUND")); + } if (this->Required) { this->Makefile->IssueMessage( diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 3719fe1..fba736e 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -1138,6 +1138,11 @@ bool cmFindPackageCommand::FindConfig() // We force the value since we do not get here if it was already set. this->Makefile->AddCacheDefinition(this->Variable, init, help.c_str(), cmStateEnums::PATH, true); + if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) == + cmPolicies::NEW && + this->Makefile->IsNormalDefinitionSet(this->Variable)) { + this->Makefile->AddDefinition(this->Variable, init); + } return found; } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 4ffd47b..d7987c2 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1962,10 +1962,10 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value, } } this->GetCMakeInstance()->AddCacheEntry(name, value, doc, type); - // if there was a definition then remove it - // The method cmFindBase::NormalizeFindResult also apply same workflow. - // See #22038 for problems raised by this behavior. - this->StateSnapshot.RemoveDefinition(name); + if (this->GetPolicyStatus(cmPolicies::CMP0126) != cmPolicies::NEW) { + // if there was a definition then remove it + this->StateSnapshot.RemoveDefinition(name); + } } void cmMakefile::MarkVariableAsUsed(const std::string& var) diff --git a/Source/cmOptionCommand.cxx b/Source/cmOptionCommand.cxx index a58e2f8..bae67e0 100644 --- a/Source/cmOptionCommand.cxx +++ b/Source/cmOptionCommand.cxx @@ -68,6 +68,13 @@ bool cmOptionCommand(std::vector<std::string> const& args, bool init = cmIsOn(initialValue); status.GetMakefile().AddCacheDefinition(args[0], init ? "ON" : "OFF", args[1].c_str(), cmStateEnums::BOOL); + if (status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0077) != + cmPolicies::NEW && + status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0126) == + cmPolicies::NEW) { + // if there was a definition then remove it + status.GetMakefile().GetStateSnapshot().RemoveDefinition(args[0]); + } if (checkAndWarn) { const auto* existsAfterSet = diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 3ebb17d..f7c0d25 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -376,7 +376,10 @@ class cmMakefile; SELECT(POLICY, CMP0125, \ "find_(path|file|library|program) have consistent behavior for " \ "cache variables.", \ - 3, 21, 0, cmPolicies::WARN) + 3, 21, 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0126, \ + "set(CACHE) does not remove a normal variable of the same name.", 3, \ + 21, 0, cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ |