Browse Source

cmTarget: store visibility as an `enum` rather than bools

C++ modules are going to introduce a third concept of "synthesized"
targets, so update logic where needed to avoid assuming "not imported?
must be normal".

Also add an accessor method to perform queries against the visibility.
Ben Boeckel 2 years ago
parent
commit
5b58695321
4 changed files with 53 additions and 13 deletions
  1. 5 0
      Source/cmGeneratorTarget.cxx
  2. 1 0
      Source/cmGeneratorTarget.h
  3. 46 13
      Source/cmTarget.cxx
  4. 1 0
      Source/cmTarget.h

+ 5 - 0
Source/cmGeneratorTarget.cxx

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

+ 1 - 0
Source/cmGeneratorTarget.h

@@ -50,6 +50,7 @@ public:
   cmGlobalGenerator* GetGlobalGenerator() const;
 
   bool IsInBuildSystem() const;
+  bool IsNormal() const;
   bool IsImported() const;
   bool IsImportedGloballyVisible() const;
   bool CanCompileSources() const;

+ 46 - 13
Source/cmTarget.cxx

@@ -629,10 +629,9 @@ public:
   bool IsDLLPlatform;
   bool IsAIX;
   bool IsAndroid;
-  bool IsImportedTarget;
-  bool ImportedGloballyVisible;
   bool BuildInterfaceIncludesAppended;
   bool PerConfig;
+  cmTarget::Visibility TargetVisibility;
   std::set<BT<std::pair<std::string, bool>>> Utilities;
   std::vector<cmCustomCommand> PreBuildCommands;
   std::vector<cmCustomCommand> PreLinkCommands;
@@ -667,6 +666,8 @@ public:
 
   cmTargetInternals();
 
+  bool IsImported() const;
+
   bool CheckImportedLibName(std::string const& prop,
                             std::string const& value) const;
 
@@ -914,9 +915,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
   this->impl->IsDLLPlatform = false;
   this->impl->IsAIX = false;
   this->impl->IsAndroid = false;
-  this->impl->IsImportedTarget =
-    (vis == VisibilityImported || vis == VisibilityImportedGlobally);
-  this->impl->ImportedGloballyVisible = vis == VisibilityImportedGlobally;
+  this->impl->TargetVisibility = vis;
   this->impl->BuildInterfaceIncludesAppended = false;
   this->impl->PerConfig = (perConfig == PerConfig::Yes);
 
@@ -939,7 +938,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
   // Save the backtrace of target construction.
   this->impl->Backtrace = this->impl->Makefile->GetBacktrace();
 
-  if (!this->IsImported()) {
+  if (this->IsNormal()) {
     // Initialize the INCLUDE_DIRECTORIES property based on the current value
     // of the same directory property:
     this->impl->IncludeDirectories.CopyFromDirectory(
@@ -988,7 +987,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
   if (this->impl->TargetType != cmStateEnums::UTILITY &&
       this->impl->TargetType != cmStateEnums::GLOBAL_TARGET) {
     metConditions.insert(TargetProperty::InitCondition::NormalTarget);
-    if (!this->IsImported()) {
+    if (this->IsNormal()) {
       metConditions.insert(
         TargetProperty::InitCondition::NormalNonImportedTarget);
     }
@@ -1091,7 +1090,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
     }
   }
 
-  if (this->IsImported() || mf->GetPropertyAsBool("SYSTEM")) {
+  if (!this->IsNormal() || mf->GetPropertyAsBool("SYSTEM")) {
     this->SetProperty("SYSTEM", "ON");
   }
 
@@ -1863,8 +1862,8 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value)
       return;
     }
     /* no need to change anything if value does not change */
-    if (!this->impl->ImportedGloballyVisible) {
-      this->impl->ImportedGloballyVisible = true;
+    if (!this->IsImportedGloballyVisible()) {
+      this->impl->TargetVisibility = VisibilityImportedGlobally;
       this->GetGlobalGenerator()->IndexTarget(this);
     }
   } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME") &&
@@ -2555,14 +2554,48 @@ bool cmTarget::IsAIX() const
   return this->impl->IsAIX;
 }
 
+bool cmTarget::IsNormal() const
+{
+  switch (this->impl->TargetVisibility) {
+    case VisibilityNormal:
+      return true;
+    case VisibilityImported:
+    case VisibilityImportedGlobally:
+      return false;
+  }
+  assert(false && "unknown visibility (IsNormal)");
+  return false;
+}
+
+bool cmTargetInternals::IsImported() const
+{
+  switch (this->TargetVisibility) {
+    case cmTarget::VisibilityImported:
+    case cmTarget::VisibilityImportedGlobally:
+      return true;
+    case cmTarget::VisibilityNormal:
+      return false;
+  }
+  assert(false && "unknown visibility (IsImported)");
+  return false;
+}
+
 bool cmTarget::IsImported() const
 {
-  return this->impl->IsImportedTarget;
+  return this->impl->IsImported();
 }
 
 bool cmTarget::IsImportedGloballyVisible() const
 {
-  return this->impl->ImportedGloballyVisible;
+  switch (this->impl->TargetVisibility) {
+    case VisibilityImportedGlobally:
+      return true;
+    case VisibilityNormal:
+    case VisibilityImported:
+      return false;
+  }
+  assert(false && "unknown visibility (IsImportedGloballyVisible)");
+  return false;
 }
 
 bool cmTarget::IsPerConfig() const
@@ -2858,7 +2891,7 @@ bool cmTargetInternals::CheckImportedLibName(std::string const& prop,
                                              std::string const& value) const
 {
   if (this->TargetType != cmStateEnums::INTERFACE_LIBRARY ||
-      !this->IsImportedTarget) {
+      !this->IsImported()) {
     this->Makefile->IssueMessage(
       MessageType::FATAL_ERROR,
       prop +

+ 1 - 0
Source/cmTarget.h

@@ -205,6 +205,7 @@ public:
   //! Return whether or not we are targeting AIX.
   bool IsAIX() const;
 
+  bool IsNormal() const;
   bool IsImported() const;
   bool IsImportedGloballyVisible() const;
   bool IsPerConfig() const;