cmTarget: Add origin property

Add the concept of "origin" to cmTarget. For now, only CPS targets get a
unique origin, but this might be expanded in the future. This will allow
us to implement different behaviors based on a target's origin.

In particular, this has been requested as a means of addressing #26998
and #27022.
This commit is contained in:
Matthew Woehlke
2025-07-22 11:20:10 -04:00
parent f65949b96e
commit cc42f1047b
3 changed files with 26 additions and 0 deletions

View File

@@ -692,6 +692,7 @@ cmTarget* cmPackageInfoReader::AddLibraryComponent(
{
// Create the imported target.
cmTarget* const target = makefile->AddImportedTarget(name, type, false);
target->SetOrigin(cmTarget::Origin::Cps);
// Set default configurations.
if (!this->DefaultConfigurations.empty()) {

View File

@@ -589,6 +589,7 @@ class cmTargetInternals
{
public:
cmStateEnums::TargetType TargetType;
cmTarget::Origin Origin = cmTarget::Origin::Unknown;
cmMakefile* Makefile;
cmPolicies::PolicyMap PolicyMap;
cmTarget const* TemplateTarget;
@@ -1112,6 +1113,18 @@ cmStateEnums::TargetType cmTarget::GetType() const
return this->impl->TargetType;
}
void cmTarget::SetOrigin(Origin origin)
{
assert(origin != cmTarget::Origin::Unknown);
assert(this->impl->Origin == cmTarget::Origin::Unknown);
this->impl->Origin = origin;
}
cmTarget::Origin cmTarget::GetOrigin() const
{
return this->impl->Origin;
}
cmMakefile* cmTarget::GetMakefile() const
{
return this->impl->Makefile;

View File

@@ -51,6 +51,12 @@ public:
Foreign,
};
enum class Origin
{
Cps,
Unknown,
};
enum class PerConfig
{
Yes,
@@ -70,6 +76,12 @@ public:
//! Return the type of target.
cmStateEnums::TargetType GetType() const;
//! Set the origin of the target.
void SetOrigin(Origin origin);
//! Return the origin of the target.
Origin GetOrigin() const;
//! Get the cmMakefile that owns this target.
cmMakefile* GetMakefile() const;