Browse Source

Genex: Reject TARGET_OBJECTS on non-object libraries earlier

Move the diagnostic that rejects the TARGET_OBJECTS generator expression
in non-buildsystem context until after the check for whether the named
target is an object library.  This order will makes more sense than the
previous order once TARGET_OBJECTS is allowed in non-buildsystem
context.
Brad King 8 years ago
parent
commit
ac0cf7ff4f

+ 8 - 9
Source/cmGeneratorExpressionNode.cxx

@@ -1226,15 +1226,6 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
                        cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
     CM_OVERRIDE
   {
-    if (!context->EvaluateForBuildsystem) {
-      std::ostringstream e;
-      e << "The evaluation of the TARGET_OBJECTS generator expression "
-           "is only suitable for consumption by CMake.  It is not suitable "
-           "for writing out elsewhere.";
-      reportError(context, content->GetOriginalExpression(), e.str());
-      return std::string();
-    }
-
     std::string tgtName = parameters.front();
     cmGeneratorTarget* gt = context->LG->FindGeneratorTargetToUse(tgtName);
     if (!gt) {
@@ -1251,6 +1242,14 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
       reportError(context, content->GetOriginalExpression(), e.str());
       return std::string();
     }
+    if (!context->EvaluateForBuildsystem) {
+      std::ostringstream e;
+      e << "The evaluation of the TARGET_OBJECTS generator expression "
+           "is only suitable for consumption by CMake.  It is not suitable "
+           "for writing out elsewhere.";
+      reportError(context, content->GetOriginalExpression(), e.str());
+      return std::string();
+    }
 
     std::vector<std::string> objects;
     gt->GetTargetObjectNames(context->Config, objects);

+ 3 - 4
Tests/RunCMake/File_Generate/OutputNameMatchesObjects-stderr.txt

@@ -1,9 +1,8 @@
-CMake Error at OutputNameMatchesObjects.cmake:2 \(file\):
+CMake Error at OutputNameMatchesObjects.cmake:[0-9]+ \(file\):
   Error evaluating generator expression:
 
     \$<TARGET_OBJECTS:foo>
 
-  The evaluation of the TARGET_OBJECTS generator expression is only suitable
-  for consumption by CMake.  It is not suitable for writing out elsewhere.
+  Objects of target "foo" referenced but is not an OBJECT library.
 Call Stack \(most recent call first\):
-  CMakeLists.txt:6 \(include\)
+  CMakeLists.txt:[0-9]+ \(include\)

+ 0 - 27
Tests/RunCMake/TargetObjects/BadContext-stderr.txt

@@ -1,27 +0,0 @@
-(CMake Error at BadContext.cmake:4 \(file\):
-  Error evaluating generator expression:
-
-    \$<TARGET_OBJECTS:NoTarget>
-
-  The evaluation of the TARGET_OBJECTS generator expression is only suitable
-  for consumption by CMake.  It is not suitable for writing out elsewhere.
-Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)
-*)+
-(CMake Error at BadContext.cmake:5 \(file\):
-  Error evaluating generator expression:
-
-    \$<TARGET_OBJECTS:NoTarget>
-
-  The evaluation of the TARGET_OBJECTS generator expression is only suitable
-  for consumption by CMake.  It is not suitable for writing out elsewhere.
-Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)
-*)+
-CMake Error:
-  Error evaluating generator expression:
-
-    \$<TARGET_OBJECTS:NoTarget>
-
-  The evaluation of the TARGET_OBJECTS generator expression is only suitable
-  for consumption by CMake.  It is not suitable for writing out elsewhere.

+ 0 - 0
Tests/RunCMake/TargetObjects/BadContext-result.txt → Tests/RunCMake/TargetObjects/NoTarget-result.txt


+ 24 - 0
Tests/RunCMake/TargetObjects/NoTarget-stderr.txt

@@ -0,0 +1,24 @@
+(CMake Error at NoTarget.cmake:4 \(file\):
+  Error evaluating generator expression:
+
+    \$<TARGET_OBJECTS:NoTarget>
+
+  Objects of target "NoTarget" referenced but no such target exists.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+*)+
+(CMake Error at NoTarget.cmake:5 \(file\):
+  Error evaluating generator expression:
+
+    \$<TARGET_OBJECTS:NoTarget>
+
+  Objects of target "NoTarget" referenced but no such target exists.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+*)+
+CMake Error:
+  Error evaluating generator expression:
+
+    \$<TARGET_OBJECTS:NoTarget>
+
+  Objects of target "NoTarget" referenced but no such target exists.

+ 0 - 0
Tests/RunCMake/TargetObjects/BadContext.cmake → Tests/RunCMake/TargetObjects/NoTarget.cmake


+ 1 - 0
Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt

@@ -0,0 +1 @@
+1

+ 8 - 0
Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt

@@ -0,0 +1,8 @@
+CMake Error at NotObjlibTarget.cmake:3 \(file\):
+  Error evaluating generator expression:
+
+    \$<TARGET_OBJECTS:StaticLib>
+
+  Objects of target "StaticLib" referenced but is not an OBJECT library.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)

+ 3 - 0
Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake

@@ -0,0 +1,3 @@
+add_library(StaticLib empty.cpp)
+
+file(GENERATE OUTPUT test_output CONTENT $<TARGET_OBJECTS:StaticLib>)

+ 2 - 1
Tests/RunCMake/TargetObjects/RunCMakeTest.cmake

@@ -1,3 +1,4 @@
 include(RunCMake)
 
-run_cmake(BadContext)
+run_cmake(NoTarget)
+run_cmake(NotObjlibTarget)

+ 4 - 0
Tests/RunCMake/TargetObjects/empty.cpp

@@ -0,0 +1,4 @@
+int empty()
+{
+  return 0;
+}