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.
This commit is contained in:
Matthew Woehlke
2025-03-10 15:27:05 -04:00
parent 0ccbe5a2e1
commit d4ab279742
3 changed files with 12 additions and 0 deletions

View File

@@ -5,6 +5,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
@@ -82,6 +83,8 @@ struct cmStateDetail::BuildsystemDirectoryStateType
std::vector<std::string> NormalTargetNames;
std::vector<std::string> ImportedTargetNames;
std::set<std::string> Projects;
std::string ProjectName;
cmPropertyMap Properties;

View File

@@ -5,10 +5,12 @@
#include <algorithm>
#include <cassert>
#include <set>
#include <string>
#include <unordered_map>
#include <cm/iterator>
#include <cmext/algorithm>
#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)
{

View File

@@ -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);