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 | |
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')
-rw-r--r-- | Source/cmAddExecutableCommand.cxx | 38 | ||||
-rw-r--r-- | Source/cmAddLibraryCommand.cxx | 39 | ||||
-rw-r--r-- | Source/cmPolicies.cxx | 5 | ||||
-rw-r--r-- | Source/cmPolicies.h | 1 |
4 files changed, 83 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)) 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())) diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index ab822d3..db23f1e 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -286,6 +286,11 @@ cmPolicies::cmPolicies() CMP0036, "CMP0036", "The build_name command should not be called.", 3,0,0,0, cmPolicies::WARN); + + this->DefinePolicy( + CMP0037, "CMP0037", + "Target names should match a validity pattern.", + 3,0,0,0, cmPolicies::WARN); } cmPolicies::~cmPolicies() diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 9e72bdc..821c58d 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -88,6 +88,7 @@ public: CMP0034, ///< Disallow command: utility_source CMP0035, ///< Disallow command: variable_requires CMP0036, ///< Disallow command: build_name + CMP0037, ///< Target names should match a validity pattern. /** \brief Always the last entry. * |