From ac0cf7ff4f5a846381593cf28ebbc9cfaf107149 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 18 Apr 2017 10:05:04 -0400 Subject: 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. --- Source/cmGeneratorExpressionNode.cxx | 17 +++++++------- .../OutputNameMatchesObjects-stderr.txt | 7 +++--- Tests/RunCMake/TargetObjects/BadContext-result.txt | 1 - Tests/RunCMake/TargetObjects/BadContext-stderr.txt | 27 ---------------------- Tests/RunCMake/TargetObjects/BadContext.cmake | 7 ------ Tests/RunCMake/TargetObjects/NoTarget-result.txt | 1 + Tests/RunCMake/TargetObjects/NoTarget-stderr.txt | 24 +++++++++++++++++++ Tests/RunCMake/TargetObjects/NoTarget.cmake | 7 ++++++ .../TargetObjects/NotObjlibTarget-result.txt | 1 + .../TargetObjects/NotObjlibTarget-stderr.txt | 8 +++++++ Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake | 3 +++ Tests/RunCMake/TargetObjects/RunCMakeTest.cmake | 3 ++- Tests/RunCMake/TargetObjects/empty.cpp | 4 ++++ 13 files changed, 61 insertions(+), 49 deletions(-) delete mode 100644 Tests/RunCMake/TargetObjects/BadContext-result.txt delete mode 100644 Tests/RunCMake/TargetObjects/BadContext-stderr.txt delete mode 100644 Tests/RunCMake/TargetObjects/BadContext.cmake create mode 100644 Tests/RunCMake/TargetObjects/NoTarget-result.txt create mode 100644 Tests/RunCMake/TargetObjects/NoTarget-stderr.txt create mode 100644 Tests/RunCMake/TargetObjects/NoTarget.cmake create mode 100644 Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt create mode 100644 Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt create mode 100644 Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake create mode 100644 Tests/RunCMake/TargetObjects/empty.cpp 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 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: \$ - 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-result.txt b/Tests/RunCMake/TargetObjects/BadContext-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/TargetObjects/BadContext-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 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: - - \$ - - 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: - - \$ - - 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: - - \$ - - 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.cmake b/Tests/RunCMake/TargetObjects/BadContext.cmake deleted file mode 100644 index 5d7e33e..0000000 --- a/Tests/RunCMake/TargetObjects/BadContext.cmake +++ /dev/null @@ -1,7 +0,0 @@ -add_library(iface INTERFACE) -target_sources(iface INTERFACE $) - -file(GENERATE OUTPUT test_output CONTENT $) -file(GENERATE OUTPUT test_output2 CONTENT $) - -install(FILES $ DESTINATION objects) diff --git a/Tests/RunCMake/TargetObjects/NoTarget-result.txt b/Tests/RunCMake/TargetObjects/NoTarget-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetObjects/NoTarget-result.txt @@ -0,0 +1 @@ +1 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: + + \$ + + 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: + + \$ + + 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: + + \$ + + Objects of target "NoTarget" referenced but no such target exists. diff --git a/Tests/RunCMake/TargetObjects/NoTarget.cmake b/Tests/RunCMake/TargetObjects/NoTarget.cmake new file mode 100644 index 0000000..5d7e33e --- /dev/null +++ b/Tests/RunCMake/TargetObjects/NoTarget.cmake @@ -0,0 +1,7 @@ +add_library(iface INTERFACE) +target_sources(iface INTERFACE $) + +file(GENERATE OUTPUT test_output CONTENT $) +file(GENERATE OUTPUT test_output2 CONTENT $) + +install(FILES $ DESTINATION objects) 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: + + \$ + + 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 $) 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; +} -- cgit v0.12