From 0e1cb07e841c5ca9207bc4e32ff0672476226cc0 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 14 Jun 2013 15:45:12 +0200 Subject: Add missing return after error report. --- Source/cmGeneratorExpressionEvaluator.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index 701c547..3e18bba 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -429,6 +429,7 @@ static const struct LinkLanguageNode : public cmGeneratorExpressionNode reportError(context, content->GetOriginalExpression(), "$ may only be used with targets. It may not " "be used with add_custom_command."); + return std::string(); } const char *lang = target->GetLinkerLanguage(context->Config); -- cgit v0.12 From b1c19ce3837036bde3b639f8285fa228b8e6f278 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 14 Jun 2013 15:59:23 +0200 Subject: Genex: Make LINK_LANGUAGE report an error when evaluating link libraries. --- Source/cmGeneratorExpressionEvaluator.cxx | 9 ++++++++- Tests/RunCMake/Languages/LINK_LANGUAGE-genex-result.txt | 1 + Tests/RunCMake/Languages/LINK_LANGUAGE-genex-stderr.txt | 6 ++++++ Tests/RunCMake/Languages/LINK_LANGUAGE-genex.cmake | 4 ++++ Tests/RunCMake/Languages/RunCMakeTest.cmake | 1 + Tests/RunCMake/Languages/empty.cpp | 7 +++++++ 6 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/Languages/LINK_LANGUAGE-genex-result.txt create mode 100644 Tests/RunCMake/Languages/LINK_LANGUAGE-genex-stderr.txt create mode 100644 Tests/RunCMake/Languages/LINK_LANGUAGE-genex.cmake create mode 100644 Tests/RunCMake/Languages/empty.cpp diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index 3e18bba..cd0d26b 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -415,8 +415,15 @@ static const struct LinkLanguageNode : public cmGeneratorExpressionNode std::string Evaluate(const std::vector ¶meters, cmGeneratorExpressionContext *context, const GeneratorExpressionContent *content, - cmGeneratorExpressionDAGChecker *) const + cmGeneratorExpressionDAGChecker *dagChecker) const { + if (dagChecker && dagChecker->EvaluatingLinkLibraries()) + { + reportError(context, content->GetOriginalExpression(), + "$ expression can not be used while evaluating " + "link libraries"); + return std::string(); + } if (parameters.size() != 0 && parameters.size() != 1) { reportError(context, content->GetOriginalExpression(), diff --git a/Tests/RunCMake/Languages/LINK_LANGUAGE-genex-result.txt b/Tests/RunCMake/Languages/LINK_LANGUAGE-genex-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/Languages/LINK_LANGUAGE-genex-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Languages/LINK_LANGUAGE-genex-stderr.txt b/Tests/RunCMake/Languages/LINK_LANGUAGE-genex-stderr.txt new file mode 100644 index 0000000..8e0591d --- /dev/null +++ b/Tests/RunCMake/Languages/LINK_LANGUAGE-genex-stderr.txt @@ -0,0 +1,6 @@ +CMake Error: + Error evaluating generator expression: + + \$ + + \$ expression can not be used while evaluating link libraries diff --git a/Tests/RunCMake/Languages/LINK_LANGUAGE-genex.cmake b/Tests/RunCMake/Languages/LINK_LANGUAGE-genex.cmake new file mode 100644 index 0000000..e0f8c57 --- /dev/null +++ b/Tests/RunCMake/Languages/LINK_LANGUAGE-genex.cmake @@ -0,0 +1,4 @@ + +add_library(foo SHARED empty.cpp) +add_library(bar SHARED empty.cpp) +target_link_libraries(foo $<$,anything>:bar>) diff --git a/Tests/RunCMake/Languages/RunCMakeTest.cmake b/Tests/RunCMake/Languages/RunCMakeTest.cmake index a99548f..59ef5dc 100644 --- a/Tests/RunCMake/Languages/RunCMakeTest.cmake +++ b/Tests/RunCMake/Languages/RunCMakeTest.cmake @@ -1,3 +1,4 @@ include(RunCMake) run_cmake(NoLangSHARED) +run_cmake(LINK_LANGUAGE-genex) diff --git a/Tests/RunCMake/Languages/empty.cpp b/Tests/RunCMake/Languages/empty.cpp new file mode 100644 index 0000000..7279c5e --- /dev/null +++ b/Tests/RunCMake/Languages/empty.cpp @@ -0,0 +1,7 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif +int empty(void) +{ + return 0; +} -- cgit v0.12 From b58aff90c5a3633ae7fa0d78731433d40a02d8bd Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 14 Jun 2013 15:58:04 +0200 Subject: Genex: Extend EvaluatingLinkLibraries to also check the top target name. This will allow testing whether we are evaluating the link libraries of a particular target. --- Source/cmGeneratorExpressionDAGChecker.cxx | 8 +++++++- Source/cmGeneratorExpressionDAGChecker.h | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx index 3e03c09..5b79e35 100644 --- a/Source/cmGeneratorExpressionDAGChecker.cxx +++ b/Source/cmGeneratorExpressionDAGChecker.cxx @@ -139,7 +139,7 @@ cmGeneratorExpressionDAGChecker::checkGraph() const } //---------------------------------------------------------------------------- -bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries() +bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries(const char *tgt) { const cmGeneratorExpressionDAGChecker *top = this; const cmGeneratorExpressionDAGChecker *parent = this->Parent; @@ -150,6 +150,12 @@ bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries() } const char *prop = top->Property.c_str(); + + if (tgt) + { + return top->Target == tgt && strcmp(prop, "LINK_LIBRARIES") == 0; + } + return (strcmp(prop, "LINK_LIBRARIES") == 0 || strcmp(prop, "LINK_INTERFACE_LIBRARIES") == 0 || strcmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES") == 0 diff --git a/Source/cmGeneratorExpressionDAGChecker.h b/Source/cmGeneratorExpressionDAGChecker.h index 85b13e5..95d466a 100644 --- a/Source/cmGeneratorExpressionDAGChecker.h +++ b/Source/cmGeneratorExpressionDAGChecker.h @@ -47,7 +47,7 @@ struct cmGeneratorExpressionDAGChecker void reportError(cmGeneratorExpressionContext *context, const std::string &expr); - bool EvaluatingLinkLibraries(); + bool EvaluatingLinkLibraries(const char *tgt = 0); #define DECLARE_TRANSITIVE_PROPERTY_METHOD(METHOD) \ bool METHOD () const; -- cgit v0.12 From ff015ee11e66388f50f9a1350e2731e7a240ccb1 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 14 Jun 2013 16:25:29 +0200 Subject: 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 ++ .../Languages/link-libraries-TARGET_FILE-genex-ok-result.txt | 1 + .../RunCMake/Languages/link-libraries-TARGET_FILE-genex-ok.cmake | 6 ++++++ .../Languages/link-libraries-TARGET_FILE-genex-result.txt | 1 + .../Languages/link-libraries-TARGET_FILE-genex-stderr.txt | 7 +++++++ Tests/RunCMake/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 cd0d26b..f57e683 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 59ef5dc..6517a81 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 0000000..573541a --- /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 0000000..f0fd6e5 --- /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 0000000..d00491f --- /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 0000000..2d7a3c9 --- /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 0000000..eca73e9 --- /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>) -- cgit v0.12