From c32f37df2c4d474fb0fb28baeac2fa27966f550d Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 23 Oct 2026 13:28:10 -0400 Subject: [PATCH] enable_language: Include unset variables in what to propagate. Fixes: #28200 --- Source/cmDefinitions.cxx | 6 ++++-- Source/cmDefinitions.h | 9 ++++++++- Source/cmGlobalGenerator.cxx | 1 - Source/cmStateSnapshot.cxx | 3 ++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx index c7cc47aed2..983cb76935 100644 --- a/Source/cmDefinitions.cxx +++ b/Source/cmDefinitions.cxx @@ -79,7 +79,8 @@ cmDefinitions cmDefinitions::MakeClosure(StackIter begin, StackIter end) } std::vector cmDefinitions::ClosureKeys(StackIter begin, - StackIter end) + StackIter end, + UnsetKeys unsetKeys) { std::vector defined; std::unordered_set bound; @@ -88,7 +89,8 @@ std::vector cmDefinitions::ClosureKeys(StackIter begin, defined.reserve(defined.size() + it->Map.size()); for (auto const& mi : it->Map) { // Use this key if it is not already set or unset. - if (bound.emplace(mi.first.view()).second && mi.second.Value) { + if (bound.emplace(mi.first.view()).second && + (unsetKeys == UnsetKeys::Include || mi.second.Value)) { defined.push_back(*mi.first.str_if_stable()); } } diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h index b423cacfd3..889fe0a31b 100644 --- a/Source/cmDefinitions.h +++ b/Source/cmDefinitions.h @@ -34,7 +34,14 @@ public: static bool HasKey(std::string const& key, StackIter begin, StackIter end); - static std::vector ClosureKeys(StackIter begin, StackIter end); + enum class UnsetKeys + { + Exclude, + Include, + }; + + static std::vector ClosureKeys( + StackIter begin, StackIter end, UnsetKeys unsetKeys = UnsetKeys::Exclude); static cmDefinitions MakeClosure(StackIter begin, StackIter end); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 1004db7e4c..dcba10eca2 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1159,7 +1159,6 @@ void cmGlobalGenerator::EnableLanguage( cmStateSnapshot snapshot = mf->GetStateSnapshot(); bool warnCMP0220 = false; for (std::string const& key : snapshot.LocalKeys()) { - // Should never need to propagate unsets if (!key.empty()) { if (mf->RaiseToRoot(key, snapshot.GetDefinition(key).GetCStr()) == cmStateSnapshot::WarnCMP0220::Yes) { diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx index 1b673aa4fd..b6be568cee 100644 --- a/Source/cmStateSnapshot.cxx +++ b/Source/cmStateSnapshot.cxx @@ -417,7 +417,8 @@ std::vector cmStateSnapshot::ClosureKeys() const std::vector cmStateSnapshot::LocalKeys() const { std::vector keys = cmDefinitions::ClosureKeys( - this->Position->Vars, this->Position->ScopeParent->Vars); + this->Position->Vars, this->Position->ScopeParent->Vars, + cmDefinitions::UnsetKeys::Include); // Remove keys that are the same in the parent scope to avoid propagating // logic meant to restore variables back to their original value.