summaryrefslogtreecommitdiffstats
path: root/Source/cmAddExecutableCommand.cxx
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2013-11-05 16:32:30 (GMT)
committerStephen Kelly <steveire@gmail.com>2013-11-07 10:06:39 (GMT)
commit05f5fde0eb83c0e49aab3214f28a098861aa3313 (patch)
treebf2a838e3b1489805abed701703df62224572702 /Source/cmAddExecutableCommand.cxx
parent18985f6c2926725b08f5941205fe21c344c4b3ea (diff)
downloadCMake-05f5fde0eb83c0e49aab3214f28a098861aa3313.zip
CMake-05f5fde0eb83c0e49aab3214f28a098861aa3313.tar.gz
CMake-05f5fde0eb83c0e49aab3214f28a098861aa3313.tar.bz2
Disallow invalid target names (#13140)
Exclude Borland and NMake from the CMP0037 test. They do not accept the colon in a target name.
Diffstat (limited to 'Source/cmAddExecutableCommand.cxx')
-rw-r--r--Source/cmAddExecutableCommand.cxx38
1 files changed, 38 insertions, 0 deletions
diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx
index 5785259..a93e834 100644
--- a/Source/cmAddExecutableCommand.cxx
+++ b/Source/cmAddExecutableCommand.cxx
@@ -69,6 +69,44 @@ bool cmAddExecutableCommand
}
}
+ bool nameOk = cmGeneratorExpression::IsValidTargetName(exename);
+ if (nameOk && !importTarget && !isAlias)
+ {
+ nameOk = exename.find(":") == std::string::npos;
+ }
+ if (!nameOk)
+ {
+ cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ bool issueMessage = false;
+ switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0037))
+ {
+ case cmPolicies::WARN:
+ issueMessage = true;
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::NEW:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ issueMessage = true;
+ messageType = cmake::FATAL_ERROR;
+ }
+ if (issueMessage)
+ {
+ cmOStringStream e;
+ e << (this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0037)) << "\n";
+ e << "The target name \"" << exename << "\" is not valid for certain "
+ "CMake features, such as generator expressions, and may result "
+ "in undefined behavior.";
+ this->Makefile->IssueMessage(messageType, e.str().c_str());
+
+ if (messageType == cmake::FATAL_ERROR)
+ {
+ return false;
+ }
+ }
+ }
+
// Special modifiers are not allowed with IMPORTED signature.
if(importTarget
&& (use_win32 || use_macbundle || excludeFromAll))