diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2021-05-02 12:20:56 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2021-05-11 16:16:08 (GMT) |
commit | b1729200c318dab23daac8643da5f9fdc673a5ef (patch) | |
tree | 46da1a315c6cc75fb22e63d07b667f31c9254de8 /Source/cmFindBase.cxx | |
parent | ee87e53d3732a6482841c01c16e89f2822137d0e (diff) | |
download | CMake-b1729200c318dab23daac8643da5f9fdc673a5ef.zip CMake-b1729200c318dab23daac8643da5f9fdc673a5ef.tar.gz CMake-b1729200c318dab23daac8643da5f9fdc673a5ef.tar.bz2 |
find_*: refactor cache variable handling
Diffstat (limited to 'Source/cmFindBase.cxx')
-rw-r--r-- | Source/cmFindBase.cxx | 62 |
1 files changed, 53 insertions, 9 deletions
diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index bf52d75..409e2e0 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -10,6 +10,7 @@ #include <cmext/algorithm> #include "cmMakefile.h" +#include "cmMessageType.h" #include "cmProperty.h" #include "cmRange.h" #include "cmSearchPath.h" @@ -20,8 +21,9 @@ class cmExecutionStatus; -cmFindBase::cmFindBase(cmExecutionStatus& status) +cmFindBase::cmFindBase(std::string findCommandName, cmExecutionStatus& status) : cmFindCommon(status) + , FindCommandName(std::move(findCommandName)) { } @@ -299,27 +301,69 @@ bool cmFindBase::CheckForVariableInCache() cmProp cacheEntry = state->GetCacheEntryValue(this->VariableName); bool found = !cmIsNOTFOUND(*cacheValue); bool cached = cacheEntry != nullptr; + auto cacheType = cached ? state->GetCacheEntryType(this->VariableName) + : cmStateEnums::UNINITIALIZED; + + if (cached && cacheType != cmStateEnums::UNINITIALIZED) { + this->VariableType = cacheType; + if (const auto* hs = + state->GetCacheEntryProperty(this->VariableName, "HELPSTRING")) { + this->VariableDocumentation = *hs; + } + } + if (found) { // 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. Tell the subclass implementations to do // this. - if (cached && - state->GetCacheEntryType(this->VariableName) == - cmStateEnums::UNINITIALIZED) { + if (cached && cacheType == cmStateEnums::UNINITIALIZED) { this->AlreadyInCacheWithoutMetaInfo = true; } return true; } - if (cached) { - cmProp hs = - state->GetCacheEntryProperty(this->VariableName, "HELPSTRING"); - this->VariableDocumentation = hs ? *hs : "(none)"; - } } return false; } +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 (this->AlreadyInCacheWithoutMetaInfo) { + this->Makefile->AddCacheDefinition(this->VariableName, "", + this->VariableDocumentation.c_str(), + this->VariableType); + } +} + +void cmFindBase::StoreFindResult(const std::string& value) +{ + if (!value.empty()) { + this->Makefile->AddCacheDefinition(this->VariableName, value, + this->VariableDocumentation.c_str(), + this->VariableType); + return; + } + + this->Makefile->AddCacheDefinition( + this->VariableName, cmStrCat(this->VariableName, "-NOTFOUND"), + this->VariableDocumentation.c_str(), this->VariableType); + + if (this->Required) { + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Could not find ", this->VariableName, " using the following ", + (this->FindCommandName == "find_file" || + this->FindCommandName == "find_path" + ? "files" + : "names"), + ": ", cmJoin(this->Names, ", "))); + cmSystemTools::SetFatalErrorOccured(); + } +} + cmFindBaseDebugState::cmFindBaseDebugState(std::string commandName, cmFindBase const* findBase) : FindCommand(findBase) |