浏览代码

Genex: Re-order TARGET_PROPERTY logic to de-duplicate checks

Check for usage requirement properties early enough to avoid duplicate
checks in other conditions.
Brad King 6 年之前
父节点
当前提交
7caebeb0e4
共有 1 个文件被更改,包括 26 次插入42 次删除
  1. 26 42
      Source/cmGeneratorExpressionNode.cxx

+ 26 - 42
Source/cmGeneratorExpressionNode.cxx

@@ -1038,14 +1038,6 @@ static const struct CompileLanguageAndIdNode : public cmGeneratorExpressionNode
   }
 } languageAndIdNode;
 
-#define TRANSITIVE_PROPERTY_NAME(PROPERTY) , "INTERFACE_" #PROPERTY
-
-static const char* targetPropertyTransitiveWhitelist[] = {
-  nullptr CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(TRANSITIVE_PROPERTY_NAME)
-};
-
-#undef TRANSITIVE_PROPERTY_NAME
-
 template <typename T>
 std::string getLinkedTargetsContent(
   std::vector<T> const& libraries, cmGeneratorTarget const* target,
@@ -1205,6 +1197,28 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
       return target->GetLinkerLanguage(context->Config);
     }
 
+    std::string interfacePropertyName;
+    bool isInterfaceProperty = false;
+
+#define POPULATE_INTERFACE_PROPERTY_NAME(prop)                                \
+  if (propertyName == #prop) {                                                \
+    interfacePropertyName = "INTERFACE_" #prop;                               \
+  } else if (propertyName == "INTERFACE_" #prop) {                            \
+    interfacePropertyName = "INTERFACE_" #prop;                               \
+    isInterfaceProperty = true;                                               \
+  } else
+
+    CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(POPULATE_INTERFACE_PROPERTY_NAME)
+    // Note that the above macro terminates with an else
+    /* else */ if (cmHasLiteralPrefix(propertyName, "COMPILE_DEFINITIONS_")) {
+      cmPolicies::PolicyStatus polSt =
+        context->LG->GetPolicyStatus(cmPolicies::CMP0043);
+      if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) {
+        interfacePropertyName = "INTERFACE_COMPILE_DEFINITIONS";
+      }
+    }
+#undef POPULATE_INTERFACE_PROPERTY_NAME
+
     cmGeneratorExpressionDAGChecker dagChecker(
       context->Backtrace, target, propertyName, content, dagCheckerParent);
 
@@ -1216,12 +1230,9 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
         // No error. We just skip cyclic references.
         return std::string();
       case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
-        for (size_t i = 1; i < cm::size(targetPropertyTransitiveWhitelist);
-             ++i) {
-          if (targetPropertyTransitiveWhitelist[i] == propertyName) {
-            // No error. We're not going to find anything new here.
-            return std::string();
-          }
+        if (isInterfaceProperty) {
+          // No error. We're not going to find anything new here.
+          return std::string();
         }
       case cmGeneratorExpressionDAGChecker::DAG:
         break;
@@ -1239,10 +1250,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
           dagCheckerParent->EvaluatingPICExpression()) {
         // No check required.
       } else if (dagCheckerParent->EvaluatingLinkLibraries()) {
-#define TRANSITIVE_PROPERTY_COMPARE(PROPERTY)                                 \
-  (#PROPERTY == propertyName || "INTERFACE_" #PROPERTY == propertyName) ||
-        if (CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(
-              TRANSITIVE_PROPERTY_COMPARE) false) { // NOLINT(*)
+        if (!interfacePropertyName.empty()) {
           reportError(
             context, content->GetOriginalExpression(),
             "$<TARGET_PROPERTY:...> expression in link libraries "
@@ -1250,42 +1258,18 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
             "over the link libraries, creating a recursion.");
           return std::string();
         }
-#undef TRANSITIVE_PROPERTY_COMPARE
 
         if (!haveProp) {
           return std::string();
         }
       } else {
 #define ASSERT_TRANSITIVE_PROPERTY_METHOD(METHOD) dagCheckerParent->METHOD() ||
-
         assert(CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(
           ASSERT_TRANSITIVE_PROPERTY_METHOD) false); // NOLINT(clang-tidy)
 #undef ASSERT_TRANSITIVE_PROPERTY_METHOD
       }
     }
 
-    std::string interfacePropertyName;
-    bool isInterfaceProperty = false;
-
-#define POPULATE_INTERFACE_PROPERTY_NAME(prop)                                \
-  if (propertyName == #prop) {                                                \
-    interfacePropertyName = "INTERFACE_" #prop;                               \
-  } else if (propertyName == "INTERFACE_" #prop) {                            \
-    interfacePropertyName = "INTERFACE_" #prop;                               \
-    isInterfaceProperty = true;                                               \
-  } else
-
-    CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(POPULATE_INTERFACE_PROPERTY_NAME)
-    // Note that the above macro terminates with an else
-    /* else */ if (cmHasLiteralPrefix(propertyName, "COMPILE_DEFINITIONS_")) {
-      cmPolicies::PolicyStatus polSt =
-        context->LG->GetPolicyStatus(cmPolicies::CMP0043);
-      if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) {
-        interfacePropertyName = "INTERFACE_COMPILE_DEFINITIONS";
-      }
-    }
-#undef POPULATE_INTERFACE_PROPERTY_NAME
-
     if (!haveProp && !target->IsImported() &&
         target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
       if (target->IsLinkInterfaceDependentBoolProperty(propertyName,