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 | |
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')
-rw-r--r-- | Source/cmFindBase.cxx | 115 | ||||
-rw-r--r-- | Source/cmFindBase.h | 7 | ||||
-rw-r--r-- | Source/cmFindLibraryCommand.cxx | 2 | ||||
-rw-r--r-- | Source/cmFindPathCommand.cxx | 2 | ||||
-rw-r--r-- | Source/cmFindProgramCommand.cxx | 2 |
5 files changed, 76 insertions, 52 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) { diff --git a/Source/cmFindBase.h b/Source/cmFindBase.h index c2a9288..d197424 100644 --- a/Source/cmFindBase.h +++ b/Source/cmFindBase.h @@ -35,10 +35,10 @@ protected: friend class cmFindBaseDebugState; void ExpandPaths(); - // see if the VariableName is already set in the cache, + // see if the VariableName is already set, // also copy the documentation from the cache to VariableDocumentation // if it has documentation in the cache - bool CheckForVariableInCache(); + bool CheckForVariableDefined(); void NormalizeFindResult(); void StoreFindResult(const std::string& value); @@ -57,8 +57,9 @@ protected: // CMAKE_*_PATH CMAKE_SYSTEM_*_PATH FRAMEWORK|LIBRARY|INCLUDE|PROGRAM std::string EnvironmentPath; // LIB,INCLUDE - bool AlreadyInCache = false; + bool AlreadyDefined = false; bool AlreadyInCacheWithoutMetaInfo = false; + bool StoreResultInCache = true; bool Required = false; diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index b1f4275..0cbe637 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -39,7 +39,7 @@ bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn) return false; } - if (this->AlreadyInCache) { + if (this->AlreadyDefined) { this->NormalizeFindResult(); return true; } diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx index 126cc2f..3d21167 100644 --- a/Source/cmFindPathCommand.cxx +++ b/Source/cmFindPathCommand.cxx @@ -36,7 +36,7 @@ bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn) return false; } - if (this->AlreadyInCache) { + if (this->AlreadyDefined) { this->NormalizeFindResult(); return true; } diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index 76fc4a4..1c87625 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -165,7 +165,7 @@ bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn) return false; } - if (this->AlreadyInCache) { + if (this->AlreadyDefined) { this->NormalizeFindResult(); return true; } |