Skip to content

Commit ca29231

Browse files
author
Sebastian Holtermann
committed
Autogen: Modernize to use cmStrCat for string concatenation
1 parent d02a99d commit ca29231

File tree

6 files changed

+151
-258
lines changed

6 files changed

+151
-258
lines changed

Source/cmQtAutoGen.cxx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,8 @@ bool cmQtAutoGen::RccLister::list(std::string const& qrcFile,
353353

354354
// Log command
355355
if (verbose) {
356-
std::string msg = "Running command:\n";
357-
msg += QuotedCommand(cmd);
358-
msg += '\n';
356+
std::string msg =
357+
cmStrCat("Running command:\n", QuotedCommand(cmd), '\n');
359358
cmSystemTools::Stdout(msg);
360359
}
361360

Source/cmQtAutoGenGlobalInitializer.cxx

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
22
file Copyright.txt or https://cmake.org/licensing for details. */
33
#include "cmQtAutoGenGlobalInitializer.h"
4-
#include "cmQtAutoGen.h"
5-
#include "cmQtAutoGenInitializer.h"
64

75
#include "cmCustomCommandLines.h"
86
#include "cmDuration.h"
@@ -11,15 +9,18 @@
119
#include "cmMakefile.h"
1210
#include "cmMessageType.h"
1311
#include "cmProcessOutput.h"
12+
#include "cmQtAutoGen.h"
13+
#include "cmQtAutoGenInitializer.h"
1414
#include "cmState.h"
1515
#include "cmStateTypes.h"
16+
#include "cmStringAlgorithms.h"
1617
#include "cmSystemTools.h"
1718
#include "cmTarget.h"
1819

19-
#include <utility>
20-
2120
#include "cm_memory.hxx"
2221

22+
#include <utility>
23+
2324
cmQtAutoGenGlobalInitializer::Keywords::Keywords()
2425
: AUTOMOC("AUTOMOC")
2526
, AUTOUIC("AUTOUIC")
@@ -119,23 +120,17 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer(
119120
bool const uicDisabled = (uic && !uicAvailable);
120121
bool const rccDisabled = (rcc && !rccAvailable);
121122
if (mocDisabled || uicDisabled || rccDisabled) {
122-
std::string msg = "AUTOGEN: No valid Qt version found for target ";
123-
msg += target->GetName();
124-
msg += ". ";
125-
msg += cmQtAutoGen::Tools(mocDisabled, uicDisabled, rccDisabled);
126-
msg += " disabled. Consider adding:\n";
127-
{
128-
std::string version = (qtVersion.second == 0)
129-
? std::string("<QTVERSION>")
130-
: std::to_string(qtVersion.second);
131-
std::string comp = uicDisabled ? "Widgets" : "Core";
132-
msg += " find_package(Qt";
133-
msg += version;
134-
msg += " COMPONENTS ";
135-
msg += comp;
136-
msg += ")\n";
137-
}
138-
msg += "to your CMakeLists.txt file.";
123+
cmAlphaNum version = (qtVersion.second == 0)
124+
? cmAlphaNum("<QTVERSION>")
125+
: cmAlphaNum(qtVersion.second);
126+
cmAlphaNum component = uicDisabled ? "Widgets" : "Core";
127+
128+
std::string const msg = cmStrCat(
129+
"AUTOGEN: No valid Qt version found for target ",
130+
target->GetName(), ". ",
131+
cmQtAutoGen::Tools(mocDisabled, uicDisabled, rccDisabled),
132+
" disabled. Consider adding:\n", " find_package(Qt", version,
133+
" COMPONENTS ", component, ")\n", "to your CMakeLists.txt file.");
139134
target->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, msg);
140135
}
141136
if (mocIsValid || uicIsValid || rccIsValid) {

Source/cmQtAutoGenInitializer.cxx

Lines changed: 35 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -716,14 +716,13 @@ bool cmQtAutoGenInitializer::InitScanFiles()
716716
if (muf.MocIt || muf.UicIt) {
717717
// Search for the default header file and a private header
718718
std::string const& srcPath = muf.SF->GetFullPath();
719-
std::string basePath = cmQtAutoGen::SubDirPrefix(srcPath);
720-
basePath += cmSystemTools::GetFilenameWithoutLastExtension(srcPath);
719+
std::string basePath =
720+
cmStrCat(cmQtAutoGen::SubDirPrefix(srcPath),
721+
cmSystemTools::GetFilenameWithoutLastExtension(srcPath));
721722
for (auto const& suffix : suffixes) {
722723
std::string const suffixedPath = basePath + suffix;
723724
for (auto const& ext : exts) {
724-
std::string fullPath = suffixedPath;
725-
fullPath += '.';
726-
fullPath += ext;
725+
std::string fullPath = cmStrCat(suffixedPath, '.', ext);
727726

728727
auto constexpr locationKind = cmSourceFileLocationKind::Known;
729728
cmSourceFile* sf = makefile->GetSource(fullPath, locationKind);
@@ -828,9 +827,8 @@ bool cmQtAutoGenInitializer::InitScanFiles()
828827
this->AutogenTarget.DependFiles.insert(muf->RealPath);
829828
}
830829
} else if (this->CMP0071Warn) {
831-
std::string msg;
832-
msg += cmPolicies::GetPolicyWarning(cmPolicies::CMP0071);
833-
msg += '\n';
830+
std::string msg =
831+
cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0071), '\n');
834832
std::string property;
835833
if (this->Moc.Enabled && this->Uic.Enabled) {
836834
property = kw.SKIP_AUTOGEN;
@@ -883,18 +881,10 @@ bool cmQtAutoGenInitializer::InitScanFiles()
883881
for (Qrc& qrc : this->Rcc.Qrcs) {
884882
qrc.PathChecksum = fpathCheckSum.getPart(qrc.QrcFile);
885883
// RCC output file name
884+
qrc.RccFile = cmStrCat(this->Dir.Build + "/", qrc.PathChecksum,
885+
"/qrc_", qrc.QrcName, ".cpp");
886886
{
887-
std::string rccFile = this->Dir.Build + "/";
888-
rccFile += qrc.PathChecksum;
889-
rccFile += "/qrc_";
890-
rccFile += qrc.QrcName;
891-
rccFile += ".cpp";
892-
qrc.RccFile = std::move(rccFile);
893-
}
894-
{
895-
std::string base = this->Dir.Info;
896-
base += "/RCC";
897-
base += qrc.QrcName;
887+
std::string base = cmStrCat(this->Dir.Info, "/RCC", qrc.QrcName);
898888
if (!qrc.Unique) {
899889
base += qrc.PathChecksum;
900890
}
@@ -927,8 +917,7 @@ bool cmQtAutoGenInitializer::InitScanFiles()
927917
// Replace '-' with '_'. The former is not valid for symbol names.
928918
std::replace(name.begin(), name.end(), '-', '_');
929919
if (!qrc.Unique) {
930-
name += "_";
931-
name += qrc.PathChecksum;
920+
name += cmStrCat("_", qrc.PathChecksum);
932921
}
933922
std::vector<std::string> nameOpts;
934923
nameOpts.emplace_back("-name");
@@ -1152,8 +1141,8 @@ bool cmQtAutoGenInitializer::InitRccTargets()
11521141
currentLine.push_back("$<CONFIG>");
11531142
commandLines.push_back(std::move(currentLine));
11541143
}
1155-
std::string ccComment = "Automatic RCC for ";
1156-
ccComment += FileProjectRelativePath(makefile, qrc.QrcFile);
1144+
std::string ccComment = cmStrCat(
1145+
"Automatic RCC for ", FileProjectRelativePath(makefile, qrc.QrcFile));
11571146

11581147
if (qrc.Generated || this->Rcc.GlobalTarget) {
11591148
// Create custom rcc target
@@ -1221,9 +1210,8 @@ bool cmQtAutoGenInitializer::SetupCustomTargets()
12211210
{
12221211
// Create info directory on demand
12231212
if (!cmSystemTools::MakeDirectory(this->Dir.Info)) {
1224-
std::string emsg = ("AutoGen: Could not create directory: ");
1225-
emsg += Quoted(this->Dir.Info);
1226-
cmSystemTools::Error(emsg);
1213+
cmSystemTools::Error(cmStrCat("AutoGen: Could not create directory: ",
1214+
Quoted(this->Dir.Info)));
12271215
return false;
12281216
}
12291217

@@ -1306,10 +1294,8 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
13061294
}
13071295
if (muf->MocIt || muf->UicIt) {
13081296
headers.emplace_back(muf->RealPath);
1309-
std::string flags;
1310-
flags += muf->MocIt ? 'M' : 'm';
1311-
flags += muf->UicIt ? 'U' : 'u';
1312-
headersFlags.emplace_back(std::move(flags));
1297+
headersFlags.emplace_back(
1298+
cmStrCat(muf->MocIt ? "M" : "m", muf->UicIt ? "U" : "u"));
13131299
}
13141300
}
13151301
}
@@ -1318,14 +1304,13 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
13181304
cmFilePathChecksum const fpathCheckSum(makefile);
13191305
std::unordered_set<std::string> emitted;
13201306
for (std::string const& hdr : headers) {
1321-
std::string basePath = fpathCheckSum.getPart(hdr);
1322-
basePath += "/moc_";
1323-
basePath += cmSystemTools::GetFilenameWithoutLastExtension(hdr);
1324-
for (unsigned int ii = 1; ii != 1024; ++ii) {
1307+
std::string basePath =
1308+
cmStrCat(fpathCheckSum.getPart(hdr), "/moc_",
1309+
cmSystemTools::GetFilenameWithoutLastExtension(hdr));
1310+
for (int ii = 1; ii != 1024; ++ii) {
13251311
std::string path = basePath;
13261312
if (ii > 1) {
1327-
path += '_';
1328-
path += std::to_string(ii);
1313+
path += cmStrCat("_", ii);
13291314
}
13301315
path += ".cpp";
13311316
if (emitted.emplace(path).second) {
@@ -1364,10 +1349,8 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
13641349
}
13651350
if (muf->MocIt || muf->UicIt) {
13661351
sources.emplace_back(muf->RealPath);
1367-
std::string flags;
1368-
flags += muf->MocIt ? 'M' : 'm';
1369-
flags += muf->UicIt ? 'U' : 'u';
1370-
sourcesFlags.emplace_back(std::move(flags));
1352+
sourcesFlags.emplace_back(
1353+
cmStrCat(muf->MocIt ? "M" : "m", muf->UicIt ? "U" : "u"));
13711354
}
13721355
}
13731356
}
@@ -1421,9 +1404,8 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
14211404
ofs.WriteStrings("AM_UIC_SEARCH_PATHS", this->Uic.SearchPaths);
14221405
}
14231406
} else {
1424-
std::string err = "AutoGen: Could not write file ";
1425-
err += this->AutogenTarget.InfoFile;
1426-
cmSystemTools::Error(err);
1407+
cmSystemTools::Error(cmStrCat("AutoGen: Could not write file ",
1408+
this->AutogenTarget.InfoFile));
14271409
return false;
14281410
}
14291411

@@ -1462,9 +1444,8 @@ bool cmQtAutoGenInitializer::SetupWriteRccInfo()
14621444
ofs.WriteStrings("ARCC_OPTIONS", qrc.Options);
14631445
ofs.WriteStrings("ARCC_INPUTS", qrc.Resources);
14641446
} else {
1465-
std::string err = "AutoRcc: Could not write file ";
1466-
err += qrc.InfoFile;
1467-
cmSystemTools::Error(err);
1447+
cmSystemTools::Error(
1448+
cmStrCat("AutoRcc: Could not write file ", qrc.InfoFile));
14681449
return false;
14691450
}
14701451
}
@@ -1519,13 +1500,10 @@ bool cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName,
15191500
if (!groupName.empty()) {
15201501
sourceGroup = makefile->GetOrCreateSourceGroup(groupName);
15211502
if (sourceGroup == nullptr) {
1522-
std::string err;
1523-
err += genNameUpper;
1524-
err += " error in ";
1525-
err += property;
1526-
err += ": Could not find or create the source group ";
1527-
err += cmQtAutoGen::Quoted(groupName);
1528-
cmSystemTools::Error(err);
1503+
cmSystemTools::Error(
1504+
cmStrCat(genNameUpper, " error in ", property,
1505+
": Could not find or create the source group ",
1506+
cmQtAutoGen::Quoted(groupName)));
15291507
return false;
15301508
}
15311509
}
@@ -1617,12 +1595,8 @@ bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars,
16171595
bool ignoreMissingTarget) const
16181596
{
16191597
auto print_err = [this, &genVars](std::string const& err) {
1620-
std::string msg = genVars.GenNameUpper;
1621-
msg += " for target ";
1622-
msg += this->Target->GetName();
1623-
msg += ": ";
1624-
msg += err;
1625-
cmSystemTools::Error(msg);
1598+
cmSystemTools::Error(cmStrCat(genVars.GenNameUpper, " for target ",
1599+
this->Target->GetName(), ": ", err));
16261600
};
16271601

16281602
// Custom executable
@@ -1682,11 +1656,8 @@ bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars,
16821656
std::make_shared<cmQtAutoGen::CompilerFeatures>();
16831657
return true;
16841658
}
1685-
std::string err = "Could not find ";
1686-
err += executable;
1687-
err += " executable target ";
1688-
err += targetName;
1689-
print_err(err);
1659+
print_err(cmStrCat("Could not find ", executable, " executable target ",
1660+
targetName));
16901661
return false;
16911662
}
16921663
}

Source/cmQtAutoGenerator.cxx

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
22
file Copyright.txt or https://cmake.org/licensing for details. */
33
#include "cmQtAutoGenerator.h"
4-
#include "cmQtAutoGen.h"
5-
6-
#include "cmsys/FStream.hxx"
74

85
#include "cm_memory.hxx"
6+
#include "cmsys/FStream.hxx"
97

108
#include "cmGlobalGenerator.h"
119
#include "cmMakefile.h"
10+
#include "cmQtAutoGen.h"
1211
#include "cmState.h"
1312
#include "cmStateDirectory.h"
1413
#include "cmStateSnapshot.h"
14+
#include "cmStringAlgorithms.h"
1515
#include "cmSystemTools.h"
1616
#include "cmake.h"
1717

@@ -60,19 +60,13 @@ void cmQtAutoGenerator::Logger::SetColorOutput(bool value)
6060

6161
std::string cmQtAutoGenerator::Logger::HeadLine(std::string const& title)
6262
{
63-
std::string head = title;
64-
head += '\n';
65-
head.append(head.size() - 1, '-');
66-
head += '\n';
67-
return head;
63+
return cmStrCat(title, "\n", std::string(title.size(), '-'), "\n");
6864
}
6965

7066
void cmQtAutoGenerator::Logger::Info(GenT genType,
7167
std::string const& message) const
7268
{
73-
std::string msg = GeneratorName(genType);
74-
msg += ": ";
75-
msg += message;
69+
std::string msg = cmStrCat(GeneratorName(genType), ": ", message);
7670
if (msg.back() != '\n') {
7771
msg.push_back('\n');
7872
}
@@ -110,19 +104,13 @@ void cmQtAutoGenerator::Logger::WarningFile(GenT genType,
110104
std::string const& filename,
111105
std::string const& message) const
112106
{
113-
std::string msg = " ";
114-
msg += Quoted(filename);
115-
msg.push_back('\n');
116-
// Message
117-
msg += message;
118-
Warning(genType, msg);
107+
Warning(genType, cmStrCat(" ", Quoted(filename), "\n", message));
119108
}
120109

121110
void cmQtAutoGenerator::Logger::Error(GenT genType,
122111
std::string const& message) const
123112
{
124-
std::string msg;
125-
msg += HeadLine(GeneratorName(genType) + " error");
113+
std::string msg = HeadLine(GeneratorName(genType) + " error");
126114
// Message
127115
msg += message;
128116
if (msg.back() != '\n') {
@@ -139,12 +127,7 @@ void cmQtAutoGenerator::Logger::ErrorFile(GenT genType,
139127
std::string const& filename,
140128
std::string const& message) const
141129
{
142-
std::string emsg = " ";
143-
emsg += Quoted(filename);
144-
emsg += '\n';
145-
// Message
146-
emsg += message;
147-
Error(genType, emsg);
130+
Error(genType, cmStrCat(" ", Quoted(filename), '\n', message));
148131
}
149132

150133
void cmQtAutoGenerator::Logger::ErrorCommand(
@@ -280,10 +263,8 @@ bool cmQtAutoGenerator::Run(std::string const& infoFile,
280263
InfoFile_ = infoFile;
281264
cmSystemTools::ConvertToUnixSlashes(InfoFile_);
282265
if (!InfoFileTime_.Load(InfoFile_)) {
283-
std::string msg = "AutoGen: The info file ";
284-
msg += Quoted(InfoFile_);
285-
msg += " is not readable\n";
286-
cmSystemTools::Stderr(msg);
266+
cmSystemTools::Stderr(cmStrCat("AutoGen: The info file ",
267+
Quoted(InfoFile_), " is not readable\n"));
287268
return false;
288269
}
289270
InfoDir_ = cmSystemTools::GetFilenamePath(infoFile);

0 commit comments

Comments
 (0)