summaryrefslogtreecommitdiffstats
path: root/Source/cmTarget.cxx
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2013-11-05 17:01:09 (GMT)
committerStephen Kelly <steveire@gmail.com>2013-11-07 10:06:39 (GMT)
commit301bb5cdda081f0bef0702e41ae4b47102b235df (patch)
tree2ee1e6000296f3db1358d70145daeafc36139e08 /Source/cmTarget.cxx
parent05f5fde0eb83c0e49aab3214f28a098861aa3313 (diff)
downloadCMake-301bb5cdda081f0bef0702e41ae4b47102b235df.zip
CMake-301bb5cdda081f0bef0702e41ae4b47102b235df.tar.gz
CMake-301bb5cdda081f0bef0702e41ae4b47102b235df.tar.bz2
Disallow link-to-self (#13947).
Diffstat (limited to 'Source/cmTarget.cxx')
-rw-r--r--Source/cmTarget.cxx45
1 files changed, 38 insertions, 7 deletions
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index d0390f7..d5e8420 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -932,12 +932,6 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf,
const char *target, const char* lib,
LinkLibraryType llt)
{
- // Never add a self dependency, even if the user asks for it.
- if(strcmp( target, lib ) == 0)
- {
- return;
- }
-
cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
{
const bool isNonImportedTarget = tgt && !tgt->IsImported();
@@ -951,7 +945,8 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf,
}
if (cmGeneratorExpression::Find(lib) != std::string::npos
- || (tgt && tgt->GetType() == INTERFACE_LIBRARY))
+ || (tgt && tgt->GetType() == INTERFACE_LIBRARY)
+ || (strcmp( target, lib ) == 0))
{
return;
}
@@ -5293,6 +5288,41 @@ void cmTarget::ComputeLinkImplementation(const char* config,
std::string item = this->CheckCMP0004(*li);
if(item == this->GetName() || item.empty())
{
+ if(item == this->GetName())
+ {
+ bool noMessage = false;
+ cmake::MessageType messageType = cmake::FATAL_ERROR;
+ cmOStringStream e;
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0038))
+ {
+ case cmPolicies::WARN:
+ {
+ e << (this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0038)) << "\n";
+ messageType = cmake::AUTHOR_WARNING;
+ }
+ break;
+ case cmPolicies::OLD:
+ noMessage = true;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ // Issue the fatal message.
+ break;
+ }
+
+ if(!noMessage)
+ {
+ e << "Target \"" << this->GetName() << "\" links to itself.";
+ this->Makefile->GetCMakeInstance()->IssueMessage(messageType,
+ e.str(),
+ this->GetBacktrace());
+ if (messageType == cmake::FATAL_ERROR)
+ {
+ return;
+ }
+ }
+ }
continue;
}
cmTarget *tgt = this->Makefile->FindTargetToUse(li->c_str());
@@ -5335,6 +5365,7 @@ void cmTarget::ComputeLinkImplementation(const char* config,
}
}
}
+
// The entry is meant for this configuration.
impl.Libraries.push_back(item);
}