summaryrefslogtreecommitdiff
path: root/Source/cmFindBase.cxx
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2021-05-20 15:14:30 +0200
committerMarc Chevrier <marc.chevrier@gmail.com>2021-05-20 17:50:13 +0200
commitd96eb5528276a19d79116d842389f3ea165ef21b (patch)
treed9b7bebf4ced2582efba39187c41476171508384 /Source/cmFindBase.cxx
parent34f9a551ce5631baef159076c697dd8f86daa8b8 (diff)
downloadcmake-d96eb5528276a19d79116d842389f3ea165ef21b.tar.gz
set(CACHE): do not remove normal variable
Fixes: #22038
Diffstat (limited to 'Source/cmFindBase.cxx')
-rw-r--r--Source/cmFindBase.cxx35
1 files changed, 30 insertions, 5 deletions
diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx
index 6296d06e24..c1281e3278 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(