summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-07-21 13:39:54 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-07-21 13:40:09 (GMT)
commit71e0887ea2c893504a4309c62de9f4e7db587de6 (patch)
treecc610108f5c1afc750093efefea51b961e9359f1
parent4c9b0fe4321b17434d99eec28b6de12c286caf26 (diff)
parentfaf36e65b9f8a35ac54eb082e8f371c2b5a1bbba (diff)
downloadCMake-71e0887ea2c893504a4309c62de9f4e7db587de6.zip
CMake-71e0887ea2c893504a4309c62de9f4e7db587de6.tar.gz
CMake-71e0887ea2c893504a4309c62de9f4e7db587de6.tar.bz2
Merge topic 'cmstrcat-pass'
faf36e65b9 cmMakefile: use single characters where possible 4fd80d5419 cmMakefile: use static string views in some locations e41ff26735 cmMakefile: use `cmStrCat` where possible 2a74f641db cmGlobalGenerator: use single chars where possible cfdb5c970c cmGlobalGenerator: use `cmStrCat` where possible 884c477545 cmCoreTryCompile: combine strings where possible b8fd1cc8d9 cmCoreTryCompile: use single characters where possible 0b74471d62 cmCoreTryCompile: use `cmStrCat` where possible Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !8640
-rw-r--r--Source/cmCoreTryCompile.cxx70
-rw-r--r--Source/cmGlobalGenerator.cxx83
-rw-r--r--Source/cmMakefile.cxx72
3 files changed, 117 insertions, 108 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 586db1b..0a1ed30 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -232,7 +232,7 @@ Arguments cmCoreTryCompile::ParseArgs(
!unparsedArguments.empty()) {
std::string m = "Unknown arguments:";
for (const auto& i : unparsedArguments) {
- m = cmStrCat(m, "\n \"", i, "\"");
+ m = cmStrCat(m, "\n \"", i, '"');
}
this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, m);
}
@@ -346,7 +346,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("<bindir> is not an absolute path:\n '",
- *arguments.BinaryDirectory, "'"));
+ *arguments.BinaryDirectory, '\''));
return cm::nullopt;
}
this->BinaryDirectory = *arguments.BinaryDirectory;
@@ -378,7 +378,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
cmStrCat("Only libraries may be used as try_compile or try_run "
"IMPORTED LINK_LIBRARIES. Got ",
tgt->GetName(), " of type ",
- cmState::GetTargetTypeName(tgt->GetType()), "."));
+ cmState::GetTargetTypeName(tgt->GetType()), '.'));
return cm::nullopt;
}
if (tgt->IsImported()) {
@@ -479,11 +479,11 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
std::map<std::string, std::string> cmakeVariables;
- std::string outFileName = this->BinaryDirectory + "/CMakeLists.txt";
+ std::string outFileName = cmStrCat(this->BinaryDirectory, "/CMakeLists.txt");
// which signature are we using? If we are using var srcfile bindir
if (this->SrcFileSignature) {
// remove any CMakeCache.txt files so we will have a clean test
- std::string ccFile = this->BinaryDirectory + "/CMakeCache.txt";
+ std::string ccFile = cmStrCat(this->BinaryDirectory, "/CMakeCache.txt");
cmSystemTools::RemoveFile(ccFile);
// Choose sources.
@@ -526,12 +526,12 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
if (!cmSystemTools::GetFilenamePath(dst).empty()) {
const auto& msg =
- cmStrCat("SOURCE_FROM_FILE given invalid filename \"", dst, "\"");
+ cmStrCat("SOURCE_FROM_FILE given invalid filename \"", dst, '"');
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, msg);
return cm::nullopt;
}
- auto dstPath = cmStrCat(this->BinaryDirectory, "/", dst);
+ auto dstPath = cmStrCat(this->BinaryDirectory, '/', dst);
auto const result = cmSystemTools::CopyFileAlways(src, dstPath);
if (!result.IsSuccess()) {
const auto& msg = cmStrCat("SOURCE_FROM_FILE failed to copy \"", src,
@@ -555,10 +555,13 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
testLangs.insert(lang);
} else {
std::ostringstream err;
- err << "Unknown extension \"" << ext << "\" for file\n"
- << " " << si << "\n"
- << "try_compile() works only for enabled languages. "
- << "Currently these are:\n ";
+ err << "Unknown extension \"" << ext
+ << "\" for file\n"
+ " "
+ << si
+ << "\n"
+ "try_compile() works only for enabled languages. "
+ "Currently these are:\n ";
std::vector<std::string> langs;
gg->GetEnabledLanguages(langs);
err << cmJoin(langs, " ");
@@ -587,7 +590,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
std::ostringstream e;
/* clang-format off */
e << "Failed to open\n"
- << " " << outFileName << "\n"
+ " " << outFileName << "\n"
<< cmSystemTools::GetLastSystemError();
/* clang-format on */
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
@@ -655,9 +658,9 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
std::string projectLangs;
for (std::string const& li : testLangs) {
- projectLangs += " " + li;
+ projectLangs += cmStrCat(' ', li);
std::string rulesOverrideBase = "CMAKE_USER_MAKE_RULES_OVERRIDE";
- std::string rulesOverrideLang = cmStrCat(rulesOverrideBase, "_", li);
+ std::string rulesOverrideLang = cmStrCat(rulesOverrideBase, '_', li);
if (cmValue rulesOverridePath =
this->Makefile->GetDefinition(rulesOverrideLang)) {
fprintf(fout, "set(%s \"%s\")\n", rulesOverrideLang.c_str(),
@@ -690,7 +693,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
}
fprintf(fout, "set(CMAKE_VERBOSE_MAKEFILE 1)\n");
for (std::string const& li : testLangs) {
- std::string langFlags = "CMAKE_" + li + "_FLAGS";
+ std::string langFlags = cmStrCat("CMAKE_", li, "_FLAGS");
cmValue flags = this->Makefile->GetDefinition(langFlags);
fprintf(fout, "set(CMAKE_%s_FLAGS %s)\n", li.c_str(),
cmOutputConverter::EscapeForCMake(*flags).c_str());
@@ -794,10 +797,10 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
}
if (!targets.empty()) {
- std::string fname = "/" + std::string(targetName) + "Targets.cmake";
+ std::string fname = cmStrCat('/', targetName, "Targets.cmake");
cmExportTryCompileFileGenerator tcfg(gg, targets, this->Makefile,
testLangs);
- tcfg.SetExportFile((this->BinaryDirectory + fname).c_str());
+ tcfg.SetExportFile(cmStrCat(this->BinaryDirectory, fname).c_str());
tcfg.SetConfig(tcConfig);
if (!tcfg.GenerateImportFile()) {
@@ -965,7 +968,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
if (arguments.LinkLibraries) {
std::string libsToLink = " ";
for (std::string const& i : *arguments.LinkLibraries) {
- libsToLink += "\"" + cmTrimWhitespace(i) + "\" ";
+ libsToLink += cmStrCat('"', cmTrimWhitespace(i), "\" ");
}
fprintf(fout, "target_link_libraries(%s %s)\n", targetName.c_str(),
libsToLink.c_str());
@@ -1064,7 +1067,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
if (cmValue tcArchs = this->Makefile->GetDefinition(
kCMAKE_TRY_COMPILE_OSX_ARCHITECTURES)) {
vars.erase(kCMAKE_OSX_ARCHITECTURES);
- std::string flag = "-DCMAKE_OSX_ARCHITECTURES=" + *tcArchs;
+ std::string flag = cmStrCat("-DCMAKE_OSX_ARCHITECTURES=", *tcArchs);
arguments.CMakeFlags.emplace_back(std::move(flag));
cmakeVariables.emplace("CMAKE_OSX_ARCHITECTURES", *tcArchs);
}
@@ -1082,7 +1085,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
for (std::string const& var : vars) {
if (cmValue val = this->Makefile->GetDefinition(var)) {
- std::string flag = "-D" + var + "=" + *val;
+ std::string flag = cmStrCat("-D", var, '=', *val);
arguments.CMakeFlags.emplace_back(std::move(flag));
cmakeVariables.emplace(var, *val);
}
@@ -1093,7 +1096,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
// Forward the GHS variables to the inner project cache.
for (std::string const& var : ghs_platform_vars) {
if (cmValue val = this->Makefile->GetDefinition(var)) {
- std::string flag = "-D" + var + "=" + "'" + *val + "'";
+ std::string flag = cmStrCat("-D", var, "=\'", *val, '\'');
arguments.CMakeFlags.emplace_back(std::move(flag));
cmakeVariables.emplace(var, *val);
}
@@ -1155,11 +1158,11 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
}
/* clang-format off */
err = cmStrCat(
- "Cannot copy output executable\n",
- " '", this->OutputFile, "'\n",
- "to destination specified by COPY_FILE:\n",
- " '", copyFile, "'\n",
- "because:\n",
+ "Cannot copy output executable\n"
+ " '", this->OutputFile, "'\n"
+ "to destination specified by COPY_FILE:\n"
+ " '", copyFile, "'\n"
+ "because:\n"
" ", err, "\n",
this->FindErrorMessage);
/* clang-format on */
@@ -1204,10 +1207,10 @@ void cmCoreTryCompile::CleanupFiles(std::string const& binDir)
}
if (!IsTemporary(binDir)) {
- cmSystemTools::Error(
+ cmSystemTools::Error(cmStrCat(
"TRY_COMPILE attempt to remove -rf directory that does not contain "
- "CMakeTmp or CMakeScratch: \"" +
- binDir + "\"");
+ "CMakeTmp or CMakeScratch: \"",
+ binDir, '"'));
return;
}
@@ -1220,8 +1223,7 @@ void cmCoreTryCompile::CleanupFiles(std::string const& binDir)
// Do not delete NFS temporary files.
!cmHasPrefix(fileName, ".nfs")) {
if (deletedFiles.insert(fileName).second) {
- std::string const fullPath =
- std::string(binDir).append("/").append(fileName);
+ std::string const fullPath = cmStrCat(binDir, '/', fileName);
if (cmSystemTools::FileIsSymlink(fullPath)) {
cmSystemTools::RemoveFile(fullPath);
} else if (cmSystemTools::FileIsDirectory(fullPath)) {
@@ -1305,12 +1307,12 @@ std::string cmCoreTryCompile::WriteSource(std::string const& filename,
{
if (!cmSystemTools::GetFilenamePath(filename).empty()) {
const auto& msg =
- cmStrCat(command, " given invalid filename \"", filename, "\"");
+ cmStrCat(command, " given invalid filename \"", filename, '"');
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, msg);
return {};
}
- auto filepath = cmStrCat(this->BinaryDirectory, "/", filename);
+ auto filepath = cmStrCat(this->BinaryDirectory, '/', filename);
cmsys::ofstream file{ filepath.c_str(), std::ios::out };
if (!file) {
const auto& msg =
@@ -1321,7 +1323,7 @@ std::string cmCoreTryCompile::WriteSource(std::string const& filename,
file << content;
if (!file) {
- const auto& msg = cmStrCat(command, " failed to write \"", filename, "\"");
+ const auto& msg = cmStrCat(command, " failed to write \"", filename, '"');
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, msg);
return {};
}
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 3d7d5a7..2ee56f1 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -239,7 +239,8 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string& lang,
if (!mf->GetDefinition(langComp)) {
if (!optional) {
- cmSystemTools::Error(langComp + " not set, after EnableLanguage");
+ cmSystemTools::Error(
+ cmStrCat(langComp, " not set, after EnableLanguage"));
}
return;
}
@@ -636,11 +637,10 @@ void cmGlobalGenerator::EnableLanguage(
#if defined(_WIN32) && !defined(__CYGWIN__)
cmSystemTools::WindowsVersion windowsVersion =
cmSystemTools::GetWindowsVersion();
- std::ostringstream windowsVersionString;
- windowsVersionString << windowsVersion.dwMajorVersion << "."
- << windowsVersion.dwMinorVersion << "."
- << windowsVersion.dwBuildNumber;
- mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION", windowsVersionString.str());
+ auto windowsVersionString = cmStrCat(windowsVersion.dwMajorVersion, '.',
+ windowsVersion.dwMinorVersion, '.',
+ windowsVersion.dwBuildNumber);
+ mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION", windowsVersionString);
#endif
// Read the DetermineSystem file
std::string systemFile = mf->GetModulesFile("CMakeDetermineSystem.cmake");
@@ -695,22 +695,22 @@ void cmGlobalGenerator::EnableLanguage(
setupFile, mf->GetCurrentSourceDirectory());
if (!cmSystemTools::FileExists(absSetupFile)) {
cmSystemTools::Error(
- "CMAKE_PROJECT_TOP_LEVEL_INCLUDES file does not exist: " +
- setupFile);
+ cmStrCat("CMAKE_PROJECT_TOP_LEVEL_INCLUDES file does not exist: ",
+ setupFile));
mf->GetState()->SetInTopLevelIncludes(false);
return;
}
if (cmSystemTools::FileIsDirectory(absSetupFile)) {
cmSystemTools::Error(
- "CMAKE_PROJECT_TOP_LEVEL_INCLUDES file is a directory: " +
- setupFile);
+ cmStrCat("CMAKE_PROJECT_TOP_LEVEL_INCLUDES file is a directory: ",
+ setupFile));
mf->GetState()->SetInTopLevelIncludes(false);
return;
}
if (!mf->ReadListFile(absSetupFile)) {
cmSystemTools::Error(
- "Failed reading CMAKE_PROJECT_TOP_LEVEL_INCLUDES file: " +
- setupFile);
+ cmStrCat("Failed reading CMAKE_PROJECT_TOP_LEVEL_INCLUDES file: ",
+ setupFile));
mf->GetState()->SetInTopLevelIncludes(false);
return;
}
@@ -754,7 +754,8 @@ void cmGlobalGenerator::EnableLanguage(
// to avoid duplicate compiler tests.
if (cmSystemTools::FileExists(fpath)) {
if (!mf->ReadListFile(fpath)) {
- cmSystemTools::Error("Could not find cmake module file: " + fpath);
+ cmSystemTools::Error(
+ cmStrCat("Could not find cmake module file: ", fpath));
}
// if this file was found then the language was already determined
// to be working
@@ -778,8 +779,8 @@ void cmGlobalGenerator::EnableLanguage(
cmStrCat("CMakeDetermine", lang, "Compiler.cmake");
std::string determineFile = mf->GetModulesFile(determineCompiler);
if (!mf->ReadListFile(determineFile)) {
- cmSystemTools::Error("Could not find cmake module file: " +
- determineCompiler);
+ cmSystemTools::Error(
+ cmStrCat("Could not find cmake module file: ", determineCompiler));
}
if (cmSystemTools::GetFatalErrorOccurred()) {
return;
@@ -807,7 +808,8 @@ void cmGlobalGenerator::EnableLanguage(
// configures CMake(LANG)Compiler.cmake
fpath = cmStrCat(rootBin, "/CMake", lang, "Compiler.cmake");
if (!mf->ReadListFile(fpath)) {
- cmSystemTools::Error("Could not find cmake module file: " + fpath);
+ cmSystemTools::Error(
+ cmStrCat("Could not find cmake module file: ", fpath));
}
this->SetLanguageEnabledFlag(lang, mf);
needSetLanguageEnabledMaps[lang] = true;
@@ -890,10 +892,11 @@ void cmGlobalGenerator::EnableLanguage(
fpath = cmStrCat("CMake", lang, "Information.cmake");
std::string informationFile = mf->GetModulesFile(fpath);
if (informationFile.empty()) {
- cmSystemTools::Error("Could not find cmake module file: " + fpath);
+ cmSystemTools::Error(
+ cmStrCat("Could not find cmake module file: ", fpath));
} else if (!mf->ReadListFile(informationFile)) {
- cmSystemTools::Error("Could not process cmake module file: " +
- informationFile);
+ cmSystemTools::Error(
+ cmStrCat("Could not process cmake module file: ", informationFile));
}
}
if (needSetLanguageEnabledMaps[lang]) {
@@ -911,8 +914,8 @@ void cmGlobalGenerator::EnableLanguage(
std::string testLang = cmStrCat("CMakeTest", lang, "Compiler.cmake");
std::string ifpath = mf->GetModulesFile(testLang);
if (!mf->ReadListFile(ifpath)) {
- cmSystemTools::Error("Could not find cmake module file: " +
- testLang);
+ cmSystemTools::Error(
+ cmStrCat("Could not find cmake module file: ", testLang));
}
std::string compilerWorks =
cmStrCat("CMAKE_", lang, "_COMPILER_WORKS");
@@ -977,7 +980,7 @@ void cmGlobalGenerator::PrintCompilerAdvice(std::ostream& os,
void cmGlobalGenerator::CheckCompilerIdCompatibility(
cmMakefile* mf, std::string const& lang) const
{
- std::string compilerIdVar = "CMAKE_" + lang + "_COMPILER_ID";
+ std::string compilerIdVar = cmStrCat("CMAKE_", lang, "_COMPILER_ID");
std::string const compilerId = mf->GetSafeDefinition(compilerIdVar);
if (compilerId == "AppleClang") {
@@ -1105,9 +1108,9 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility(
}
{
// Fix compiler versions.
- std::string version = "CMAKE_" + lang + "_COMPILER_VERSION";
- std::string emulated = "CMAKE_" + lang + "_SIMULATE_VERSION";
- std::string emulatedId = "CMAKE_" + lang + "_SIMULATE_ID";
+ std::string version = cmStrCat("CMAKE_", lang, "_COMPILER_VERSION");
+ std::string emulated = cmStrCat("CMAKE_", lang, "_SIMULATE_VERSION");
+ std::string emulatedId = cmStrCat("CMAKE_", lang, "_SIMULATE_ID");
std::string const& actual = mf->GetRequiredDefinition(emulated);
mf->AddDefinition(version, actual);
mf->RemoveDefinition(emulatedId);
@@ -1208,7 +1211,7 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
return;
}
- std::string linkerPrefVar = "CMAKE_" + l + "_LINKER_PREFERENCE";
+ std::string linkerPrefVar = cmStrCat("CMAKE_", l, "_LINKER_PREFERENCE");
cmValue linkerPref = mf->GetDefinition(linkerPrefVar);
int preference = 0;
if (cmNonempty(linkerPref)) {
@@ -1234,7 +1237,7 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
this->LanguageToLinkerPreference[l] = preference;
- std::string outputExtensionVar = "CMAKE_" + l + "_OUTPUT_EXTENSION";
+ std::string outputExtensionVar = cmStrCat("CMAKE_", l, "_OUTPUT_EXTENSION");
if (cmValue p = mf->GetDefinition(outputExtensionVar)) {
std::string outputExtension = *p;
this->LanguageToOutputExtension[l] = outputExtension;
@@ -1251,7 +1254,7 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
this->FillExtensionToLanguageMap(l, mf);
std::string ignoreExtensionsVar =
- std::string("CMAKE_") + std::string(l) + std::string("_IGNORE_EXTENSIONS");
+ cmStrCat("CMAKE_", l, "_IGNORE_EXTENSIONS");
std::string ignoreExts = mf->GetSafeDefinition(ignoreExtensionsVar);
cmList extensionList{ ignoreExts };
for (std::string const& i : extensionList) {
@@ -1262,8 +1265,7 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
void cmGlobalGenerator::FillExtensionToLanguageMap(const std::string& l,
cmMakefile* mf)
{
- std::string extensionsVar = std::string("CMAKE_") + std::string(l) +
- std::string("_SOURCE_FILE_EXTENSIONS");
+ std::string extensionsVar = cmStrCat("CMAKE_", l, "_SOURCE_FILE_EXTENSIONS");
const std::string& exts = mf->GetSafeDefinition(extensionsVar);
cmList extensionList{ exts };
for (std::string const& i : extensionList) {
@@ -1886,7 +1888,7 @@ void cmGlobalGenerator::FinalizeTargetConfiguration()
std::set<std::string> standardIncludesSet;
for (std::string const& li : langs) {
std::string const standardIncludesVar =
- "CMAKE_" + li + "_STANDARD_INCLUDE_DIRECTORIES";
+ cmStrCat("CMAKE_", li, "_STANDARD_INCLUDE_DIRECTORIES");
std::string const& standardIncludesStr =
mf->GetSafeDefinition(standardIncludesVar);
cmList standardIncludesList{ standardIncludesStr };
@@ -2017,13 +2019,14 @@ void cmGlobalGenerator::CheckTargetProperties()
for (auto const& notFound : notFoundMap) {
notFoundVars += notFound.first;
notFoundVars += notFound.second;
- notFoundVars += "\n";
+ notFoundVars += '\n';
}
- cmSystemTools::Error("The following variables are used in this project, "
- "but they are set to NOTFOUND.\n"
- "Please set them or make sure they are set and "
- "tested correctly in the CMake files:\n" +
- notFoundVars);
+ cmSystemTools::Error(
+ cmStrCat("The following variables are used in this project, "
+ "but they are set to NOTFOUND.\n"
+ "Please set them or make sure they are set and "
+ "tested correctly in the CMake files:\n",
+ notFoundVars));
}
}
@@ -2181,8 +2184,8 @@ int cmGlobalGenerator::Build(
outputflag, timeout)) {
cmSystemTools::SetRunCommandHideConsole(hideconsole);
cmSystemTools::Error(
- "Generator: execution of make failed. Make command was: " +
- makeCommandStr);
+ cmStrCat("Generator: execution of make failed. Make command was: ",
+ makeCommandStr));
ostr << *outputPtr
<< "\nGenerator: execution of make failed. Make command was: "
<< outputMakeCommandStr << std::endl;
@@ -3342,7 +3345,7 @@ void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target)
// Place the labels file in a per-target support directory.
std::string dir = target->GetSupportDirectory();
std::string file = cmStrCat(dir, "/Labels.txt");
- std::string json_file = dir + "/Labels.json";
+ std::string json_file = cmStrCat(dir, "/Labels.json");
#ifndef CMAKE_BOOTSTRAP
// Check whether labels are enabled for this target.
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index e1841b6..16a5188 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -515,7 +515,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
if (!hadNestedError) {
// The command invocation requested that we report an error.
std::string const error =
- std::string(lff.OriginalName()) + " " + status.GetError();
+ cmStrCat(lff.OriginalName(), ' ', status.GetError());
this->IssueMessage(MessageType::FATAL_ERROR, error);
}
result = false;
@@ -1756,7 +1756,7 @@ void cmMakefile::Configure()
bool hasVersion = false;
// search for the right policy command
for (cmListFileFunction const& func : listFile.Functions) {
- if (func.LowerCaseName() == "cmake_minimum_required") {
+ if (func.LowerCaseName() == "cmake_minimum_required"_s) {
hasVersion = true;
break;
}
@@ -1803,7 +1803,7 @@ void cmMakefile::Configure()
bool hasProject = false;
// search for a project command
for (cmListFileFunction const& func : listFile.Functions) {
- if (func.LowerCaseName() == "project") {
+ if (func.LowerCaseName() == "project"_s) {
hasProject = true;
break;
}
@@ -1860,7 +1860,8 @@ void cmMakefile::ConfigureSubDirectory(cmMakefile* mf)
cmSystemTools::Message(msg);
}
- std::string const currentStartFile = currentStart + "/CMakeLists.txt";
+ std::string const currentStartFile =
+ cmStrCat(currentStart, "/CMakeLists.txt");
if (!cmSystemTools::FileExists(currentStartFile, true)) {
// The file is missing. Check policy CMP0014.
std::ostringstream e;
@@ -2149,11 +2150,11 @@ void cmMakefile::AddGlobalLinkInformation(cmTarget& target)
for (auto j = linkLibs.begin(); j != linkLibs.end(); ++j) {
std::string libraryName = *j;
cmTargetLinkLibraryType libType = GENERAL_LibraryType;
- if (libraryName == "optimized") {
+ if (libraryName == "optimized"_s) {
libType = OPTIMIZED_LibraryType;
++j;
libraryName = *j;
- } else if (libraryName == "debug") {
+ } else if (libraryName == "debug"_s) {
libType = DEBUG_LibraryType;
++j;
libraryName = *j;
@@ -2520,7 +2521,7 @@ bool cmMakefile::IsSet(const std::string& name) const
bool cmMakefile::PlatformIs32Bit() const
{
if (cmValue plat_abi = this->GetDefinition("CMAKE_INTERNAL_PLATFORM_ABI")) {
- if (*plat_abi == "ELF X32") {
+ if (*plat_abi == "ELF X32"_s) {
return false;
}
}
@@ -2541,7 +2542,7 @@ bool cmMakefile::PlatformIs64Bit() const
bool cmMakefile::PlatformIsx32() const
{
if (cmValue plat_abi = this->GetDefinition("CMAKE_INTERNAL_PLATFORM_ABI")) {
- if (*plat_abi == "ELF X32") {
+ if (*plat_abi == "ELF X32"_s) {
return true;
}
}
@@ -2571,7 +2572,7 @@ cmMakefile::AppleSDK cmMakefile::GetAppleSDKType() const
for (auto const& entry : sdkDatabase) {
if (cmHasPrefix(sdkRoot, entry.name) ||
- sdkRoot.find(std::string("/") + entry.name) != std::string::npos) {
+ sdkRoot.find(cmStrCat('/', entry.name)) != std::string::npos) {
return entry.sdk;
}
}
@@ -3153,15 +3154,15 @@ MessageType cmMakefile::ExpandVariablesInStringNew(
char nextc = *next;
if (nextc == 't') {
result.append(last, in - last);
- result.append("\t");
+ result.push_back('\t');
last = next + 1;
} else if (nextc == 'n') {
result.append(last, in - last);
- result.append("\n");
+ result.push_back('\n');
last = next + 1;
} else if (nextc == 'r') {
result.append(last, in - last);
- result.append("\r");
+ result.push_back('\r');
last = next + 1;
} else if (nextc == ';' && openstack.empty()) {
// Handled in ExpandListArgument; pass the backslash literally.
@@ -3238,9 +3239,9 @@ MessageType cmMakefile::ExpandVariablesInStringNew(
errorstr += "Invalid character (\'";
errorstr += inc;
result.append(last, in - last);
- errorstr += "\') in a variable name: "
- "'" +
- result.substr(openstack.back().loc) + "'";
+ errorstr += cmStrCat("\') in a variable name: "
+ "'",
+ result.substr(openstack.back().loc), '\'');
mtype = MessageType::FATAL_ERROR;
error = true;
}
@@ -3647,13 +3648,13 @@ void cmMakefile::EnableLanguage(std::vector<std::string> const& languages,
}
}
if (!duplicate_languages.empty()) {
- auto quantity = duplicate_languages.size() == 1 ? std::string(" has")
- : std::string("s have");
- this->IssueMessage(MessageType::AUTHOR_WARNING,
- "Languages to be enabled may not be specified more "
- "than once at the same time. The following language" +
- quantity + " been specified multiple times: " +
- cmJoin(duplicate_languages, ", "));
+ auto quantity = duplicate_languages.size() == 1 ? " has"_s : "s have"_s;
+ this->IssueMessage(
+ MessageType::AUTHOR_WARNING,
+ cmStrCat("Languages to be enabled may not be specified more "
+ "than once at the same time. The following language",
+ quantity, " been specified multiple times: ",
+ cmJoin(duplicate_languages, ", ")));
}
}
@@ -3664,7 +3665,7 @@ void cmMakefile::EnableLanguage(std::vector<std::string> const& languages,
std::vector<std::string> languages_for_RC;
languages_without_RC.reserve(unique_languages.size());
for (std::string const& language : unique_languages) {
- if (language == "RC") {
+ if (language == "RC"_s) {
languages_for_RC.push_back(language);
} else {
languages_without_RC.push_back(language);
@@ -3698,8 +3699,9 @@ int cmMakefile::TryCompile(const std::string& srcdir,
cmWorkingDirectory workdir(bindir);
if (workdir.Failed()) {
this->IssueMessage(MessageType::FATAL_ERROR,
- "Failed to set working directory to " + bindir + " : " +
- std::strerror(workdir.GetLastResult()));
+ cmStrCat("Failed to set working directory to ", bindir,
+ " : ",
+ std::strerror(workdir.GetLastResult())));
cmSystemTools::SetFatalErrorOccurred();
this->IsSourceFileTryCompile = false;
return 1;
@@ -3927,7 +3929,7 @@ std::string cmMakefile::GetModulesFile(const std::string& filename,
if (!moduleInCMakeModulePath.empty() && !moduleInCMakeRoot.empty()) {
cmValue currentFile = this->GetDefinition("CMAKE_CURRENT_LIST_FILE");
- std::string mods = cmSystemTools::GetCMakeRoot() + "/Modules/";
+ std::string mods = cmStrCat(cmSystemTools::GetCMakeRoot(), "/Modules/");
if (currentFile && cmSystemTools::IsSubDirectory(*currentFile, mods)) {
switch (this->GetPolicyStatus(cmPolicies::CMP0017)) {
case cmPolicies::WARN: {
@@ -3986,8 +3988,9 @@ void cmMakefile::ConfigureString(const std::string& input, std::string& output,
cmValue def = this->GetDefinition(this->cmDefineRegex.match(2));
if (!cmIsOff(def)) {
const std::string indentation = this->cmDefineRegex.match(1);
- cmSystemTools::ReplaceString(line, "#" + indentation + "cmakedefine",
- "#" + indentation + "define");
+ cmSystemTools::ReplaceString(line,
+ cmStrCat("#", indentation, "cmakedefine"),
+ cmStrCat("#", indentation, "define"));
output += line;
} else {
output += "/* #undef ";
@@ -3997,8 +4000,9 @@ void cmMakefile::ConfigureString(const std::string& input, std::string& output,
} else if (this->cmDefine01Regex.find(line)) {
const std::string indentation = this->cmDefine01Regex.match(1);
cmValue def = this->GetDefinition(this->cmDefine01Regex.match(2));
- cmSystemTools::ReplaceString(line, "#" + indentation + "cmakedefine01",
- "#" + indentation + "define");
+ cmSystemTools::ReplaceString(line,
+ cmStrCat("#", indentation, "cmakedefine01"),
+ cmStrCat("#", indentation, "define"));
output += line;
if (!cmIsOff(def)) {
output += " 1";
@@ -4036,12 +4040,12 @@ int cmMakefile::ConfigureFile(const std::string& infile,
{
int res = 1;
if (!this->CanIWriteThisFile(outfile)) {
- cmSystemTools::Error("Attempt to write file: " + outfile +
- " into a source directory.");
+ cmSystemTools::Error(cmStrCat("Attempt to write file: ", outfile,
+ " into a source directory."));
return 0;
}
if (!cmSystemTools::FileExists(infile)) {
- cmSystemTools::Error("File " + infile + " does not exist.");
+ cmSystemTools::Error(cmStrCat("File ", infile, " does not exist."));
return 0;
}
std::string soutfile = outfile;
@@ -4154,7 +4158,7 @@ cmValue cmMakefile::GetProperty(const std::string& prop) const
{
// Check for computed properties.
static std::string output;
- if (prop == "TESTS") {
+ if (prop == "TESTS"_s) {
std::vector<std::string> keys;
// get list of keys
const auto* t = this;