summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/cmPolicies.cxx5
-rw-r--r--Source/cmPolicies.h1
-rw-r--r--Source/cmTarget.cxx45
3 files changed, 44 insertions, 7 deletions
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index db23f1ecd2..af33d0b397 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -291,6 +291,11 @@ cmPolicies::cmPolicies()
CMP0037, "CMP0037",
"Target names should match a validity pattern.",
3,0,0,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0038, "CMP0038",
+ "Targets may not link directly to themselves.",
+ 3,0,0,0, cmPolicies::WARN);
}
cmPolicies::~cmPolicies()
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 821c58d841..2ea997301b 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -89,6 +89,7 @@ public:
CMP0035, ///< Disallow command: variable_requires
CMP0036, ///< Disallow command: build_name
CMP0037, ///< Target names should match a validity pattern.
+ CMP0038, ///< Targets may not link directly to themselves
/** \brief Always the last entry.
*
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index d0390f747d..d5e8420639 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);
}