Merge topic 'dag-LINKER_LANGUAGE'

ff015ee Genex: Report error if a target file is needed to evaluate link libraries.
b58aff9 Genex: Extend EvaluatingLinkLibraries to also check the top target name.
b1c19ce Genex: Make LINK_LANGUAGE report an error when evaluating link libraries.
0e1cb07 Add missing return after error report.
This commit is contained in:
Brad King 2013-06-26 09:03:05 -04:00 committed by CMake Topic Stage
commit bef7c0251e
13 changed files with 65 additions and 4 deletions

View File

@ -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

View File

@ -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;

View File

@ -469,8 +469,15 @@ static const struct LinkLanguageNode : public cmGeneratorExpressionNode
std::string Evaluate(const std::vector<std::string> &parameters,
cmGeneratorExpressionContext *context,
const GeneratorExpressionContent *content,
cmGeneratorExpressionDAGChecker *) const
cmGeneratorExpressionDAGChecker *dagChecker) const
{
if (dagChecker && dagChecker->EvaluatingLinkLibraries())
{
reportError(context, content->GetOriginalExpression(),
"$<LINK_LANGUAGE> expression can not be used while evaluating "
"link libraries");
return std::string();
}
if (parameters.size() != 0 && parameters.size() != 1)
{
reportError(context, content->GetOriginalExpression(),
@ -483,6 +490,7 @@ static const struct LinkLanguageNode : public cmGeneratorExpressionNode
reportError(context, content->GetOriginalExpression(),
"$<LINK_LANGUAGE> 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);
@ -1146,7 +1154,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();
@ -1171,6 +1179,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);

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,6 @@
CMake Error:
Error evaluating generator expression:
\$<LINK_LANGUAGE>
\$<LINK_LANGUAGE> expression can 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:$<LINK_LANGUAGE>,anything>:bar>)

View File

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

View File

@ -0,0 +1,7 @@
#ifdef _WIN32
__declspec(dllexport)
#endif
int empty(void)
{
return 0;
}

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>)