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.
This commit is contained in:
Stephen Kelly 2013-06-14 16:25:29 +02:00
parent b58aff90c5
commit ff015ee11e
7 changed files with 29 additions and 1 deletions

View File

@ -1100,7 +1100,7 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
std::string Evaluate(const std::vector<std::string> &parameters, std::string Evaluate(const std::vector<std::string> &parameters,
cmGeneratorExpressionContext *context, cmGeneratorExpressionContext *context,
const GeneratorExpressionContent *content, const GeneratorExpressionContent *content,
cmGeneratorExpressionDAGChecker *) const cmGeneratorExpressionDAGChecker *dagChecker) const
{ {
// Lookup the referenced target. // Lookup the referenced target.
std::string name = *parameters.begin(); std::string name = *parameters.begin();
@ -1125,6 +1125,13 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
"Target \"" + name + "\" is not an executable or library."); "Target \"" + name + "\" is not an executable or library.");
return std::string(); 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->DependTargets.insert(target);
context->AllTargets.insert(target); context->AllTargets.insert(target);

View File

@ -2,3 +2,5 @@ include(RunCMake)
run_cmake(NoLangSHARED) run_cmake(NoLangSHARED)
run_cmake(LINK_LANGUAGE-genex) run_cmake(LINK_LANGUAGE-genex)
run_cmake(link-libraries-TARGET_FILE-genex)
run_cmake(link-libraries-TARGET_FILE-genex-ok)

View File

@ -0,0 +1,6 @@
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>)

View File

@ -0,0 +1,7 @@
CMake Error:
Error evaluating generator expression:
\$<TARGET_FILE:foo>
Expressions which require the linker language may not be used while
evaluating link libraries

View File

@ -0,0 +1,4 @@
add_library(foo SHARED empty.cpp)
add_library(bar SHARED empty.cpp)
target_link_libraries(foo $<$<STREQUAL:$<TARGET_FILE:foo>,anything>:bar>)