CMP0037: De-duplicate check and message generation
This commit is contained in:
parent
a2611d816b
commit
409527a03c
@ -8,7 +8,7 @@
|
|||||||
#include "cmGeneratorExpression.h"
|
#include "cmGeneratorExpression.h"
|
||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
#include "cmPolicies.h"
|
#include "cmStateTypes.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
#include "cmTarget.h"
|
#include "cmTarget.h"
|
||||||
#include "cmake.h"
|
#include "cmake.h"
|
||||||
@ -160,35 +160,9 @@ bool cmAddCustomTargetCommand::InitialPass(
|
|||||||
if (nameOk) {
|
if (nameOk) {
|
||||||
nameOk = targetName.find(':') == std::string::npos;
|
nameOk = targetName.find(':') == std::string::npos;
|
||||||
}
|
}
|
||||||
if (!nameOk) {
|
if (!nameOk &&
|
||||||
cmake::MessageType messageType = cmake::AUTHOR_WARNING;
|
!this->Makefile->CheckCMP0037(targetName, cmStateEnums::UTILITY)) {
|
||||||
std::ostringstream e;
|
return false;
|
||||||
bool issueMessage = false;
|
|
||||||
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0037)) {
|
|
||||||
case cmPolicies::WARN:
|
|
||||||
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0037) << "\n";
|
|
||||||
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) {
|
|
||||||
/* clang-format off */
|
|
||||||
e << "The target name \"" << targetName <<
|
|
||||||
"\" is reserved or not valid for certain "
|
|
||||||
"CMake features, such as generator expressions, and may result "
|
|
||||||
"in undefined behavior.";
|
|
||||||
/* clang-format on */
|
|
||||||
this->Makefile->IssueMessage(messageType, e.str());
|
|
||||||
|
|
||||||
if (messageType == cmake::FATAL_ERROR) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the last command line finished.
|
// Store the last command line finished.
|
||||||
|
@ -7,10 +7,8 @@
|
|||||||
#include "cmGeneratorExpression.h"
|
#include "cmGeneratorExpression.h"
|
||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
#include "cmPolicies.h"
|
|
||||||
#include "cmStateTypes.h"
|
#include "cmStateTypes.h"
|
||||||
#include "cmTarget.h"
|
#include "cmTarget.h"
|
||||||
#include "cmake.h"
|
|
||||||
|
|
||||||
class cmExecutionStatus;
|
class cmExecutionStatus;
|
||||||
|
|
||||||
@ -63,35 +61,9 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args,
|
|||||||
if (nameOk && !importTarget && !isAlias) {
|
if (nameOk && !importTarget && !isAlias) {
|
||||||
nameOk = exename.find(':') == std::string::npos;
|
nameOk = exename.find(':') == std::string::npos;
|
||||||
}
|
}
|
||||||
if (!nameOk) {
|
if (!nameOk &&
|
||||||
cmake::MessageType messageType = cmake::AUTHOR_WARNING;
|
!this->Makefile->CheckCMP0037(exename, cmStateEnums::EXECUTABLE)) {
|
||||||
std::ostringstream e;
|
return false;
|
||||||
bool issueMessage = false;
|
|
||||||
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0037)) {
|
|
||||||
case cmPolicies::WARN:
|
|
||||||
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0037) << "\n";
|
|
||||||
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) {
|
|
||||||
/* clang-format off */
|
|
||||||
e << "The target name \"" << exename <<
|
|
||||||
"\" is reserved or not valid for certain "
|
|
||||||
"CMake features, such as generator expressions, and may result "
|
|
||||||
"in undefined behavior.";
|
|
||||||
/* clang-format on */
|
|
||||||
this->Makefile->IssueMessage(messageType, e.str());
|
|
||||||
|
|
||||||
if (messageType == cmake::FATAL_ERROR) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special modifiers are not allowed with IMPORTED signature.
|
// Special modifiers are not allowed with IMPORTED signature.
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include "cmGeneratorExpression.h"
|
#include "cmGeneratorExpression.h"
|
||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
#include "cmPolicies.h"
|
|
||||||
#include "cmState.h"
|
#include "cmState.h"
|
||||||
#include "cmStateTypes.h"
|
#include "cmStateTypes.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
@ -175,35 +174,8 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args,
|
|||||||
if (nameOk && !importTarget && !isAlias) {
|
if (nameOk && !importTarget && !isAlias) {
|
||||||
nameOk = libName.find(':') == std::string::npos;
|
nameOk = libName.find(':') == std::string::npos;
|
||||||
}
|
}
|
||||||
if (!nameOk) {
|
if (!nameOk && !this->Makefile->CheckCMP0037(libName, type)) {
|
||||||
cmake::MessageType messageType = cmake::AUTHOR_WARNING;
|
return false;
|
||||||
std::ostringstream e;
|
|
||||||
bool issueMessage = false;
|
|
||||||
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0037)) {
|
|
||||||
case cmPolicies::WARN:
|
|
||||||
if (type != cmStateEnums::INTERFACE_LIBRARY) {
|
|
||||||
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0037) << "\n";
|
|
||||||
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) {
|
|
||||||
e << "The target name \"" << libName
|
|
||||||
<< "\" is reserved or not valid for certain "
|
|
||||||
"CMake features, such as generator expressions, and may result "
|
|
||||||
"in undefined behavior.";
|
|
||||||
this->Makefile->IssueMessage(messageType, e.str());
|
|
||||||
|
|
||||||
if (messageType == cmake::FATAL_ERROR) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAlias) {
|
if (isAlias) {
|
||||||
|
@ -123,6 +123,42 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
|
|||||||
this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace());
|
this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cmMakefile::CheckCMP0037(std::string const& targetName,
|
||||||
|
cmStateEnums::TargetType targetType) const
|
||||||
|
{
|
||||||
|
cmake::MessageType messageType = cmake::AUTHOR_WARNING;
|
||||||
|
std::ostringstream e;
|
||||||
|
bool issueMessage = false;
|
||||||
|
switch (this->GetPolicyStatus(cmPolicies::CMP0037)) {
|
||||||
|
case cmPolicies::WARN:
|
||||||
|
if (targetType != cmStateEnums::INTERFACE_LIBRARY) {
|
||||||
|
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0037) << "\n";
|
||||||
|
issueMessage = true;
|
||||||
|
}
|
||||||
|
CM_FALLTHROUGH;
|
||||||
|
case cmPolicies::OLD:
|
||||||
|
break;
|
||||||
|
case cmPolicies::NEW:
|
||||||
|
case cmPolicies::REQUIRED_IF_USED:
|
||||||
|
case cmPolicies::REQUIRED_ALWAYS:
|
||||||
|
issueMessage = true;
|
||||||
|
messageType = cmake::FATAL_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (issueMessage) {
|
||||||
|
e << "The target name \"" << targetName
|
||||||
|
<< "\" is reserved or not valid for certain "
|
||||||
|
"CMake features, such as generator expressions, and may result "
|
||||||
|
"in undefined behavior.";
|
||||||
|
this->IssueMessage(messageType, e.str());
|
||||||
|
|
||||||
|
if (messageType == cmake::FATAL_ERROR) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
cmStringRange cmMakefile::GetIncludeDirectoriesEntries() const
|
cmStringRange cmMakefile::GetIncludeDirectoriesEntries() const
|
||||||
{
|
{
|
||||||
return this->StateSnapshot.GetDirectory().GetIncludeDirectoriesEntries();
|
return this->StateSnapshot.GetDirectory().GetIncludeDirectoriesEntries();
|
||||||
|
@ -741,6 +741,9 @@ public:
|
|||||||
/** Set whether or not to report a CMP0000 violation. */
|
/** Set whether or not to report a CMP0000 violation. */
|
||||||
void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }
|
void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }
|
||||||
|
|
||||||
|
bool CheckCMP0037(std::string const& targetName,
|
||||||
|
cmStateEnums::TargetType targetType) const;
|
||||||
|
|
||||||
cmStringRange GetIncludeDirectoriesEntries() const;
|
cmStringRange GetIncludeDirectoriesEntries() const;
|
||||||
cmBacktraceRange GetIncludeDirectoriesBacktraces() const;
|
cmBacktraceRange GetIncludeDirectoriesBacktraces() const;
|
||||||
cmStringRange GetCompileOptionsEntries() const;
|
cmStringRange GetCompileOptionsEntries() const;
|
||||||
|
Loading…
Reference in New Issue
Block a user