cmGlobalGenerator: use cmStrCat where possible

This commit is contained in:
Ben Boeckel
2023-07-19 16:32:25 -04:00
parent 884c477545
commit cfdb5c970c

View File

@@ -239,7 +239,8 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string& lang,
if (!mf->GetDefinition(langComp)) { if (!mf->GetDefinition(langComp)) {
if (!optional) { if (!optional) {
cmSystemTools::Error(langComp + " not set, after EnableLanguage"); cmSystemTools::Error(
cmStrCat(langComp, " not set, after EnableLanguage"));
} }
return; return;
} }
@@ -636,11 +637,10 @@ void cmGlobalGenerator::EnableLanguage(
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
cmSystemTools::WindowsVersion windowsVersion = cmSystemTools::WindowsVersion windowsVersion =
cmSystemTools::GetWindowsVersion(); cmSystemTools::GetWindowsVersion();
std::ostringstream windowsVersionString; auto windowsVersionString = cmStrCat(windowsVersion.dwMajorVersion, '.',
windowsVersionString << windowsVersion.dwMajorVersion << "." windowsVersion.dwMinorVersion, '.',
<< windowsVersion.dwMinorVersion << "." windowsVersion.dwBuildNumber);
<< windowsVersion.dwBuildNumber; mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION", windowsVersionString);
mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION", windowsVersionString.str());
#endif #endif
// Read the DetermineSystem file // Read the DetermineSystem file
std::string systemFile = mf->GetModulesFile("CMakeDetermineSystem.cmake"); std::string systemFile = mf->GetModulesFile("CMakeDetermineSystem.cmake");
@@ -695,22 +695,22 @@ void cmGlobalGenerator::EnableLanguage(
setupFile, mf->GetCurrentSourceDirectory()); setupFile, mf->GetCurrentSourceDirectory());
if (!cmSystemTools::FileExists(absSetupFile)) { if (!cmSystemTools::FileExists(absSetupFile)) {
cmSystemTools::Error( cmSystemTools::Error(
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES file does not exist: " + cmStrCat("CMAKE_PROJECT_TOP_LEVEL_INCLUDES file does not exist: ",
setupFile); setupFile));
mf->GetState()->SetInTopLevelIncludes(false); mf->GetState()->SetInTopLevelIncludes(false);
return; return;
} }
if (cmSystemTools::FileIsDirectory(absSetupFile)) { if (cmSystemTools::FileIsDirectory(absSetupFile)) {
cmSystemTools::Error( cmSystemTools::Error(
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES file is a directory: " + cmStrCat("CMAKE_PROJECT_TOP_LEVEL_INCLUDES file is a directory: ",
setupFile); setupFile));
mf->GetState()->SetInTopLevelIncludes(false); mf->GetState()->SetInTopLevelIncludes(false);
return; return;
} }
if (!mf->ReadListFile(absSetupFile)) { if (!mf->ReadListFile(absSetupFile)) {
cmSystemTools::Error( cmSystemTools::Error(
"Failed reading CMAKE_PROJECT_TOP_LEVEL_INCLUDES file: " + cmStrCat("Failed reading CMAKE_PROJECT_TOP_LEVEL_INCLUDES file: ",
setupFile); setupFile));
mf->GetState()->SetInTopLevelIncludes(false); mf->GetState()->SetInTopLevelIncludes(false);
return; return;
} }
@@ -754,7 +754,8 @@ void cmGlobalGenerator::EnableLanguage(
// to avoid duplicate compiler tests. // to avoid duplicate compiler tests.
if (cmSystemTools::FileExists(fpath)) { if (cmSystemTools::FileExists(fpath)) {
if (!mf->ReadListFile(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 // if this file was found then the language was already determined
// to be working // to be working
@@ -778,8 +779,8 @@ void cmGlobalGenerator::EnableLanguage(
cmStrCat("CMakeDetermine", lang, "Compiler.cmake"); cmStrCat("CMakeDetermine", lang, "Compiler.cmake");
std::string determineFile = mf->GetModulesFile(determineCompiler); std::string determineFile = mf->GetModulesFile(determineCompiler);
if (!mf->ReadListFile(determineFile)) { if (!mf->ReadListFile(determineFile)) {
cmSystemTools::Error("Could not find cmake module file: " + cmSystemTools::Error(
determineCompiler); cmStrCat("Could not find cmake module file: ", determineCompiler));
} }
if (cmSystemTools::GetFatalErrorOccurred()) { if (cmSystemTools::GetFatalErrorOccurred()) {
return; return;
@@ -807,7 +808,8 @@ void cmGlobalGenerator::EnableLanguage(
// configures CMake(LANG)Compiler.cmake // configures CMake(LANG)Compiler.cmake
fpath = cmStrCat(rootBin, "/CMake", lang, "Compiler.cmake"); fpath = cmStrCat(rootBin, "/CMake", lang, "Compiler.cmake");
if (!mf->ReadListFile(fpath)) { 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); this->SetLanguageEnabledFlag(lang, mf);
needSetLanguageEnabledMaps[lang] = true; needSetLanguageEnabledMaps[lang] = true;
@@ -890,10 +892,11 @@ void cmGlobalGenerator::EnableLanguage(
fpath = cmStrCat("CMake", lang, "Information.cmake"); fpath = cmStrCat("CMake", lang, "Information.cmake");
std::string informationFile = mf->GetModulesFile(fpath); std::string informationFile = mf->GetModulesFile(fpath);
if (informationFile.empty()) { 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)) { } else if (!mf->ReadListFile(informationFile)) {
cmSystemTools::Error("Could not process cmake module file: " + cmSystemTools::Error(
informationFile); cmStrCat("Could not process cmake module file: ", informationFile));
} }
} }
if (needSetLanguageEnabledMaps[lang]) { if (needSetLanguageEnabledMaps[lang]) {
@@ -911,8 +914,8 @@ void cmGlobalGenerator::EnableLanguage(
std::string testLang = cmStrCat("CMakeTest", lang, "Compiler.cmake"); std::string testLang = cmStrCat("CMakeTest", lang, "Compiler.cmake");
std::string ifpath = mf->GetModulesFile(testLang); std::string ifpath = mf->GetModulesFile(testLang);
if (!mf->ReadListFile(ifpath)) { if (!mf->ReadListFile(ifpath)) {
cmSystemTools::Error("Could not find cmake module file: " + cmSystemTools::Error(
testLang); cmStrCat("Could not find cmake module file: ", testLang));
} }
std::string compilerWorks = std::string compilerWorks =
cmStrCat("CMAKE_", lang, "_COMPILER_WORKS"); cmStrCat("CMAKE_", lang, "_COMPILER_WORKS");
@@ -977,7 +980,7 @@ void cmGlobalGenerator::PrintCompilerAdvice(std::ostream& os,
void cmGlobalGenerator::CheckCompilerIdCompatibility( void cmGlobalGenerator::CheckCompilerIdCompatibility(
cmMakefile* mf, std::string const& lang) const 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); std::string const compilerId = mf->GetSafeDefinition(compilerIdVar);
if (compilerId == "AppleClang") { if (compilerId == "AppleClang") {
@@ -1105,9 +1108,9 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility(
} }
{ {
// Fix compiler versions. // Fix compiler versions.
std::string version = "CMAKE_" + lang + "_COMPILER_VERSION"; std::string version = cmStrCat("CMAKE_", lang, "_COMPILER_VERSION");
std::string emulated = "CMAKE_" + lang + "_SIMULATE_VERSION"; std::string emulated = cmStrCat("CMAKE_", lang, "_SIMULATE_VERSION");
std::string emulatedId = "CMAKE_" + lang + "_SIMULATE_ID"; std::string emulatedId = cmStrCat("CMAKE_", lang, "_SIMULATE_ID");
std::string const& actual = mf->GetRequiredDefinition(emulated); std::string const& actual = mf->GetRequiredDefinition(emulated);
mf->AddDefinition(version, actual); mf->AddDefinition(version, actual);
mf->RemoveDefinition(emulatedId); mf->RemoveDefinition(emulatedId);
@@ -1208,7 +1211,7 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
return; return;
} }
std::string linkerPrefVar = "CMAKE_" + l + "_LINKER_PREFERENCE"; std::string linkerPrefVar = cmStrCat("CMAKE_", l, "_LINKER_PREFERENCE");
cmValue linkerPref = mf->GetDefinition(linkerPrefVar); cmValue linkerPref = mf->GetDefinition(linkerPrefVar);
int preference = 0; int preference = 0;
if (cmNonempty(linkerPref)) { if (cmNonempty(linkerPref)) {
@@ -1234,7 +1237,7 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
this->LanguageToLinkerPreference[l] = preference; 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)) { if (cmValue p = mf->GetDefinition(outputExtensionVar)) {
std::string outputExtension = *p; std::string outputExtension = *p;
this->LanguageToOutputExtension[l] = outputExtension; this->LanguageToOutputExtension[l] = outputExtension;
@@ -1251,7 +1254,7 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
this->FillExtensionToLanguageMap(l, mf); this->FillExtensionToLanguageMap(l, mf);
std::string ignoreExtensionsVar = std::string ignoreExtensionsVar =
std::string("CMAKE_") + std::string(l) + std::string("_IGNORE_EXTENSIONS"); cmStrCat("CMAKE_", l, "_IGNORE_EXTENSIONS");
std::string ignoreExts = mf->GetSafeDefinition(ignoreExtensionsVar); std::string ignoreExts = mf->GetSafeDefinition(ignoreExtensionsVar);
cmList extensionList{ ignoreExts }; cmList extensionList{ ignoreExts };
for (std::string const& i : extensionList) { for (std::string const& i : extensionList) {
@@ -1262,8 +1265,7 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
void cmGlobalGenerator::FillExtensionToLanguageMap(const std::string& l, void cmGlobalGenerator::FillExtensionToLanguageMap(const std::string& l,
cmMakefile* mf) cmMakefile* mf)
{ {
std::string extensionsVar = std::string("CMAKE_") + std::string(l) + std::string extensionsVar = cmStrCat("CMAKE_", l, "_SOURCE_FILE_EXTENSIONS");
std::string("_SOURCE_FILE_EXTENSIONS");
const std::string& exts = mf->GetSafeDefinition(extensionsVar); const std::string& exts = mf->GetSafeDefinition(extensionsVar);
cmList extensionList{ exts }; cmList extensionList{ exts };
for (std::string const& i : extensionList) { for (std::string const& i : extensionList) {
@@ -1886,7 +1888,7 @@ void cmGlobalGenerator::FinalizeTargetConfiguration()
std::set<std::string> standardIncludesSet; std::set<std::string> standardIncludesSet;
for (std::string const& li : langs) { for (std::string const& li : langs) {
std::string const standardIncludesVar = std::string const standardIncludesVar =
"CMAKE_" + li + "_STANDARD_INCLUDE_DIRECTORIES"; cmStrCat("CMAKE_", li, "_STANDARD_INCLUDE_DIRECTORIES");
std::string const& standardIncludesStr = std::string const& standardIncludesStr =
mf->GetSafeDefinition(standardIncludesVar); mf->GetSafeDefinition(standardIncludesVar);
cmList standardIncludesList{ standardIncludesStr }; cmList standardIncludesList{ standardIncludesStr };
@@ -2019,11 +2021,12 @@ void cmGlobalGenerator::CheckTargetProperties()
notFoundVars += notFound.second; notFoundVars += notFound.second;
notFoundVars += "\n"; notFoundVars += "\n";
} }
cmSystemTools::Error("The following variables are used in this project, " cmSystemTools::Error(
"but they are set to NOTFOUND.\n" cmStrCat("The following variables are used in this project, "
"Please set them or make sure they are set and " "but they are set to NOTFOUND.\n"
"tested correctly in the CMake files:\n" + "Please set them or make sure they are set and "
notFoundVars); "tested correctly in the CMake files:\n",
notFoundVars));
} }
} }
@@ -2181,8 +2184,8 @@ int cmGlobalGenerator::Build(
outputflag, timeout)) { outputflag, timeout)) {
cmSystemTools::SetRunCommandHideConsole(hideconsole); cmSystemTools::SetRunCommandHideConsole(hideconsole);
cmSystemTools::Error( cmSystemTools::Error(
"Generator: execution of make failed. Make command was: " + cmStrCat("Generator: execution of make failed. Make command was: ",
makeCommandStr); makeCommandStr));
ostr << *outputPtr ostr << *outputPtr
<< "\nGenerator: execution of make failed. Make command was: " << "\nGenerator: execution of make failed. Make command was: "
<< outputMakeCommandStr << std::endl; << outputMakeCommandStr << std::endl;
@@ -3342,7 +3345,7 @@ void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target)
// Place the labels file in a per-target support directory. // Place the labels file in a per-target support directory.
std::string dir = target->GetSupportDirectory(); std::string dir = target->GetSupportDirectory();
std::string file = cmStrCat(dir, "/Labels.txt"); 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 #ifndef CMAKE_BOOTSTRAP
// Check whether labels are enabled for this target. // Check whether labels are enabled for this target.