From d4ab2797424b1c9de3a765c1b5fd2e7fcf5a2b28 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Mon, 10 Mar 2025 15:27:05 -0400 Subject: [PATCH] cmState: Track known projects Add a member to directory state that records the set of known projects. Add a method to query whether a project exists. Internally, while this doesn't allow us to confirm that a variable like `foo_VERSION` is actually associated with a project `foo`, it provides a much stronger indicator than the mere existence of said variable. --- Source/cmStatePrivate.h | 3 +++ Source/cmStateSnapshot.cxx | 8 ++++++++ Source/cmStateSnapshot.h | 1 + 3 files changed, 12 insertions(+) diff --git a/Source/cmStatePrivate.h b/Source/cmStatePrivate.h index c693d34168..afcf1fca95 100644 --- a/Source/cmStatePrivate.h +++ b/Source/cmStatePrivate.h @@ -5,6 +5,7 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include #include #include #include @@ -82,6 +83,8 @@ struct cmStateDetail::BuildsystemDirectoryStateType std::vector NormalTargetNames; std::vector ImportedTargetNames; + std::set Projects; + std::string ProjectName; cmPropertyMap Properties; diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx index 3e3fbbbe04..3b35c4adb8 100644 --- a/Source/cmStateSnapshot.cxx +++ b/Source/cmStateSnapshot.cxx @@ -5,10 +5,12 @@ #include #include +#include #include #include #include +#include #include "cmDefinitions.h" #include "cmLinkedTree.h" @@ -413,6 +415,7 @@ cmStateDirectory cmStateSnapshot::GetDirectory() const void cmStateSnapshot::SetProjectName(std::string const& name) { this->Position->BuildSystemDirectory->ProjectName = name; + this->Position->BuildSystemDirectory->Projects.insert(name); } std::string cmStateSnapshot::GetProjectName() const @@ -420,6 +423,11 @@ std::string cmStateSnapshot::GetProjectName() const return this->Position->BuildSystemDirectory->ProjectName; } +bool cmStateSnapshot::CheckProjectName(std::string const& name) const +{ + return cm::contains(this->Position->BuildSystemDirectory->Projects, name); +} + cmPackageState& cmStateSnapshot::GetPackageState( std::string const& packagePath) { diff --git a/Source/cmStateSnapshot.h b/Source/cmStateSnapshot.h index edc7e29399..07071b1239 100644 --- a/Source/cmStateSnapshot.h +++ b/Source/cmStateSnapshot.h @@ -57,6 +57,7 @@ public: void SetProjectName(std::string const& name); std::string GetProjectName() const; + bool CheckProjectName(std::string const& name) const; cmPackageState& GetPackageState(std::string const& packagePath);