瀏覽代碼

cmMakefile: add support for a "synthesized" target

It is a normal target, but will end up copying its internals from
another target. Keep track of this state so that such copying can only
occur when intended.
Ben Boeckel 2 年之前
父節點
當前提交
c97de1047f
共有 6 個文件被更改,包括 41 次插入4 次删除
  1. 5 0
      Source/cmGeneratorTarget.cxx
  2. 1 0
      Source/cmGeneratorTarget.h
  3. 12 3
      Source/cmMakefile.cxx
  4. 4 1
      Source/cmMakefile.h
  5. 17 0
      Source/cmTarget.cxx
  6. 2 0
      Source/cmTarget.h

+ 5 - 0
Source/cmGeneratorTarget.cxx

@@ -1242,6 +1242,11 @@ bool cmGeneratorTarget::IsNormal() const
   return this->Target->IsNormal();
 }
 
+bool cmGeneratorTarget::IsSynthetic() const
+{
+  return this->Target->IsSynthetic();
+}
+
 bool cmGeneratorTarget::IsImported() const
 {
   return this->Target->IsImported();

+ 1 - 0
Source/cmGeneratorTarget.h

@@ -51,6 +51,7 @@ public:
 
   bool IsInBuildSystem() const;
   bool IsNormal() const;
+  bool IsSynthetic() const;
   bool IsImported() const;
   bool IsImportedGloballyVisible() const;
   bool CanCompileSources() const;

+ 12 - 3
Source/cmMakefile.cxx

@@ -2115,12 +2115,21 @@ cmTarget* cmMakefile::AddNewTarget(cmStateEnums::TargetType type,
   return &this->CreateNewTarget(name, type).first;
 }
 
+cmTarget* cmMakefile::AddSynthesizedTarget(cmStateEnums::TargetType type,
+                                           const std::string& name)
+{
+  return &this
+            ->CreateNewTarget(name, type, cmTarget::PerConfig::Yes,
+                              cmTarget::Visibility::Generated)
+            .first;
+}
+
 std::pair<cmTarget&, bool> cmMakefile::CreateNewTarget(
   const std::string& name, cmStateEnums::TargetType type,
-  cmTarget::PerConfig perConfig)
+  cmTarget::PerConfig perConfig, cmTarget::Visibility vis)
 {
-  auto ib = this->Targets.emplace(
-    name, cmTarget(name, type, cmTarget::Visibility::Normal, this, perConfig));
+  auto ib =
+    this->Targets.emplace(name, cmTarget(name, type, vis, this, perConfig));
   auto it = ib.first;
   if (!ib.second) {
     return std::make_pair(std::ref(it->second), false);

+ 4 - 1
Source/cmMakefile.h

@@ -241,10 +241,13 @@ public:
 
   std::pair<cmTarget&, bool> CreateNewTarget(
     const std::string& name, cmStateEnums::TargetType type,
-    cmTarget::PerConfig perConfig = cmTarget::PerConfig::Yes);
+    cmTarget::PerConfig perConfig = cmTarget::PerConfig::Yes,
+    cmTarget::Visibility vis = cmTarget::Visibility::Normal);
 
   cmTarget* AddNewTarget(cmStateEnums::TargetType type,
                          const std::string& name);
+  cmTarget* AddSynthesizedTarget(cmStateEnums::TargetType type,
+                                 const std::string& name);
 
   /** Create a target instance for the utility.  */
   cmTarget* AddNewUtilityTarget(const std::string& utilityName,

+ 17 - 0
Source/cmTarget.cxx

@@ -2559,6 +2559,7 @@ bool cmTarget::IsNormal() const
   switch (this->impl->TargetVisibility) {
     case Visibility::Normal:
       return true;
+    case Visibility::Generated:
     case Visibility::Imported:
     case Visibility::ImportedGlobally:
       return false;
@@ -2567,6 +2568,20 @@ bool cmTarget::IsNormal() const
   return false;
 }
 
+bool cmTarget::IsSynthetic() const
+{
+  switch (this->impl->TargetVisibility) {
+    case Visibility::Generated:
+      return true;
+    case Visibility::Normal:
+    case Visibility::Imported:
+    case Visibility::ImportedGlobally:
+      return false;
+  }
+  assert(false && "unknown visibility (IsSynthetic)");
+  return false;
+}
+
 bool cmTargetInternals::IsImported() const
 {
   switch (this->TargetVisibility) {
@@ -2574,6 +2589,7 @@ bool cmTargetInternals::IsImported() const
     case cmTarget::Visibility::ImportedGlobally:
       return true;
     case cmTarget::Visibility::Normal:
+    case cmTarget::Visibility::Generated:
       return false;
   }
   assert(false && "unknown visibility (IsImported)");
@@ -2591,6 +2607,7 @@ bool cmTarget::IsImportedGloballyVisible() const
     case Visibility::ImportedGlobally:
       return true;
     case Visibility::Normal:
+    case Visibility::Generated:
     case Visibility::Imported:
       return false;
   }

+ 2 - 0
Source/cmTarget.h

@@ -49,6 +49,7 @@ public:
   enum class Visibility
   {
     Normal,
+    Generated,
     Imported,
     ImportedGlobally,
   };
@@ -206,6 +207,7 @@ public:
   bool IsAIX() const;
 
   bool IsNormal() const;
+  bool IsSynthetic() const;
   bool IsImported() const;
   bool IsImportedGloballyVisible() const;
   bool IsPerConfig() const;