Преглед изворни кода

Factor out generator checks for filtering on non-compiling targets

Add a `cmGeneratorTarget::CanCompileSources` helper method to tell
generators whether a target might compile anything.
Brad King пре 5 година
родитељ
комит
2f0790df50

+ 5 - 0
Source/cmGeneratorTarget.cxx

@@ -1120,6 +1120,11 @@ bool cmGeneratorTarget::IsImportedGloballyVisible() const
   return this->Target->IsImportedGloballyVisible();
   return this->Target->IsImportedGloballyVisible();
 }
 }
 
 
+bool cmGeneratorTarget::CanCompileSources() const
+{
+  return this->Target->CanCompileSources();
+}
+
 const std::string& cmGeneratorTarget::GetLocationForBuild() const
 const std::string& cmGeneratorTarget::GetLocationForBuild() const
 {
 {
   static std::string location;
   static std::string location;

+ 1 - 0
Source/cmGeneratorTarget.h

@@ -48,6 +48,7 @@ public:
   bool IsInBuildSystem() const;
   bool IsInBuildSystem() const;
   bool IsImported() const;
   bool IsImported() const;
   bool IsImportedGloballyVisible() const;
   bool IsImportedGloballyVisible() const;
+  bool CanCompileSources() const;
   const std::string& GetLocation(const std::string& config) const;
   const std::string& GetLocation(const std::string& config) const;
 
 
   std::vector<cmCustomCommand> const& GetPreBuildCommands() const;
   std::vector<cmCustomCommand> const& GetPreBuildCommands() const;

+ 4 - 12
Source/cmGlobalGenerator.cxx

@@ -302,9 +302,7 @@ bool cmGlobalGenerator::CheckTargetsForMissingSources() const
   bool failed = false;
   bool failed = false;
   for (const auto& localGen : this->LocalGenerators) {
   for (const auto& localGen : this->LocalGenerators) {
     for (const auto& target : localGen->GetGeneratorTargets()) {
     for (const auto& target : localGen->GetGeneratorTargets()) {
-      if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET ||
-          target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY ||
-          target->GetType() == cmStateEnums::TargetType::UTILITY ||
+      if (!target->CanCompileSources() ||
           cmIsOn(target->GetProperty("ghs_integrity_app"))) {
           cmIsOn(target->GetProperty("ghs_integrity_app"))) {
         continue;
         continue;
       }
       }
@@ -358,9 +356,7 @@ bool cmGlobalGenerator::CheckTargetsForPchCompilePdb() const
   bool failed = false;
   bool failed = false;
   for (const auto& generator : this->LocalGenerators) {
   for (const auto& generator : this->LocalGenerators) {
     for (const auto& target : generator->GetGeneratorTargets()) {
     for (const auto& target : generator->GetGeneratorTargets()) {
-      if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET ||
-          target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY ||
-          target->GetType() == cmStateEnums::TargetType::UTILITY ||
+      if (!target->CanCompileSources() ||
           cmIsOn(target->GetProperty("ghs_integrity_app"))) {
           cmIsOn(target->GetProperty("ghs_integrity_app"))) {
         continue;
         continue;
       }
       }
@@ -1595,9 +1591,7 @@ bool cmGlobalGenerator::AddAutomaticSources()
   for (const auto& lg : this->LocalGenerators) {
   for (const auto& lg : this->LocalGenerators) {
     lg->CreateEvaluationFileOutputs();
     lg->CreateEvaluationFileOutputs();
     for (const auto& gt : lg->GetGeneratorTargets()) {
     for (const auto& gt : lg->GetGeneratorTargets()) {
-      if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
-          gt->GetType() == cmStateEnums::UTILITY ||
-          gt->GetType() == cmStateEnums::GLOBAL_TARGET) {
+      if (!gt->CanCompileSources()) {
         continue;
         continue;
       }
       }
       lg->AddUnityBuild(gt.get());
       lg->AddUnityBuild(gt.get());
@@ -1609,9 +1603,7 @@ bool cmGlobalGenerator::AddAutomaticSources()
   }
   }
   for (const auto& lg : this->LocalGenerators) {
   for (const auto& lg : this->LocalGenerators) {
     for (const auto& gt : lg->GetGeneratorTargets()) {
     for (const auto& gt : lg->GetGeneratorTargets()) {
-      if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
-          gt->GetType() == cmStateEnums::UTILITY ||
-          gt->GetType() == cmStateEnums::GLOBAL_TARGET) {
+      if (!gt->CanCompileSources()) {
         continue;
         continue;
       }
       }
       // Handle targets that re-use a PCH from an above-handled target.
       // Handle targets that re-use a PCH from an above-handled target.

+ 1 - 1
Source/cmLocalGenerator.cxx

@@ -797,7 +797,7 @@ bool cmLocalGenerator::ComputeTargetCompileFeatures()
 
 
     // Now that C/C++ _STANDARD values have been computed
     // Now that C/C++ _STANDARD values have been computed
     // set the values to ObjC/ObjCXX _STANDARD variables
     // set the values to ObjC/ObjCXX _STANDARD variables
-    if (target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
+    if (target->CanCompileSources()) {
       for (std::string const& c : configNames) {
       for (std::string const& c : configNames) {
         target->ComputeCompileFeatures(c, inferredEnabledLanguages);
         target->ComputeCompileFeatures(c, inferredEnabledLanguages);
       }
       }

+ 1 - 2
Source/cmLocalUnixMakefileGenerator3.cxx

@@ -137,8 +137,7 @@ void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles(
   std::map<std::string, LocalObjectInfo>& localObjectFiles)
   std::map<std::string, LocalObjectInfo>& localObjectFiles)
 {
 {
   for (const auto& gt : this->GetGeneratorTargets()) {
   for (const auto& gt : this->GetGeneratorTargets()) {
-    if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
-        gt->GetType() == cmStateEnums::UTILITY) {
+    if (!gt->CanCompileSources()) {
       continue;
       continue;
     }
     }
     std::vector<cmSourceFile const*> objectSources;
     std::vector<cmSourceFile const*> objectSources;

+ 24 - 7
Source/cmTarget.cxx

@@ -272,8 +272,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
   };
   };
 
 
   // Setup default property values.
   // Setup default property values.
-  if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
-      this->GetType() != cmStateEnums::UTILITY) {
+  if (this->CanCompileSources()) {
     initProp("ANDROID_API");
     initProp("ANDROID_API");
     initProp("ANDROID_API_MIN");
     initProp("ANDROID_API_MIN");
     initProp("ANDROID_ARCH");
     initProp("ANDROID_ARCH");
@@ -505,6 +504,8 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
   if (impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
   if (impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
       impl->TargetType == cmStateEnums::MODULE_LIBRARY) {
       impl->TargetType == cmStateEnums::MODULE_LIBRARY) {
     this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
     this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
+  } else if (this->CanCompileSources()) {
+    initProp("POSITION_INDEPENDENT_CODE");
   }
   }
   if (impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
   if (impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
       impl->TargetType == cmStateEnums::EXECUTABLE) {
       impl->TargetType == cmStateEnums::EXECUTABLE) {
@@ -512,11 +513,6 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
     initProp("WINDOWS_EXPORT_ALL_SYMBOLS");
     initProp("WINDOWS_EXPORT_ALL_SYMBOLS");
   }
   }
 
 
-  if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
-      this->GetType() != cmStateEnums::UTILITY) {
-    initProp("POSITION_INDEPENDENT_CODE");
-  }
-
   // Record current policies for later use.
   // Record current policies for later use.
   impl->Makefile->RecordPolicies(impl->PolicyMap);
   impl->Makefile->RecordPolicies(impl->PolicyMap);
 
 
@@ -1910,6 +1906,27 @@ bool cmTarget::IsPerConfig() const
   return impl->PerConfig;
   return impl->PerConfig;
 }
 }
 
 
+bool cmTarget::CanCompileSources() const
+{
+  if (this->IsImported()) {
+    return false;
+  }
+  switch (this->GetType()) {
+    case cmStateEnums::EXECUTABLE:
+    case cmStateEnums::STATIC_LIBRARY:
+    case cmStateEnums::SHARED_LIBRARY:
+    case cmStateEnums::MODULE_LIBRARY:
+    case cmStateEnums::OBJECT_LIBRARY:
+      return true;
+    case cmStateEnums::UTILITY:
+    case cmStateEnums::INTERFACE_LIBRARY:
+    case cmStateEnums::GLOBAL_TARGET:
+    case cmStateEnums::UNKNOWN_LIBRARY:
+      break;
+  }
+  return false;
+}
+
 const char* cmTarget::GetSuffixVariableInternal(
 const char* cmTarget::GetSuffixVariableInternal(
   cmStateEnums::ArtifactType artifact) const
   cmStateEnums::ArtifactType artifact) const
 {
 {

+ 1 - 0
Source/cmTarget.h

@@ -196,6 +196,7 @@ public:
   bool IsImported() const;
   bool IsImported() const;
   bool IsImportedGloballyVisible() const;
   bool IsImportedGloballyVisible() const;
   bool IsPerConfig() const;
   bool IsPerConfig() const;
+  bool CanCompileSources() const;
 
 
   bool GetMappedConfig(std::string const& desired_config, cmProp& loc,
   bool GetMappedConfig(std::string const& desired_config, cmProp& loc,
                        cmProp& imp, std::string& suffix) const;
                        cmProp& imp, std::string& suffix) const;