From c42acbbecc7ffdca172876d61aa688abeadb9606 Mon Sep 17 00:00:00 2001 From: Alex Overchenko Date: Sat, 20 Dec 2025 09:26:34 +0300 Subject: [PATCH] Source: replace string addition to cmStrCat --- Source/CPack/cmCPackFreeBSDGenerator.cxx | 14 ++-- Source/CPack/cmCPackGenerator.cxx | 4 +- Source/CPack/cmCPackInnoSetupGenerator.cxx | 2 +- Source/CPack/cmCPackNSISGenerator.cxx | 3 +- Source/CTest/cmCTestBuildHandler.cxx | 4 +- Source/CTest/cmCTestCoverageHandler.cxx | 4 +- Source/cmArgumentParser.cxx | 6 +- Source/cmCMakePath.cxx | 5 +- Source/cmCacheManager.cxx | 31 +++++---- Source/cmCommonTargetGenerator.cxx | 7 +- Source/cmCurl.cxx | 8 ++- Source/cmDependsJavaParserHelper.cxx | 12 ++-- Source/cmDocumentation.cxx | 2 +- Source/cmExportAndroidMKGenerator.cxx | 8 +-- Source/cmExtraEclipseCDT4Generator.cxx | 2 +- Source/cmExtraKateGenerator.cxx | 2 +- Source/cmExtraSublimeTextGenerator.cxx | 15 ++-- Source/cmFastbuildTargetGenerator.cxx | 22 +++--- Source/cmFileAPICodemodel.cxx | 6 +- Source/cmFileCommand.cxx | 13 ++-- Source/cmGeneratorTarget.cxx | 69 ++++++++++--------- .../cmGeneratorTarget_CompatibleInterface.cxx | 7 +- .../cmGeneratorTarget_TransitiveProperty.cxx | 2 +- Source/cmGhsMultiTargetGenerator.cxx | 5 +- Source/cmGlobalFastbuildGenerator.cxx | 19 ++--- Source/cmInstallExportGenerator.cxx | 2 +- 26 files changed, 143 insertions(+), 131 deletions(-) diff --git a/Source/CPack/cmCPackFreeBSDGenerator.cxx b/Source/CPack/cmCPackFreeBSDGenerator.cxx index e4a308ca4b..62cc67250d 100644 --- a/Source/CPack/cmCPackFreeBSDGenerator.cxx +++ b/Source/CPack/cmCPackFreeBSDGenerator.cxx @@ -388,12 +388,12 @@ int cmCPackFreeBSDGenerator::PackageFiles() // a file with the package name and version as specified in the // manifest, so we look those up (again). lastSlash is the slash // itself, we need that as path separator to the calculated package name. - std::string actualPackage = - ((lastSlash != std::string::npos) - ? std::string(currentPackage, 0, lastSlash + 1) - : std::string()) + - var_lookup("CPACK_FREEBSD_PACKAGE_NAME") + '-' + - var_lookup("CPACK_FREEBSD_PACKAGE_VERSION") + FreeBSDPackageSuffix_17; + std::string actualPackage = cmStrCat( + (lastSlash != std::string::npos) + ? cm::string_view(currentPackage).substr(0, lastSlash + 1) + : ""_s, + var_lookup("CPACK_FREEBSD_PACKAGE_NAME"), '-', + var_lookup("CPACK_FREEBSD_PACKAGE_VERSION"), FreeBSDPackageSuffix_17); this->packageFileNames.clear(); this->packageFileNames.emplace_back(actualPackage); @@ -442,7 +442,7 @@ int cmCPackFreeBSDGenerator::PackageFiles() std::string const packageSubDirectory = cmSystemTools::GetParentDirectory(sourceFile); std::string const targetFileName = - packageSubDirectory + '/' + packageFileName; + cmStrCat(packageSubDirectory, '/', packageFileName); if (cmSystemTools::RenameFile(sourceFile, targetFileName)) { this->packageFileNames.clear(); this->packageFileNames.emplace_back(targetFileName); diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index f9fed6dc09..aa07d83ed3 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -1610,12 +1610,12 @@ std::string cmCPackGenerator::GetSanitizedDirOrFileName( "[Ll][Pp][Tt][1-9]" ")[.]?$"); if (reserved_pattern.find(name)) { - return "_" + name; + return cmStrCat('_', std::move(name)); } // Given name ends in a dot (on Windows)? // Then return it appended with an underscore. if (name.back() == '.') { - return name + '_'; + return cmStrCat(std::move(name), '_'); } #endif } diff --git a/Source/CPack/cmCPackInnoSetupGenerator.cxx b/Source/CPack/cmCPackInnoSetupGenerator.cxx index 93641b5471..a03c2c1442 100644 --- a/Source/CPack/cmCPackInnoSetupGenerator.cxx +++ b/Source/CPack/cmCPackInnoSetupGenerator.cxx @@ -889,7 +889,7 @@ bool cmCPackInnoSetupGenerator::BuildDownloadedComponentArchive( { // Remove the old archive, if one exists std::string const& archiveFile = - uploadDirectory + '/' + component->ArchiveFile; + cmStrCat(uploadDirectory, '/', component->ArchiveFile); cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Building downloaded component archive: " << archiveFile << std::endl); diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index 85f17866c0..538222d21c 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -773,7 +773,8 @@ std::string cmCPackNSISGenerator::CreateComponentDescription( } // Remove the old archive, if one exists - std::string archiveFile = uploadDirectory + '/' + component->ArchiveFile; + std::string archiveFile = + cmStrCat(uploadDirectory, '/', component->ArchiveFile); cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Building downloaded component archive: " << archiveFile << std::endl); diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index 422d37116b..d1132add41 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -514,11 +514,11 @@ void cmCTestBuildHandler::GenerateXMLLaunched(cmXMLWriter& xml) char const* fname = launchDir.GetFile(i); if (this->IsLaunchedErrorFile(fname) && numErrorsAllowed) { numErrorsAllowed--; - fragments.insert(this->CTestLaunchDir + '/' + fname); + fragments.insert(cmStrCat(this->CTestLaunchDir, '/', fname)); ++this->TotalErrors; } else if (this->IsLaunchedWarningFile(fname) && numWarningsAllowed) { numWarningsAllowed--; - fragments.insert(this->CTestLaunchDir + '/' + fname); + fragments.insert(cmStrCat(this->CTestLaunchDir, '/', fname)); ++this->TotalWarnings; } } diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index 8fd237e12d..65cbd53d97 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -791,9 +791,9 @@ static std::string joinCommandLine(std::vector const& args) for (std::string const& s : args) { if (s.find(' ') == std::string::npos) { - ret += s + ' '; + ret = cmStrCat(std::move(ret), s, ' '); } else { - ret += "\"" + s + "\" "; + ret = cmStrCat(std::move(ret), '"', s, "\" "); } } diff --git a/Source/cmArgumentParser.cxx b/Source/cmArgumentParser.cxx index 3d82c81441..30bdadc074 100644 --- a/Source/cmArgumentParser.cxx +++ b/Source/cmArgumentParser.cxx @@ -216,10 +216,8 @@ bool ParseResult::MaybeReportError(cmMakefile& mf) const } std::string e; for (auto const& kel : this->KeywordErrors) { - e = cmStrCat(e, "Error after keyword \"", kel.first, "\":\n"); - for (auto const& ke : kel.second) { - e += ke; - } + e = cmStrCat(std::move(e), "Error after keyword \"", kel.first, "\":\n", + cmJoin(kel.second, {})); } mf.IssueMessage(MessageType::FATAL_ERROR, e); return true; diff --git a/Source/cmCMakePath.cxx b/Source/cmCMakePath.cxx index 5f6db32034..d046c93deb 100644 --- a/Source/cmCMakePath.cxx +++ b/Source/cmCMakePath.cxx @@ -7,6 +7,8 @@ #include +#include "cmStringAlgorithms.h" + #if defined(_WIN32) # include #endif @@ -17,7 +19,6 @@ #if defined(_WIN32) # include -# include "cmStringAlgorithms.h" #endif cmCMakePath& cmCMakePath::ReplaceWideExtension(cm::string_view extension) @@ -33,7 +34,7 @@ cmCMakePath& cmCMakePath::ReplaceWideExtension(cm::string_view extension) if (extension[0] != '.') { file += '.'; } - file.append(std::string(extension)); + file = cmStrCat(std::move(file), extension); } this->Path.replace_filename(file); return *this; diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 30d033c615..23d6751981 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -71,10 +71,9 @@ bool cmCacheManager::LoadCache(std::string const& path, bool internal, } while (realbuffer[0] == '/' && realbuffer[1] == '/') { if ((realbuffer[2] == '\\') && (realbuffer[3] == 'n')) { - helpString += '\n'; - helpString += &realbuffer[4]; + helpString = cmStrCat(std::move(helpString), '\n', &realbuffer[4]); } else { - helpString += &realbuffer[2]; + helpString = cmStrCat(std::move(helpString), &realbuffer[2]); } cmSystemTools::GetLineFromStream(fin, buffer); lineno++; @@ -149,17 +148,17 @@ bool cmCacheManager::LoadCache(std::string const& path, bool internal, std::string currentcwd = path; std::string oldcwd = *oldDir; cmSystemTools::ConvertToUnixSlashes(currentcwd); - currentcwd += "/CMakeCache.txt"; - oldcwd += "/CMakeCache.txt"; + currentcwd = cmStrCat(std::move(currentcwd), "/CMakeCache.txt"); + oldcwd = cmStrCat(std::move(oldcwd), "/CMakeCache.txt"); if (!cmSystemTools::SameFile(oldcwd, currentcwd)) { cmValue dir = this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR"); - std::ostringstream message; - message << "The current CMakeCache.txt directory " << currentcwd - << " is different than the directory " << (dir ? *dir : "") - << " where CMakeCache.txt was created. This may result " + std::string message = + cmStrCat("The current CMakeCache.txt directory ", currentcwd, + " is different than the directory ", (dir ? *dir : ""), + " where CMakeCache.txt was created. This may result " "in binaries being created in the wrong place. If you " - "are not sure, reedit the CMakeCache.txt"; - cmSystemTools::Error(message.str()); + "are not sure, reedit the CMakeCache.txt"); + cmSystemTools::Error(message); } } this->CacheLoaded = true; @@ -225,7 +224,8 @@ bool cmCacheManager::SaveCache(std::string const& path, cmMessenger* messenger) cmGeneratedFileStream fout(cacheFile); fout.SetCopyIfDifferent(true); if (!fout) { - cmSystemTools::Error("Unable to open cache file for save. " + cacheFile); + cmSystemTools::Error( + cmStrCat("Unable to open cache file for save. ", std::move(cacheFile))); cmSystemTools::ReportLastSystemError(""); return false; } @@ -342,11 +342,12 @@ bool cmCacheManager::SaveCache(std::string const& path, cmMessenger* messenger) fout.Close(); std::string checkCacheFile = cmStrCat(path, "/CMakeFiles"); cmSystemTools::MakeDirectory(checkCacheFile); - checkCacheFile += "/cmake.check_cache"; + checkCacheFile = cmStrCat(std::move(checkCacheFile), "/cmake.check_cache"); cmsys::ofstream checkCache(checkCacheFile.c_str()); if (!checkCache) { - cmSystemTools::Error("Unable to open check cache file for write. " + - checkCacheFile); + cmSystemTools::Error( + cmStrCat("Unable to open check cache file for write. ", + std::move(checkCacheFile))); return false; } checkCache << "# This file is generated by cmake for dependency checking " diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index d41a3560bb..72bf359965 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -393,9 +393,10 @@ std::string cmCommonTargetGenerator::GenerateCodeCheckRules( if (!compilerLauncher.empty()) { // In __run_co_compile case the launcher command is supplied // via --launcher= and consumed - code_check += " --launcher="; - code_check += this->GeneratorTarget->GetLocalGenerator()->EscapeForShell( - compilerLauncher); + code_check = + cmStrCat(std::move(code_check), " --launcher=", + this->GeneratorTarget->GetLocalGenerator()->EscapeForShell( + compilerLauncher)); compilerLauncher.clear(); } if (cmNonempty(iwyu)) { diff --git a/Source/cmCurl.cxx b/Source/cmCurl.cxx index 627e302c4c..484ac1fc97 100644 --- a/Source/cmCurl.cxx +++ b/Source/cmCurl.cxx @@ -2,6 +2,8 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmCurl.h" +#include + #include #include @@ -28,9 +30,9 @@ #define check_curl_result(result, errstr) \ do { \ if ((result) != CURLE_OK && (result) != CURLE_NOT_BUILT_IN) { \ - e += e.empty() ? "" : "\n"; \ - e += (errstr); \ - e += ::curl_easy_strerror(result); \ + bool isNeedNewline = !e.empty(); \ + e = cmStrCat(std::move(e), isNeedNewline ? "\n"_s : ""_s, (errstr), \ + ::curl_easy_strerror(result)); \ } \ } while (false) diff --git a/Source/cmDependsJavaParserHelper.cxx b/Source/cmDependsJavaParserHelper.cxx index a24bcd0a31..1cf6fdd298 100644 --- a/Source/cmDependsJavaParserHelper.cxx +++ b/Source/cmDependsJavaParserHelper.cxx @@ -14,6 +14,7 @@ #include "cmsys/FStream.hxx" #include "cmDependsJavaLexer.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" int cmDependsJava_yyparse(yyscan_t yyscanner); @@ -40,8 +41,7 @@ void cmDependsJavaParserHelper::CurrentClass::AddFileNamesForPrinting( { std::string rname; if (prefix) { - rname += prefix; - rname += sep; + rname = cmStrCat(std::move(rname), prefix, sep); } rname += this->Name; files->push_back(rname); @@ -310,10 +310,10 @@ void cmDependsJavaParserHelper::UpdateCombine(char const* str1, char const* str2) { if (this->CurrentCombine.empty() && str1) { - this->CurrentCombine = str1; + // We can reuse allocated memory from `this->CurrentCombine` + this->CurrentCombine = cmStrCat(std::move(this->CurrentCombine), str1); } - this->CurrentCombine += "."; - this->CurrentCombine += str2; + this->CurrentCombine = cmStrCat(std::move(this->CurrentCombine), '.', str2); } int cmDependsJavaParserHelper::ParseFile(char const* file) @@ -329,7 +329,7 @@ int cmDependsJavaParserHelper::ParseFile(char const* file) std::string fullfile; std::string line; while (cmSystemTools::GetLineFromStream(ifs, line)) { - fullfile += line + "\n"; + fullfile = cmStrCat(std::move(fullfile), line, '\n'); } return this->ParseString(fullfile.c_str(), 0); } diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index f632207309..e3b634eb79 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -462,7 +462,7 @@ bool cmDocumentation::PrintFiles(std::ostream& os, std::string const& pattern) std::vector files; this->GlobHelp(files, pattern); std::sort(files.begin(), files.end()); - cmRST r(os, cmSystemTools::GetCMakeRoot() + "/Help"); + cmRST r(os, cmStrCat(cmSystemTools::GetCMakeRoot(), "/Help")); for (std::string const& f : files) { found = r.ProcessFile(f) || found; } diff --git a/Source/cmExportAndroidMKGenerator.cxx b/Source/cmExportAndroidMKGenerator.cxx index 524fe58432..0b125f75f6 100644 --- a/Source/cmExportAndroidMKGenerator.cxx +++ b/Source/cmExportAndroidMKGenerator.cxx @@ -68,9 +68,9 @@ void cmExportAndroidMKGenerator::GenerateInterfaceProperties( if (gt->GetType() == cmStateEnums::SHARED_LIBRARY || gt->GetType() == cmStateEnums::MODULE_LIBRARY) { - sharedLibs += " " + lib; + sharedLibs = cmStrCat(std::move(sharedLibs), ' ', lib); } else { - staticLibs += " " + lib; + staticLibs = cmStrCat(std::move(staticLibs), ' ', lib); } } else { bool relpath = false; @@ -82,10 +82,10 @@ void cmExportAndroidMKGenerator::GenerateInterfaceProperties( // if it is full or a link library then use string directly if (cmSystemTools::FileIsFullPath(lib) || cmHasLiteralPrefix(lib, "-l") || relpath) { - ldlibs += " " + lib; + ldlibs = cmStrCat(std::move(ldlibs), ' ', lib); // if it is not a path and does not have a -l then add -l } else if (!lib.empty()) { - ldlibs += " -l" + lib; + ldlibs = cmStrCat(std::move(ldlibs), " -l", lib); } } } diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 5c86bc490f..9a5e10903d 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -738,7 +738,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const // - only if not named the same as an output directory if (!cmSystemTools::FileIsDirectory( cmStrCat(this->HomeOutputDirectory, '/', p))) { - excludeFromOut += p + "/|"; + excludeFromOut = cmStrCat(std::move(excludeFromOut), p, "/|"); } } diff --git a/Source/cmExtraKateGenerator.cxx b/Source/cmExtraKateGenerator.cxx index 4363f23941..8045b4cf32 100644 --- a/Source/cmExtraKateGenerator.cxx +++ b/Source/cmExtraKateGenerator.cxx @@ -328,7 +328,7 @@ std::string cmExtraKateGenerator::GenerateProjectName( std::string const& name, std::string const& type, std::string const& path) const { - return name + (type.empty() ? "" : "-") + type + '@' + path; + return cmStrCat(name, (type.empty() ? "" : "-"), type, '@', path); } std::string cmExtraKateGenerator::GetPathBasename( diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx index 4b0ee982c3..ad371d571c 100644 --- a/Source/cmExtraSublimeTextGenerator.cxx +++ b/Source/cmExtraSublimeTextGenerator.cxx @@ -318,14 +318,12 @@ std::string cmExtraSublimeTextGenerator::BuildMakeCommand( std::string generator = this->GlobalGenerator->GetName(); if (generator == "NMake Makefiles") { std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile); - command += R"(, "/NOLOGO", "/f", ")"; - command += makefileName + "\""; - command += ", \"" + target + "\""; + command = cmStrCat(std::move(command), R"(, "/NOLOGO", "/f", ")", + std::move(makefileName), "\", \"", target, '"'); } else if (generator == "Ninja") { std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile); - command += R"(, "-f", ")"; - command += makefileName + "\""; - command += ", \"" + target + "\""; + command = cmStrCat(std::move(command), R"(, "-f", ")", + std::move(makefileName), "\", \"", target, '"'); } else { std::string makefileName; if (generator == "MinGW Makefiles") { @@ -335,9 +333,8 @@ std::string cmExtraSublimeTextGenerator::BuildMakeCommand( } else { makefileName = cmSystemTools::ConvertToOutputPath(makefile); } - command += R"(, "-f", ")"; - command += makefileName + "\""; - command += ", \"" + target + "\""; + command = cmStrCat(std::move(command), R"(, "-f", ")", + std::move(makefileName), "\", \"", target, '"'); } return command; } diff --git a/Source/cmFastbuildTargetGenerator.cxx b/Source/cmFastbuildTargetGenerator.cxx index 2726fba2ff..06f6ab9eca 100644 --- a/Source/cmFastbuildTargetGenerator.cxx +++ b/Source/cmFastbuildTargetGenerator.cxx @@ -339,9 +339,9 @@ void cmFastbuildTargetGenerator::AddOutput(cmCustomCommandGenerator const& ccg, void cmFastbuildTargetGenerator::AddExecArguments( FastbuildExecNode& exec, std::string const& scriptFilename) const { - exec.ExecArguments = FASTBUILD_SCRIPT_FILE_ARG; - exec.ExecArguments += - cmGlobalFastbuildGenerator::QuoteIfHasSpaces(scriptFilename); + exec.ExecArguments = + cmStrCat(FASTBUILD_SCRIPT_FILE_ARG, + cmGlobalFastbuildGenerator::QuoteIfHasSpaces(scriptFilename)); exec.ScriptFile = scriptFilename; exec.ExecExecutable = @@ -510,18 +510,16 @@ FastbuildExecNode cmFastbuildTargetGenerator::GetDepsCheckExec( exec.ExecUseStdOutAsOutput = true; exec.ExecOutput = depender.ExecOutput + ".deps-checker"; exec.ExecExecutable = cmSystemTools::GetCMakeCommand(); - exec.ExecArguments += "-E cmake_fastbuild_check_depends "; - exec.ExecArguments += depender.ExecOutput + ' '; - char const* sep = ""; + exec.ExecArguments = + cmStrCat(std::move(exec.ExecArguments), + "-E cmake_fastbuild_check_depends ", depender.ExecOutput); for (auto const& dep : depender.OutputsAlias.PreBuildDependencies) { - exec.ExecArguments += sep; - exec.ExecArguments += dep.Name; - sep = " "; + exec.ExecArguments = + cmStrCat(std::move(exec.ExecArguments), ' ', dep.Name); } for (auto const& dep : depender.ByproductsAlias.PreBuildDependencies) { - exec.ExecArguments += sep; - exec.ExecArguments += dep.Name; - sep = " "; + exec.ExecArguments = + cmStrCat(std::move(exec.ExecArguments), ' ', dep.Name); } return exec; } diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index fb4ec36875..d1f2e0b88a 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -2060,9 +2060,9 @@ Json::Value Target::DumpArtifacts() this->GT->GetOutputInfo(this->Config); if (output && !output->PdbDir.empty()) { Json::Value artifact = Json::objectValue; - artifact["path"] = RelativeIfUnder(this->TopBuild, - output->PdbDir + '/' + - this->GT->GetPDBName(this->Config)); + artifact["path"] = RelativeIfUnder( + this->TopBuild, + cmStrCat(output->PdbDir, '/', this->GT->GetPDBName(this->Config))); artifacts.append(std::move(artifact)); // NOLINT(*) } } diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 3956096b45..8791385d93 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -1607,9 +1607,10 @@ bool HandleRemoveImpl(std::vector const& args, bool recurse, { std::string fileName = arg; if (fileName.empty()) { - std::string const r = recurse ? "REMOVE_RECURSE" : "REMOVE"; + std::string r = recurse ? "REMOVE_RECURSE" : "REMOVE"; status.GetMakefile().IssueMessage( - MessageType::AUTHOR_WARNING, "Ignoring empty file name in " + r + "."); + MessageType::AUTHOR_WARNING, + cmStrCat("Ignoring empty file name in ", std::move(r), '.')); continue; } if (!cmsys::SystemTools::FileIsFullPath(fileName)) { @@ -2195,8 +2196,9 @@ bool HandleDownloadCommand(std::vector const& args, } for (auto const& range : curl_ranges) { - std::string curl_range = range.first + '-' + - (range.second.has_value() ? range.second.value() : ""); + std::string curl_range = + cmStrCat(range.first, '-', + (range.second.has_value() ? range.second.value() : "")); res = ::curl_easy_setopt(curl, CURLOPT_RANGE, curl_range.c_str()); check_curl_result(res, "DOWNLOAD cannot set range: "); } @@ -3203,7 +3205,8 @@ bool HandleCreateLinkCommand(std::vector const& args, parser.Parse(cmMakeRange(args).advance(3), &unconsumedArgs); if (!unconsumedArgs.empty()) { - status.SetError("unknown argument: \"" + unconsumedArgs.front() + '\"'); + status.SetError(cmStrCat("unknown argument: \"", + std::move(unconsumedArgs.front()), '\"')); return false; } diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 5363720c60..45f35e11f9 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -322,7 +322,7 @@ std::string cmGeneratorTarget::GetOutputName( std::string configUpper = cmSystemTools::UpperCase(config); if (!type.empty() && !configUpper.empty()) { // _OUTPUT_NAME_ - props.push_back(type + "_OUTPUT_NAME_" + configUpper); + props.push_back(cmStrCat(type, "_OUTPUT_NAME_", configUpper)); } if (!type.empty()) { // _OUTPUT_NAME @@ -357,7 +357,8 @@ std::string cmGeneratorTarget::GetOutputName( // from the above block. this->LocalGenerator->GetCMakeInstance()->IssueMessage( MessageType::FATAL_ERROR, - "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.", + cmStrCat("Target '", this->GetName(), + "' OUTPUT_NAME depends on itself."), this->GetBacktrace()); } return i->second; @@ -806,7 +807,8 @@ bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang, cmPolicies::PolicyStatus cmp0069 = this->GetPolicyStatusCMP0069(); if (cmp0069 == cmPolicies::OLD || cmp0069 == cmPolicies::WARN) { - if (this->Makefile->IsOn("_CMAKE_" + lang + "_IPO_LEGACY_BEHAVIOR")) { + if (this->Makefile->IsOn( + cmStrCat("_CMAKE_", lang, "_IPO_LEGACY_BEHAVIOR"))) { return true; } if (this->PolicyReportedCMP0069) { @@ -2683,32 +2685,33 @@ void cmGeneratorTarget::AddCUDAArchitectureFlagsImpl(cmBuildStep compileOrLink, } for (CudaArchitecture& architecture : architectures) { - flags += - " \"--generate-code=arch=compute_" + architecture.name + ",code=["; + flags = cmStrCat(std::move(flags), " \"--generate-code=arch=compute_", + architecture.name, ",code=["); if (architecture.virtual_) { - flags += "compute_" + architecture.name; + flags = cmStrCat(std::move(flags), "compute_", architecture.name); if (ipoEnabled || architecture.real) { - flags += ","; + flags += ','; } } if (ipoEnabled) { if (compileOrLink == cmBuildStep::Compile) { - flags += "lto_" + architecture.name; + flags = cmStrCat(std::move(flags), "lto_", architecture.name); } else if (compileOrLink == cmBuildStep::Link) { - flags += "sm_" + architecture.name; + flags = cmStrCat(std::move(flags), "sm_", architecture.name); } } else if (architecture.real) { - flags += "sm_" + architecture.name; + flags = cmStrCat(std::move(flags), "sm_", architecture.name); } flags += "]\""; } } else if (compiler == "Clang" && compileOrLink == cmBuildStep::Compile) { for (CudaArchitecture& architecture : architectures) { - flags += " --cuda-gpu-arch=sm_" + architecture.name; + flags = + cmStrCat(std::move(flags), " --cuda-gpu-arch=sm_", architecture.name); if (!architecture.real) { this->Makefile->IssueMessage( @@ -2717,7 +2720,8 @@ void cmGeneratorTarget::AddCUDAArchitectureFlagsImpl(cmBuildStep compileOrLink, } if (!architecture.virtual_) { - flags += " --no-cuda-include-ptx=sm_" + architecture.name; + flags = cmStrCat(std::move(flags), " --no-cuda-include-ptx=sm_", + architecture.name); } } } @@ -2750,9 +2754,10 @@ void cmGeneratorTarget::AddHIPArchitectureFlags(cmBuildStep compileOrLink, std::string arch = this->GetSafeProperty("HIP_ARCHITECTURES"); if (arch.empty()) { - this->Makefile->IssueMessage(MessageType::FATAL_ERROR, - "HIP_ARCHITECTURES is empty for target \"" + - this->GetName() + "\"."); + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("HIP_ARCHITECTURES is empty for target \"", this->GetName(), + "\".")); } // If HIP_ARCHITECTURES is false we don't add any architectures. @@ -2816,29 +2821,29 @@ std::string cmGeneratorTarget::GetCreateRuleVariable( { switch (this->GetType()) { case cmStateEnums::STATIC_LIBRARY: { - std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY"; + std::string var = cmStrCat("CMAKE_", lang, "_CREATE_STATIC_LIBRARY"); return this->GetFeatureSpecificLinkRuleVariable(var, lang, config); } case cmStateEnums::SHARED_LIBRARY: if (this->IsArchivedAIXSharedLibrary()) { - return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY_ARCHIVE"; + return cmStrCat("CMAKE_", lang, "_CREATE_SHARED_LIBRARY_ARCHIVE"); } - return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY"; + return cmStrCat("CMAKE_", lang, "_CREATE_SHARED_LIBRARY"); case cmStateEnums::MODULE_LIBRARY: - return "CMAKE_" + lang + "_CREATE_SHARED_MODULE"; + return cmStrCat("CMAKE_", lang, "_CREATE_SHARED_MODULE"); case cmStateEnums::EXECUTABLE: if (this->IsExecutableWithExports()) { std::string linkExeWithExports = - "CMAKE_" + lang + "_LINK_EXECUTABLE_WITH_EXPORTS"; + cmStrCat("CMAKE_", lang, "_LINK_EXECUTABLE_WITH_EXPORTS"); if (this->Makefile->IsDefinitionSet(linkExeWithExports)) { return linkExeWithExports; } } - return "CMAKE_" + lang + "_LINK_EXECUTABLE"; + return cmStrCat("CMAKE_", lang, "_LINK_EXECUTABLE"); default: break; } - return ""; + return {}; } //---------------------------------------------------------------------------- @@ -3276,9 +3281,9 @@ std::string cmGeneratorTarget::GetPchCreateCompileOptions( if (GlobalGenerator->IsFastbuild()) { // Account for potential spaces in a shell-friendly way. cmSystemTools::ReplaceString(createOptionList, "", - '"' + pchHeader + '"'); + cmStrCat('"', pchHeader, '"')); cmSystemTools::ReplaceString(createOptionList, "", - '"' + pchFile + '"'); + cmStrCat('"', pchFile, '"')); } else { cmSystemTools::ReplaceString(createOptionList, "", pchHeader); @@ -3320,9 +3325,9 @@ std::string cmGeneratorTarget::GetPchUseCompileOptions( if (GlobalGenerator->IsFastbuild()) { // Account for potential spaces in a shell-friendly way. cmSystemTools::ReplaceString(useOptionList, "", - '"' + pchHeader + '"'); + cmStrCat('"', pchHeader, '"')); cmSystemTools::ReplaceString(useOptionList, "", - '"' + pchFile + '"'); + cmStrCat('"', pchFile, '"')); } else { cmSystemTools::ReplaceString(useOptionList, "", pchHeader); cmSystemTools::ReplaceString(useOptionList, "", pchFile); @@ -4021,7 +4026,7 @@ std::string cmGeneratorTarget::GetPDBOutputName( // from the above block. this->LocalGenerator->GetCMakeInstance()->IssueMessage( MessageType::FATAL_ERROR, - "Target '" + this->GetName() + "' PDB_NAME depends on itself.", + cmStrCat("Target '", this->GetName(), "' PDB_NAME depends on itself."), this->GetBacktrace()); } return i->second; @@ -4541,7 +4546,8 @@ cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo( // from the above block. this->LocalGenerator->GetCMakeInstance()->IssueMessage( MessageType::FATAL_ERROR, - "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.", + cmStrCat("Target '", this->GetName(), + "' OUTPUT_DIRECTORY depends on itself."), this->GetBacktrace()); return nullptr; } @@ -6347,7 +6353,8 @@ std::string cmGeneratorTarget::GetSwiftModuleFileName() const if (this->GetPolicyStatusCMP0195() == cmPolicies::NEW) { if (cmValue moduleTriple = this->Makefile->GetDefinition("CMAKE_Swift_MODULE_TRIPLE")) { - moduleFilename += "/" + *moduleTriple + ".swiftmodule"; + moduleFilename = cmStrCat(std::move(moduleFilename), '/', *moduleTriple, + ".swiftmodule"); } } return moduleFilename; @@ -6383,8 +6390,8 @@ std::string cmGeneratorTarget::GetSwiftModuleDirectory( std::string cmGeneratorTarget::GetSwiftModulePath( std::string const& config) const { - return this->GetSwiftModuleDirectory(config) + "/" + - this->GetSwiftModuleFileName(); + return cmStrCat(this->GetSwiftModuleDirectory(config), '/', + this->GetSwiftModuleFileName()); } std::string cmGeneratorTarget::GetPropertyOrDefault( diff --git a/Source/cmGeneratorTarget_CompatibleInterface.cxx b/Source/cmGeneratorTarget_CompatibleInterface.cxx index 1c008f2732..2243cdd173 100644 --- a/Source/cmGeneratorTarget_CompatibleInterface.cxx +++ b/Source/cmGeneratorTarget_CompatibleInterface.cxx @@ -679,8 +679,9 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt, if (propInitialized) { std::pair consistent = consistentProperty(propContent, ifacePropContent, t); - report += reportEntry; - report += compatibilityAgree(t, propContent != consistent.second); + report = + cmStrCat(std::move(report), reportEntry, + compatibilityAgree(t, propContent != consistent.second)); if (!consistent.first) { std::ostringstream e; e << "The INTERFACE_" << p << " property of \"" @@ -692,7 +693,7 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt, propContent = consistent.second; continue; } - report += reportEntry + "(Interface set)\n"; + report = cmStrCat(std::move(report), reportEntry, "(Interface set)\n"); propContent = ifacePropContent; propInitialized = true; } else { diff --git a/Source/cmGeneratorTarget_TransitiveProperty.cxx b/Source/cmGeneratorTarget_TransitiveProperty.cxx index ad64d99191..d20819b5c6 100644 --- a/Source/cmGeneratorTarget_TransitiveProperty.cxx +++ b/Source/cmGeneratorTarget_TransitiveProperty.cxx @@ -65,7 +65,7 @@ bool cmGeneratorTarget::MaybeHaveInterfaceProperty(std::string const& prop, cm::GenEx::Evaluation* eval, UseTo usage) const { - std::string const key = prop + '@' + eval->Context.Config; + std::string const key = cmStrCat(prop, '@', eval->Context.Config); auto i = this->MaybeInterfacePropertyExists.find(key); if (i == this->MaybeInterfacePropertyExists.end()) { // Insert an entry now in case there is a cycle. diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 9f34d60464..16e68fdde9 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -658,8 +658,9 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj) } else { std::vector customCommands; if (this->ComputeCustomCommandOrder(customCommands)) { - std::string message = "The custom commands for target [" + - this->GeneratorTarget->GetName() + "] had a cycle.\n"; + std::string message = + cmStrCat("The custom commands for target [", + this->GeneratorTarget->GetName(), "] had a cycle.\n"); cmSystemTools::Error(message); } else { /* Custom targets do not have a dependency on SOURCES files. diff --git a/Source/cmGlobalFastbuildGenerator.cxx b/Source/cmGlobalFastbuildGenerator.cxx index 77a6fb85b8..390b899cd4 100644 --- a/Source/cmGlobalFastbuildGenerator.cxx +++ b/Source/cmGlobalFastbuildGenerator.cxx @@ -699,7 +699,7 @@ std::string cmGlobalFastbuildGenerator::Quote(std::string const& str, std::string cmGlobalFastbuildGenerator::QuoteIfHasSpaces(std::string str) { if (str.find(' ') != std::string::npos) { - return '"' + str + '"'; + return cmStrCat('"', str, '"'); } return str; } @@ -976,7 +976,7 @@ void cmGlobalFastbuildGenerator::AddCompiler(std::string const& language, } // Calculate the root location of the compiler - std::string const variableString = "CMAKE_" + language + "_COMPILER"; + std::string const variableString = cmStrCat("CMAKE_", language, "_COMPILER"); std::string const compilerLocation = mf->GetSafeDefinition(variableString); if (compilerLocation.empty()) { return; @@ -992,15 +992,15 @@ void cmGlobalFastbuildGenerator::AddCompiler(std::string const& language, compilerDef.Name = FASTBUILD_COMPILER_PREFIX + language; compilerDef.Executable = compilerLocation; compilerDef.CmakeCompilerID = - mf->GetSafeDefinition("CMAKE_" + language + "_COMPILER_ID"); + mf->GetSafeDefinition(cmStrCat("CMAKE_", language, "_COMPILER_ID")); if (compilerDef.CmakeCompilerID == "Clang" && - mf->GetSafeDefinition("CMAKE_" + language + - "_COMPILER_FRONTEND_VARIANT") == "MSVC") { + mf->GetSafeDefinition(cmStrCat( + "CMAKE_", language, "_COMPILER_FRONTEND_VARIANT")) == "MSVC") { compilerDef.CmakeCompilerID = "Clang-cl"; } compilerDef.CmakeCompilerVersion = - mf->GetSafeDefinition("CMAKE_" + language + "_COMPILER_VERSION"); + mf->GetSafeDefinition(cmStrCat("CMAKE_", language, "_COMPILER_VERSION")); compilerDef.Language = language; cmExpandList(mf->GetSafeDefinition(FASTBUILD_COMPILER_EXTRA_FILES), @@ -1052,10 +1052,11 @@ void cmGlobalFastbuildGenerator::AddCompiler(std::string const& language, compilerDef.ExtraFiles.push_back("$Root$/vcruntime140.dll"); compilerDef.ExtraFiles.push_back( "$Root$/vcruntime140_1.dll"); // Required as of 16.5.1 (14.25.28610) - compilerDef.ExtraFiles.push_back("$Root$/" + i18nNum + "/clui.dll"); compilerDef.ExtraFiles.push_back( - "$Root$/" + i18nNum + "/mspft140ui.dll"); // Localized messages for - // static analysis + cmStrCat("$Root$/", i18nNum, "/clui.dll")); + compilerDef.ExtraFiles.push_back(cmStrCat( + "$Root$/", i18nNum, "/mspft140ui.dll")); // Localized messages for + // static analysis } // Visual Studio 15 (19.10 to 19.19) else if (cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL, diff --git a/Source/cmInstallExportGenerator.cxx b/Source/cmInstallExportGenerator.cxx index 4ba3f01b7a..88864390b5 100644 --- a/Source/cmInstallExportGenerator.cxx +++ b/Source/cmInstallExportGenerator.cxx @@ -246,5 +246,5 @@ void cmInstallExportGenerator::GenerateScriptActions(std::ostream& os, std::string cmInstallExportGenerator::GetDestinationFile() const { - return this->Destination + '/' + this->FileName; + return cmStrCat(this->Destination, '/', this->FileName); }