diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2021-06-01 14:05:34 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-06-02 18:55:00 (GMT) |
commit | 87b71eec6257b0d9c43b446205d61f334278fe7d (patch) | |
tree | 727adaa232629c537ca47112fbc3f7fbeec36127 /Source/cmFindBase.cxx | |
parent | 2104cfe388f5d77b98727c89edff453b1d23fed6 (diff) | |
download | CMake-87b71eec6257b0d9c43b446205d61f334278fe7d.zip CMake-87b71eec6257b0d9c43b446205d61f334278fe7d.tar.gz CMake-87b71eec6257b0d9c43b446205d61f334278fe7d.tar.bz2 |
find_*: Add support for option NO_CACHE
Request that find result is stored in a normal variable rather than a
cache entry.
Fixes: #20687
Issue: #20743
Diffstat (limited to 'Source/cmFindBase.cxx')
-rw-r--r-- | Source/cmFindBase.cxx | 115 |
1 files changed, 69 insertions, 46 deletions
diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index c1281e3..1038ac2 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -39,12 +39,15 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn) // copy argsIn into args so it can be modified, // in the process extract the DOC "documentation" + // and handle options NO_CACHE and ENV size_t size = argsIn.size(); std::vector<std::string> args; bool foundDoc = false; for (unsigned int j = 0; j < size; ++j) { if (foundDoc || argsIn[j] != "DOC") { - if (argsIn[j] == "ENV") { + if (argsIn[j] == "NO_CACHE") { + this->StoreResultInCache = false; + } else if (argsIn[j] == "ENV") { if (j + 1 < size) { j++; cmSystemTools::GetPath(args, argsIn[j].c_str()); @@ -68,11 +71,10 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn) return false; } this->VariableName = args[0]; - if (this->CheckForVariableInCache()) { - this->AlreadyInCache = true; + if (this->CheckForVariableDefined()) { + this->AlreadyDefined = true; return true; } - this->AlreadyInCache = false; // Find what search path locations have been enabled/disable this->SelectDefaultSearchModes(); @@ -297,12 +299,12 @@ void cmFindBase::FillUserGuessPath() paths.AddSuffixes(this->SearchPathSuffixes); } -bool cmFindBase::CheckForVariableInCache() +bool cmFindBase::CheckForVariableDefined() { - if (cmProp cacheValue = this->Makefile->GetDefinition(this->VariableName)) { + if (cmProp value = this->Makefile->GetDefinition(this->VariableName)) { cmState* state = this->Makefile->GetState(); cmProp cacheEntry = state->GetCacheEntryValue(this->VariableName); - bool found = !cmIsNOTFOUND(*cacheValue); + bool found = !cmIsNOTFOUND(*value); bool cached = cacheEntry != nullptr; auto cacheType = cached ? state->GetCacheEntryType(this->VariableName) : cmStateEnums::UNINITIALIZED; @@ -350,41 +352,53 @@ void cmFindBase::NormalizeFindResult() } } - // If the user specifies the entry on the command line without a - // type we should add the type and docstring but keep the original - // value. - if (value != *existingValue || this->AlreadyInCacheWithoutMetaInfo) { - this->Makefile->GetCMakeInstance()->AddCacheEntry( - this->VariableName, value.c_str(), this->VariableDocumentation.c_str(), - this->VariableType); - if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) == - cmPolicies::NEW) { - if (this->Makefile->IsNormalDefinitionSet(this->VariableName)) { - this->Makefile->AddDefinition(this->VariableName, value); + if (this->StoreResultInCache) { + // If the user specifies the entry on the command line without a + // type we should add the type and docstring but keep the original + // value. + if (value != *existingValue || this->AlreadyInCacheWithoutMetaInfo) { + this->Makefile->GetCMakeInstance()->AddCacheEntry( + this->VariableName, value.c_str(), + this->VariableDocumentation.c_str(), this->VariableType); + 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 there was a definition then remove it - // This is required to ensure same behavior as - // cmMakefile::AddCacheDefinition. - this->Makefile->RemoveDefinition(this->VariableName); } + } else { + // ensure a normal variable is defined. + this->Makefile->AddDefinition(this->VariableName, value); } } else { // If the user specifies the entry on the command line without a // type we should add the type and docstring but keep the original // value. - if (this->AlreadyInCacheWithoutMetaInfo) { - 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)); + if (this->StoreResultInCache) { + if (this->AlreadyInCacheWithoutMetaInfo) { + 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)); + } } + } else { + // ensure a normal variable is defined. + this->Makefile->AddDefinition( + this->VariableName, + this->Makefile->GetSafeDefinition(this->VariableName)); } } } @@ -397,23 +411,32 @@ void cmFindBase::StoreFindResult(const std::string& value) 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)) { + if (this->StoreResultInCache) { + 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); + } + } else { 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")); + auto notFound = cmStrCat(this->VariableName, "-NOTFOUND"); + if (this->StoreResultInCache) { + this->Makefile->AddCacheDefinition(this->VariableName, notFound, + this->VariableDocumentation.c_str(), + this->VariableType, force); + if (updateNormalVariable && + this->Makefile->IsNormalDefinitionSet(this->VariableName)) { + this->Makefile->AddDefinition(this->VariableName, notFound); + } + } else { + this->Makefile->AddDefinition(this->VariableName, notFound); } if (this->Required) { |