summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-04-18 14:05:04 (GMT)
committerBrad King <brad.king@kitware.com>2017-04-18 14:29:36 (GMT)
commitac0cf7ff4f5a846381593cf28ebbc9cfaf107149 (patch)
treec87e38b9518483b9f7d7fbab681a38d6927a7998
parent8577978c580d09abc56fa39f387a3991c91c31ba (diff)
downloadCMake-ac0cf7ff4f5a846381593cf28ebbc9cfaf107149.zip
CMake-ac0cf7ff4f5a846381593cf28ebbc9cfaf107149.tar.gz
CMake-ac0cf7ff4f5a846381593cf28ebbc9cfaf107149.tar.bz2
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.
-rw-r--r--Source/cmGeneratorExpressionNode.cxx17
-rw-r--r--Tests/RunCMake/File_Generate/OutputNameMatchesObjects-stderr.txt7
-rw-r--r--Tests/RunCMake/TargetObjects/BadContext-stderr.txt27
-rw-r--r--Tests/RunCMake/TargetObjects/NoTarget-result.txt (renamed from Tests/RunCMake/TargetObjects/BadContext-result.txt)0
-rw-r--r--Tests/RunCMake/TargetObjects/NoTarget-stderr.txt24
-rw-r--r--Tests/RunCMake/TargetObjects/NoTarget.cmake (renamed from Tests/RunCMake/TargetObjects/BadContext.cmake)0
-rw-r--r--Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt1
-rw-r--r--Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake3
-rw-r--r--Tests/RunCMake/TargetObjects/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/TargetObjects/empty.cpp4
11 files changed, 53 insertions, 41 deletions
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx
index 29ad5d1..65949a3 100644
--- a/Source/cmGeneratorExpressionNode.cxx
+++ b/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);
diff --git a/Tests/RunCMake/File_Generate/OutputNameMatchesObjects-stderr.txt b/Tests/RunCMake/File_Generate/OutputNameMatchesObjects-stderr.txt
index d3aa973..b08ef5a 100644
--- a/Tests/RunCMake/File_Generate/OutputNameMatchesObjects-stderr.txt
+++ b/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\)
diff --git a/Tests/RunCMake/TargetObjects/BadContext-stderr.txt b/Tests/RunCMake/TargetObjects/BadContext-stderr.txt
deleted file mode 100644
index b78189e..0000000
--- a/Tests/RunCMake/TargetObjects/BadContext-stderr.txt
+++ /dev/null
@@ -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.
diff --git a/Tests/RunCMake/TargetObjects/BadContext-result.txt b/Tests/RunCMake/TargetObjects/NoTarget-result.txt
index d00491f..d00491f 100644
--- a/Tests/RunCMake/TargetObjects/BadContext-result.txt
+++ b/Tests/RunCMake/TargetObjects/NoTarget-result.txt
diff --git a/Tests/RunCMake/TargetObjects/NoTarget-stderr.txt b/Tests/RunCMake/TargetObjects/NoTarget-stderr.txt
new file mode 100644
index 0000000..eadccaf
--- /dev/null
+++ b/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.
diff --git a/Tests/RunCMake/TargetObjects/BadContext.cmake b/Tests/RunCMake/TargetObjects/NoTarget.cmake
index 5d7e33e..5d7e33e 100644
--- a/Tests/RunCMake/TargetObjects/BadContext.cmake
+++ b/Tests/RunCMake/TargetObjects/NoTarget.cmake
diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt b/Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt b/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt
new file mode 100644
index 0000000..a66794c
--- /dev/null
+++ b/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\)
diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake b/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake
new file mode 100644
index 0000000..8e5fdd0
--- /dev/null
+++ b/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake
@@ -0,0 +1,3 @@
+add_library(StaticLib empty.cpp)
+
+file(GENERATE OUTPUT test_output CONTENT $<TARGET_OBJECTS:StaticLib>)
diff --git a/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake b/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake
index 85c76e2..30b9fee 100644
--- a/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake
+++ b/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake
@@ -1,3 +1,4 @@
include(RunCMake)
-run_cmake(BadContext)
+run_cmake(NoTarget)
+run_cmake(NotObjlibTarget)
diff --git a/Tests/RunCMake/TargetObjects/empty.cpp b/Tests/RunCMake/TargetObjects/empty.cpp
new file mode 100644
index 0000000..4086dcc
--- /dev/null
+++ b/Tests/RunCMake/TargetObjects/empty.cpp
@@ -0,0 +1,4 @@
+int empty()
+{
+ return 0;
+}