From 0b74471d62944a25423e9e09c778fd604daea0f8 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 19 Jul 2023 16:29:45 -0400 Subject: cmCoreTryCompile: use `cmStrCat` where possible --- Source/cmCoreTryCompile.cxx | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 586db1b..adbcadd 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -479,11 +479,11 @@ cm::optional cmCoreTryCompile::TryCompileCode( std::map 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. @@ -655,7 +655,7 @@ cm::optional 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); if (cmValue rulesOverridePath = @@ -690,7 +690,7 @@ cm::optional 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 +794,10 @@ cm::optional 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 +965,7 @@ cm::optional 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 +1064,7 @@ cm::optional 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 +1082,7 @@ cm::optional 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 +1093,7 @@ cm::optional 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); } @@ -1204,10 +1204,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 +1220,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)) { -- cgit v0.12 From b8fd1cc8d9286d1045a86d138fb24544e359ede6 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 19 Jul 2023 16:27:26 -0400 Subject: cmCoreTryCompile: use single characters where possible --- Source/cmCoreTryCompile.cxx | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index adbcadd..9b67d7f 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 cmCoreTryCompile::TryCompileCode( this->Makefile->IssueMessage( MessageType::FATAL_ERROR, cmStrCat(" is not an absolute path:\n '", - *arguments.BinaryDirectory, "'")); + *arguments.BinaryDirectory, '\'')); return cm::nullopt; } this->BinaryDirectory = *arguments.BinaryDirectory; @@ -378,7 +378,7 @@ cm::optional 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()) { @@ -526,12 +526,12 @@ cm::optional 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, @@ -655,9 +655,9 @@ cm::optional cmCoreTryCompile::TryCompileCode( std::string projectLangs; for (std::string const& li : testLangs) { - projectLangs += cmStrCat(" ", 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(), @@ -794,7 +794,7 @@ cm::optional cmCoreTryCompile::TryCompileCode( } if (!targets.empty()) { - std::string fname = cmStrCat("/", targetName, "Targets.cmake"); + std::string fname = cmStrCat('/', targetName, "Targets.cmake"); cmExportTryCompileFileGenerator tcfg(gg, targets, this->Makefile, testLangs); tcfg.SetExportFile(cmStrCat(this->BinaryDirectory, fname).c_str()); @@ -965,7 +965,7 @@ cm::optional cmCoreTryCompile::TryCompileCode( if (arguments.LinkLibraries) { std::string libsToLink = " "; for (std::string const& i : *arguments.LinkLibraries) { - libsToLink += cmStrCat("\"", cmTrimWhitespace(i), "\" "); + libsToLink += cmStrCat('"', cmTrimWhitespace(i), "\" "); } fprintf(fout, "target_link_libraries(%s %s)\n", targetName.c_str(), libsToLink.c_str()); @@ -1082,7 +1082,7 @@ cm::optional cmCoreTryCompile::TryCompileCode( for (std::string const& var : vars) { if (cmValue val = this->Makefile->GetDefinition(var)) { - std::string flag = cmStrCat("-D", var, "=", *val); + std::string flag = cmStrCat("-D", var, '=', *val); arguments.CMakeFlags.emplace_back(std::move(flag)); cmakeVariables.emplace(var, *val); } @@ -1093,7 +1093,7 @@ cm::optional 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 = cmStrCat("-D", var, "=", "'", *val, "'"); + std::string flag = cmStrCat("-D", var, '=', '\'', *val, '\''); arguments.CMakeFlags.emplace_back(std::move(flag)); cmakeVariables.emplace(var, *val); } @@ -1207,7 +1207,7 @@ void cmCoreTryCompile::CleanupFiles(std::string const& binDir) cmSystemTools::Error(cmStrCat( "TRY_COMPILE attempt to remove -rf directory that does not contain " "CMakeTmp or CMakeScratch: \"", - binDir, "\"")); + binDir, '"')); return; } @@ -1220,7 +1220,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 = cmStrCat(binDir, "/", fileName); + std::string const fullPath = cmStrCat(binDir, '/', fileName); if (cmSystemTools::FileIsSymlink(fullPath)) { cmSystemTools::RemoveFile(fullPath); } else if (cmSystemTools::FileIsDirectory(fullPath)) { @@ -1304,12 +1304,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 = @@ -1320,7 +1320,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 {}; } -- cgit v0.12 From 884c47754543c8462e097093925da5b4c142a819 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 19 Jul 2023 16:30:48 -0400 Subject: cmCoreTryCompile: combine strings where possible --- Source/cmCoreTryCompile.cxx | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 9b67d7f..0a1ed30 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -555,10 +555,13 @@ cm::optional 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 langs; gg->GetEnabledLanguages(langs); err << cmJoin(langs, " "); @@ -587,7 +590,7 @@ cm::optional 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()); @@ -1093,7 +1096,7 @@ cm::optional 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 = cmStrCat("-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 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 */ -- cgit v0.12 From cfdb5c970c45b9e98d34ef72a036842f033d2cf8 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 19 Jul 2023 16:32:25 -0400 Subject: cmGlobalGenerator: use `cmStrCat` where possible --- Source/cmGlobalGenerator.cxx | 81 +++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 3d7d5a7..97cb737 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 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 }; @@ -2019,11 +2021,12 @@ void cmGlobalGenerator::CheckTargetProperties() notFoundVars += notFound.second; 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. -- cgit v0.12 From 2a74f641dbb6edb2468d836d9c0152e87f44957a Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 19 Jul 2023 16:32:33 -0400 Subject: cmGlobalGenerator: use single chars where possible --- Source/cmGlobalGenerator.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 97cb737..2ee56f1 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2019,7 +2019,7 @@ void cmGlobalGenerator::CheckTargetProperties() for (auto const& notFound : notFoundMap) { notFoundVars += notFound.first; notFoundVars += notFound.second; - notFoundVars += "\n"; + notFoundVars += '\n'; } cmSystemTools::Error( cmStrCat("The following variables are used in this project, " -- cgit v0.12 From e41ff26735dc03f2e34f414c59182c088dedca4b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 19 Jul 2023 16:32:50 -0400 Subject: cmMakefile: use `cmStrCat` where possible --- Source/cmMakefile.cxx | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index e1841b6..5483c2f 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; @@ -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; @@ -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; } } @@ -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; } @@ -3649,11 +3650,12 @@ void cmMakefile::EnableLanguage(std::vector 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, ", ")); + 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, ", "))); } } @@ -3698,8 +3700,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 +3930,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 +3989,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 +4001,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 +4041,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; -- cgit v0.12 From 4fd80d54196cdf4538d8620fb7b27b33d77d3374 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 19 Jul 2023 16:33:00 -0400 Subject: cmMakefile: use static string views in some locations --- Source/cmMakefile.cxx | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5483c2f..b29eca2 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -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; } @@ -2150,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; @@ -2521,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; } } @@ -2542,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; } } @@ -3648,8 +3648,7 @@ void cmMakefile::EnableLanguage(std::vector const& languages, } } if (!duplicate_languages.empty()) { - auto quantity = duplicate_languages.size() == 1 ? std::string(" has") - : std::string("s have"); + 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 " @@ -3666,7 +3665,7 @@ void cmMakefile::EnableLanguage(std::vector const& languages, std::vector 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); @@ -4159,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 keys; // get list of keys const auto* t = this; -- cgit v0.12 From faf36e65b9f8a35ac54eb082e8f371c2b5a1bbba Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 19 Jul 2023 16:38:34 -0400 Subject: cmMakefile: use single characters where possible --- Source/cmMakefile.cxx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index b29eca2..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 = - cmStrCat(lff.OriginalName(), " ", status.GetError()); + cmStrCat(lff.OriginalName(), ' ', status.GetError()); this->IssueMessage(MessageType::FATAL_ERROR, error); } result = false; @@ -2572,7 +2572,7 @@ cmMakefile::AppleSDK cmMakefile::GetAppleSDKType() const for (auto const& entry : sdkDatabase) { if (cmHasPrefix(sdkRoot, entry.name) || - sdkRoot.find(cmStrCat("/", entry.name)) != std::string::npos) { + sdkRoot.find(cmStrCat('/', entry.name)) != std::string::npos) { return entry.sdk; } } @@ -3154,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. @@ -3241,7 +3241,7 @@ MessageType cmMakefile::ExpandVariablesInStringNew( result.append(last, in - last); errorstr += cmStrCat("\') in a variable name: " "'", - result.substr(openstack.back().loc), "'"); + result.substr(openstack.back().loc), '\''); mtype = MessageType::FATAL_ERROR; error = true; } -- cgit v0.12