From 5aefc8b7b83ae9313b089ce23b86f7f5db428d10 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 14 May 2025 21:34:30 +0200 Subject: [PATCH] cmFindBase: let the debug state know if it has already been found This avoids reporting a "not found" state for searches that had cached results. --- Source/cmFindBase.cxx | 29 ++++++++++++++----- .../RunCMake/find_path/FromPATHEnv-stderr.txt | 2 +- .../find_path/FromPATHEnvDebugVar-stderr.txt | 2 +- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index b3fb9c0e4a..b8d4765692 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -90,6 +90,10 @@ bool cmFindBase::ParseArguments(std::vector const& argsIn) this->VariableName = args[0]; this->InitialState = this->GetInitialState(); if (this->IsFound()) { + if (this->DebugState) { + this->DebugState->FoundAt( + *this->Makefile->GetDefinition(this->VariableName)); + } return true; } @@ -524,6 +528,7 @@ bool cmFindBase::IsDefined() const void cmFindBase::NormalizeFindResult() { + std::string foundValue; if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0125) == cmPolicies::NEW) { // ensure the path returned by find_* command is absolute @@ -542,6 +547,7 @@ void cmFindBase::NormalizeFindResult() } } + foundValue = 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 @@ -571,6 +577,10 @@ void cmFindBase::NormalizeFindResult() // type we should add the type and docstring but keep the original // value. if (this->StoreResultInCache) { + auto const& existingValue = + this->Makefile->GetCMakeInstance()->GetCacheDefinition( + this->VariableName); + foundValue = *existingValue; if (this->AlreadyInCacheWithoutMetaInfo) { this->Makefile->AddCacheDefinition(this->VariableName, "", this->VariableDocumentation, @@ -578,19 +588,20 @@ void cmFindBase::NormalizeFindResult() if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) == cmPolicies::NEW && this->Makefile->IsNormalDefinitionSet(this->VariableName)) { - this->Makefile->AddDefinition( - this->VariableName, - *this->Makefile->GetCMakeInstance()->GetCacheDefinition( - this->VariableName)); + this->Makefile->AddDefinition(this->VariableName, *existingValue); } } } else { + auto const& existingValue = + this->Makefile->GetSafeDefinition(this->VariableName); + foundValue = existingValue; // ensure a normal variable is defined. - this->Makefile->AddDefinition( - this->VariableName, - this->Makefile->GetSafeDefinition(this->VariableName)); + this->Makefile->AddDefinition(this->VariableName, existingValue); } } + if (this->DebugState) { + this->DebugState->FoundAt(foundValue); + } } void cmFindBase::StoreFindResult(std::string const& value) @@ -613,6 +624,10 @@ void cmFindBase::StoreFindResult(std::string const& value) this->Makefile->AddDefinition(this->VariableName, value); } + if (this->DebugState) { + this->DebugState->FoundAt(value); + } + return; } diff --git a/Tests/RunCMake/find_path/FromPATHEnv-stderr.txt b/Tests/RunCMake/find_path/FromPATHEnv-stderr.txt index 9340c7aa7a..a2cd856184 100644 --- a/Tests/RunCMake/find_path/FromPATHEnv-stderr.txt +++ b/Tests/RunCMake/find_path/FromPATHEnv-stderr.txt @@ -26,4 +26,4 @@ find_path considered the following locations:.* The item was found at.* -.*include/PrefixInPATH.* +.*find_path/include/ diff --git a/Tests/RunCMake/find_path/FromPATHEnvDebugVar-stderr.txt b/Tests/RunCMake/find_path/FromPATHEnvDebugVar-stderr.txt index 9340c7aa7a..a2cd856184 100644 --- a/Tests/RunCMake/find_path/FromPATHEnvDebugVar-stderr.txt +++ b/Tests/RunCMake/find_path/FromPATHEnvDebugVar-stderr.txt @@ -26,4 +26,4 @@ find_path considered the following locations:.* The item was found at.* -.*include/PrefixInPATH.* +.*find_path/include/