diff options
author | Stephen Kelly <steveire@gmail.com> | 2013-11-05 16:32:30 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2013-11-07 10:06:39 (GMT) |
commit | 05f5fde0eb83c0e49aab3214f28a098861aa3313 (patch) | |
tree | bf2a838e3b1489805abed701703df62224572702 /Source/cmAddLibraryCommand.cxx | |
parent | 18985f6c2926725b08f5941205fe21c344c4b3ea (diff) | |
download | CMake-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/cmAddLibraryCommand.cxx')
-rw-r--r-- | Source/cmAddLibraryCommand.cxx | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx index 0e61c99..4c591b6 100644 --- a/Source/cmAddLibraryCommand.cxx +++ b/Source/cmAddLibraryCommand.cxx @@ -108,6 +108,45 @@ bool cmAddLibraryCommand break; } } + + bool nameOk = cmGeneratorExpression::IsValidTargetName(libName); + if (nameOk && !importTarget && !isAlias) + { + nameOk = libName.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 = type != cmTarget::INTERFACE_LIBRARY; + 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 \"" << libName << "\" 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; + } + } + } + if (isAlias) { if(!cmGeneratorExpression::IsValidTargetName(libName.c_str())) |