Merge topic 'MakeTargetLinkLibrariesComplainWhenNoTargetIsUsed'

6acc71c New CMP0016 for deciding whether an unknown target in TLL() is an error.
da033b1 Remove trailing whitespace
6aef6d8 Just warn in case of a bad target as only argument for t_l_l()
c786635 Make target_link_libraries() complain if bad target name is used
43f96ea Remove trailing whitespace
This commit is contained in:
Brad King 2010-08-31 14:48:26 -04:00 committed by CMake Topic Stage
commit 28e073213f
3 changed files with 88 additions and 37 deletions

View File

@ -426,7 +426,7 @@ cmPolicies::cmPolicies()
this->DefinePolicy(
CMP0015, "CMP0015",
"link_directories() treats paths relative to the source dir.",
"In CMake 2.6.4 and lower the link_directories() command passed relative "
"In CMake 2.8.0 and lower the link_directories() command passed relative "
"paths unchanged to the linker. "
"In CMake 2.8.1 and above the link_directories() command prefers to "
"interpret relative paths with respect to CMAKE_CURRENT_SOURCE_DIR, "
@ -437,6 +437,15 @@ cmPolicies::cmPolicies()
"absolute paths by appending the relative path to "
"CMAKE_CURRENT_SOURCE_DIR.",
2,8,1,0, cmPolicies::WARN);
this->DefinePolicy(
CMP0016, "CMP0016",
"target_link_libraries() reports error if only argument is not a target.",
"In CMake 2.8.2 and lower the target_link_libraries() command silently "
"ignored if it was called with only one argument, and this argument "
"wasn't a valid target. "
"In CMake 2.8.3 and above it reports an error in this case.",
2,8,3,0, cmPolicies::WARN);
}
cmPolicies::~cmPolicies()

View File

@ -51,6 +51,7 @@ public:
CMP0013, // Duplicate binary directories not allowed
CMP0014, // Input directories must have CMakeLists.txt
CMP0015, // link_directories() treats paths relative to source dir
CMP0016, // target_link_libraries() fails if only argument is not a target
// Always the last entry. Useful mostly to avoid adding a comma
// the last policy when adding a new one.

View File

@ -29,23 +29,64 @@ bool cmTargetLinkLibrariesCommand
return false;
}
// but we might not have any libs after variable expansion
if(args.size() < 2)
{
return true;
}
// Lookup the target for which libraries are specified.
this->Target =
this->Makefile->GetCMakeInstance()
->GetGlobalGenerator()->FindTarget(0, args[0].c_str());
if(!this->Target)
{
cmake::MessageType t = cmake::FATAL_ERROR; // fail by default
cmOStringStream e;
e << "Cannot specify link libraries for target \"" << args[0] << "\" "
<< "which is not built by this project.";
// The bad target is the only argument. Check how policy CMP0016 is set,
// and accept, warn or fail respectively:
if (args.size() < 2)
{
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0016))
{
case cmPolicies::WARN:
t = cmake::AUTHOR_WARNING;
// Print the warning.
e << "\n"
<< "CMake does not support this but it used to work accidentally "
<< "and is being allowed for compatibility."
<< "\n" << this->Makefile->GetPolicies()->
GetPolicyWarning(cmPolicies::CMP0016);
break;
case cmPolicies::OLD: // OLD behavior does not warn.
t = cmake::MESSAGE;
break;
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
e << "\n" << this->Makefile->GetPolicies()->
GetRequiredPolicyError(cmPolicies::CMP0016);
break;
case cmPolicies::NEW: // NEW behavior prints the error.
default:
break;
}
}
// now actually print the message
switch(t)
{
case cmake::AUTHOR_WARNING:
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
break;
case cmake::FATAL_ERROR:
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
cmSystemTools::SetFatalErrorOccured();
break;
default:
break;
}
return true;
}
// but we might not have any libs after variable expansion
if(args.size() < 2)
{
return true;
}