From ff015ee11e66388f50f9a1350e2731e7a240ccb1 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 14 Jun 2013 16:25:29 +0200 Subject: [PATCH] Genex: Report error if a target file is needed to evaluate link libraries. Constructs such as target_link_libraries(foo $<$,foo.so>:bar>) segfault before this patch. --- Source/cmGeneratorExpressionEvaluator.cxx | 9 ++++++++- Tests/RunCMake/Languages/RunCMakeTest.cmake | 2 ++ .../link-libraries-TARGET_FILE-genex-ok-result.txt | 1 + .../Languages/link-libraries-TARGET_FILE-genex-ok.cmake | 6 ++++++ .../link-libraries-TARGET_FILE-genex-result.txt | 1 + .../link-libraries-TARGET_FILE-genex-stderr.txt | 7 +++++++ .../Languages/link-libraries-TARGET_FILE-genex.cmake | 4 ++++ 7 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok-result.txt create mode 100644 Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok.cmake create mode 100644 Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-result.txt create mode 100644 Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-stderr.txt create mode 100644 Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex.cmake diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index cd0d26b33..f57e683c2 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -1100,7 +1100,7 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode std::string Evaluate(const std::vector ¶meters, cmGeneratorExpressionContext *context, const GeneratorExpressionContent *content, - cmGeneratorExpressionDAGChecker *) const + cmGeneratorExpressionDAGChecker *dagChecker) const { // Lookup the referenced target. std::string name = *parameters.begin(); @@ -1125,6 +1125,13 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode "Target \"" + name + "\" is not an executable or library."); return std::string(); } + if (dagChecker && dagChecker->EvaluatingLinkLibraries(name.c_str())) + { + ::reportError(context, content->GetOriginalExpression(), + "Expressions which require the linker language may not " + "be used while evaluating link libraries"); + return std::string(); + } context->DependTargets.insert(target); context->AllTargets.insert(target); diff --git a/Tests/RunCMake/Languages/RunCMakeTest.cmake b/Tests/RunCMake/Languages/RunCMakeTest.cmake index 59ef5dc09..6517a8105 100644 --- a/Tests/RunCMake/Languages/RunCMakeTest.cmake +++ b/Tests/RunCMake/Languages/RunCMakeTest.cmake @@ -2,3 +2,5 @@ include(RunCMake) run_cmake(NoLangSHARED) run_cmake(LINK_LANGUAGE-genex) +run_cmake(link-libraries-TARGET_FILE-genex) +run_cmake(link-libraries-TARGET_FILE-genex-ok) diff --git a/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok-result.txt b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok-result.txt new file mode 100644 index 000000000..573541ac9 --- /dev/null +++ b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok.cmake b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok.cmake new file mode 100644 index 000000000..f0fd6e5aa --- /dev/null +++ b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok.cmake @@ -0,0 +1,6 @@ + +enable_language(CXX) + +add_library(foo SHARED empty.cpp) +add_library(bar SHARED empty.cpp) +target_link_libraries(foo $<$,anything>:bar>) diff --git a/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-result.txt b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-stderr.txt b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-stderr.txt new file mode 100644 index 000000000..2d7a3c9d6 --- /dev/null +++ b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex-stderr.txt @@ -0,0 +1,7 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + Expressions which require the linker language may not be used while + evaluating link libraries diff --git a/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex.cmake b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex.cmake new file mode 100644 index 000000000..eca73e977 --- /dev/null +++ b/Tests/RunCMake/Languages/link-libraries-TARGET_FILE-genex.cmake @@ -0,0 +1,4 @@ + +add_library(foo SHARED empty.cpp) +add_library(bar SHARED empty.cpp) +target_link_libraries(foo $<$,anything>:bar>)