cmFindCommon: support suppressing implicit event logging

`find_package` has different behavior where not all modes support
reliably knowing if a search has already happened in order to not always
report failing searches.
This commit is contained in:
Ben Boeckel
2025-05-20 20:29:47 +02:00
committed by Brad King
parent 5aefc8b7b8
commit a90598f17c
2 changed files with 13 additions and 5 deletions

View File

@@ -507,6 +507,11 @@ void cmFindCommonDebugState::FailedAt(std::string const& path,
this->FailedAtImpl(path, regexName);
}
bool cmFindCommonDebugState::ShouldImplicitlyLogEvents() const
{
return true;
}
void cmFindCommonDebugState::Write()
{
auto const* const fc = this->FindCommand;
@@ -517,11 +522,13 @@ void cmFindCommonDebugState::Write()
fc->Makefile->GetCMakeInstance()->GetConfigureLog()) {
// Write event if any of:
// - debug mode is enabled
// - the variable was not defined (first run)
// - the variable found state does not match the new found state (state
// transition)
if (fc->DebugModeEnabled() || !fc->IsDefined() ||
fc->IsFound() != this->IsFound) {
// - implicit logging should happen and:
// - the variable was not defined (first run)
// - the variable found state does not match the new found state (state
// transition)
if (fc->DebugModeEnabled() ||
(this->ShouldImplicitlyLogEvents() &&
(!fc->IsDefined() || fc->IsFound() != this->IsFound))) {
this->WriteEvent(*log, *fc->Makefile);
}
}

View File

@@ -185,6 +185,7 @@ protected:
virtual void FoundAtImpl(std::string const& path, std::string regexName) = 0;
virtual void FailedAtImpl(std::string const& path,
std::string regexName) = 0;
virtual bool ShouldImplicitlyLogEvents() const;
virtual void WriteDebug() const = 0;
#ifndef CMAKE_BOOTSTRAP