cmGlobalGenerator: factor out messaging for CMP0037

Also make some strings into character literals.
This commit is contained in:
Ben Boeckel 2023-09-24 19:13:32 -04:00
parent 34b393f97f
commit 7a4c02cb38

View File

@ -2690,13 +2690,9 @@ cmGlobalGenerator::SplitFrameworkPath(const std::string& path,
return cm::nullopt; return cm::nullopt;
} }
bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName, static bool RaiseCMP0037Message(cmake* cm, cmTarget* tgt,
std::string const& reason) const std::string const& reason)
{ {
cmTarget* tgt = this->FindTarget(targetName);
if (!tgt) {
return true;
}
MessageType messageType = MessageType::AUTHOR_WARNING; MessageType messageType = MessageType::AUTHOR_WARNING;
std::ostringstream e; std::ostringstream e;
bool issueMessage = false; bool issueMessage = false;
@ -2715,13 +2711,12 @@ bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName,
break; break;
} }
if (issueMessage) { if (issueMessage) {
e << "The target name \"" << targetName << "\" is reserved " << reason e << "The target name \"" << tgt->GetName() << "\" is reserved " << reason
<< "."; << ".";
if (messageType == MessageType::AUTHOR_WARNING) { if (messageType == MessageType::AUTHOR_WARNING) {
e << " It may result in undefined behavior."; e << " It may result in undefined behavior.";
} }
this->GetCMakeInstance()->IssueMessage(messageType, e.str(), cm->IssueMessage(messageType, e.str(), tgt->GetBacktrace());
tgt->GetBacktrace());
if (messageType == MessageType::FATAL_ERROR) { if (messageType == MessageType::FATAL_ERROR) {
return false; return false;
} }
@ -2729,6 +2724,16 @@ bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName,
return true; return true;
} }
bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName,
std::string const& reason) const
{
cmTarget* tgt = this->FindTarget(targetName);
if (!tgt) {
return true;
}
return RaiseCMP0037Message(this->GetCMakeInstance(), tgt, reason);
}
void cmGlobalGenerator::CreateDefaultGlobalTargets( void cmGlobalGenerator::CreateDefaultGlobalTargets(
std::vector<GlobalTargetInfo>& targets) std::vector<GlobalTargetInfo>& targets)
{ {