Browse Source

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.
Matthew Woehlke 3 months ago
parent
commit
cc42f1047b
3 changed files with 26 additions and 0 deletions
  1. 1 0
      Source/cmPackageInfoReader.cxx
  2. 13 0
      Source/cmTarget.cxx
  3. 12 0
      Source/cmTarget.h

+ 1 - 0
Source/cmPackageInfoReader.cxx

@@ -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()) {

+ 13 - 0
Source/cmTarget.cxx

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

+ 12 - 0
Source/cmTarget.h

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