diff options
author | Brad King <brad.king@kitware.com> | 2021-05-25 14:02:56 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-05-25 14:03:03 (GMT) |
commit | bf2717e436ff2fceaaaf3a9e032d5f10c7dc8d06 (patch) | |
tree | 8f1124bf7f5904c1b3c83eb08905b417aa0a5809 /Source | |
parent | 0c16774fecb8a9ef989f6c0a6705c080ee55d720 (diff) | |
parent | d96eb5528276a19d79116d842389f3ea165ef21b (diff) | |
download | CMake-bf2717e436ff2fceaaaf3a9e032d5f10c7dc8d06.zip CMake-bf2717e436ff2fceaaaf3a9e032d5f10c7dc8d06.tar.gz CMake-bf2717e436ff2fceaaaf3a9e032d5f10c7dc8d06.tar.bz2 |
Merge topic 'set-cache-keep-normal-variable'
d96eb55282 set(CACHE): do not remove normal variable
Acked-by: Kitware Robot <kwrobot@kitware.com>
Reviewed-by: Ben Boeckel <ben.boeckel@kitware.com>
Merge-request: !6146
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 675ff1d..ffe94ba 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) \ |