Commit ff015ee1 authored by Stephen Kelly's avatar Stephen Kelly
Browse files

Genex: Report error if a target file is needed to evaluate link libraries.

Constructs such as

 target_link_libraries(foo $<$<STREQUAL:$<TARGET_FILE:foo>,foo.so>:bar>)

segfault before this patch.
parent b58aff90
......@@ -1100,7 +1100,7 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
std::string Evaluate(const std::vector<std::string> &parameters,
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);
......
......@@ -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)
enable_language(CXX)
add_library(foo SHARED empty.cpp)
add_library(bar SHARED empty.cpp)
target_link_libraries(foo $<$<STREQUAL:$<TARGET_FILE:bar>,anything>:bar>)
CMake Error:
Error evaluating generator expression:
\$<TARGET_FILE:foo>
Expressions which require the linker language may not be used while
evaluating link libraries
add_library(foo SHARED empty.cpp)
add_library(bar SHARED empty.cpp)
target_link_libraries(foo $<$<STREQUAL:$<TARGET_FILE:foo>,anything>:bar>)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment