cmStrCat: combine neighboring arguments where possible

Found using the `cmstrcat-adjacent-literals` rule for `ast-grep`.
This commit is contained in:
Ben Boeckel
2025-05-15 19:11:41 +02:00
parent 483d13daf4
commit 23779057fd
26 changed files with 112 additions and 77 deletions
+4 -3
View File
@@ -848,9 +848,10 @@ void cmCursesMainForm::HandleInput()
curField, "HELPSTRING");
}
if (helpString) {
this->HelpMessage[1] =
cmStrCat("Current option is: ", curField, '\n',
"Help string for this option is: ", *helpString, '\n');
this->HelpMessage[1] = cmStrCat("Current option is: ", curField,
"\n"
"Help string for this option is: ",
*helpString, '\n');
} else {
this->HelpMessage[1] = "";
}
+1 -1
View File
@@ -237,7 +237,7 @@ bool cmAddLibraryCommand(std::vector<std::string> const& args,
"ADD_LIBRARY called with ",
(type == cmStateEnums::SHARED_LIBRARY ? "SHARED" : "MODULE"),
" option but the target platform does not support dynamic "
"linking. ",
"linking. "
"Building a STATIC library instead. This may lead to problems."));
CM_FALLTHROUGH;
case cmPolicies::OLD:
+3 -2
View File
@@ -77,8 +77,9 @@ bool cmAddSubDirectoryCommand(std::vector<std::string> const& args,
if (!cmSystemTools::IsSubDirectory(srcPath,
mf.GetCurrentSourceDirectory())) {
status.SetError(
cmStrCat("not given a binary directory but the given source ",
"directory \"", srcPath, "\" is not a subdirectory of \"",
cmStrCat("not given a binary directory but the given source "
"directory \"",
srcPath, "\" is not a subdirectory of \"",
mf.GetCurrentSourceDirectory(),
"\". When specifying an "
"out-of-tree source a binary directory must be explicitly "
+1 -1
View File
@@ -467,7 +467,7 @@ bool cmCMakeLanguageCommand(std::vector<cmListFileArgument> const& args,
if (!defer.Directory) {
return FatalError(status,
cmStrCat("DEFER DIRECTORY:\n "_s, dir,
"\nis not known. "_s,
"\nis not known. "
"It may not have been processed yet."_s));
}
} else if (expArgs[expArg] == "ID"_s) {
+3 -3
View File
@@ -626,7 +626,7 @@ cm::optional<cmPkgConfigResult> ImportPackage(
if (!cmPkgConfigResolver::CheckVersion(req.ver, ver)) {
warn_or_error(cmStrCat("Package '", package, "' version '", ver,
"' does not meet version requirement '",
req.ver.string(), "' ", "of '", req.parent, "'"),
req.ver.string(), "' of '", req.parent, "'"),
imEnv);
return {};
}
@@ -856,7 +856,7 @@ bool CheckPackageDependencies(
if (!cmPkgConfigResolver::CheckVersion(dep.VerReq, *ver)) {
warn_or_error(cmStrCat("Package '", dep.Name, "' version '", *ver,
"' does not meet version requirement '",
dep.VerReq.string(), "' ", "of '", name, "'"),
dep.VerReq.string(), "' of '", name, "'"),
imEnv);
return false;
}
@@ -869,7 +869,7 @@ bool CheckPackageDependencies(
if (!cmPkgConfigResolver::CheckVersion(dep.VerReq, ver)) {
warn_or_error(cmStrCat("Package '", dep.Name, "' version '", ver,
"' does not meet version requirement '",
dep.VerReq.string(), "' ", "of '", name, "'"),
dep.VerReq.string(), "' of '", name, "'"),
imEnv);
return false;
}
+4 -3
View File
@@ -1179,8 +1179,8 @@ void cmComputeLinkDepends::AddLinkEntries(
cmStrCat("Impossible to link target '", this->Target->GetName(),
"' because the link item '", entry.Item.Value,
"', specified with the group feature '", currentFeature,
'\'', ", has already occurred with the feature '",
groupFeature, '\'', ", which is not allowed."),
"', has already occurred with the feature '",
groupFeature, "', which is not allowed."),
this->Target->GetBacktrace());
continue;
}
@@ -1203,7 +1203,8 @@ void cmComputeLinkDepends::AddLinkEntries(
cmStrCat("Impossible to link target '", this->Target->GetName(),
"' because the link item '", entry.Item.Value,
"' is specified with the features '", itemFeature,
"' and '", entry.Feature, "'",
"' and '", entry.Feature,
"'"
", and both have an 'OVERRIDE' attribute that overrides "
"the other. Such cycles are not allowed."),
this->Target->GetBacktrace());
+2 -1
View File
@@ -125,7 +125,8 @@ bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f)
mf.IssueMessage(
MessageType::AUTHOR_WARNING,
cmStrCat(
data.Variable, " is set to incorrect value\n ", value, '\n',
data.Variable, " is set to incorrect value\n ", value,
"\n"
"See 'Help/dev/experimental.rst' in the source tree of this "
"version of CMake for documentation of the experimental feature "
"and the corresponding activation value. This project's code "
+2 -1
View File
@@ -407,7 +407,8 @@ bool cmExportCommand(std::vector<std::string> const& args,
case cmPolicies::WARN:
mf.IssueMessage(
MessageType::AUTHOR_WARNING,
cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0103), '\n',
cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0103),
"\n"
"export() command already specified for the file\n ",
arguments.Filename, "\nDid you miss 'APPEND' keyword?"));
CM_FALLTHROUGH;
+11 -7
View File
@@ -417,7 +417,8 @@ bool HandleStringsCommand(std::vector<std::string> const& args,
"CMAKE_POLICY_WARNING_CMP0159")) {
status.GetMakefile().IssueMessage(
MessageType::AUTHOR_WARNING,
cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0159), '\n',
cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0159),
"\n"
"For compatibility, CMake is leaving CMAKE_MATCH_<n> "
"unchanged."));
}
@@ -2131,8 +2132,9 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
if (!file.empty()) {
fout.open(file.c_str(), std::ios::binary);
if (!fout) {
status.SetError(cmStrCat("DOWNLOAD cannot open file for write\n",
" file: \"", file, '"'));
status.SetError(cmStrCat("DOWNLOAD cannot open file for write\n"
" file: \"",
file, '"'));
return false;
}
}
@@ -2330,8 +2332,9 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
std::string actualHash = hash->HashFile(file);
if (actualHash.empty()) {
status.SetError(cmStrCat("DOWNLOAD cannot compute hash on download\n",
" for file: \"", file, '"'));
status.SetError(cmStrCat("DOWNLOAD cannot compute hash on download\n"
" for file: \"",
file, '"'));
return false;
}
@@ -2990,8 +2993,9 @@ bool HandleLockCommand(std::vector<std::string> const& args,
} else {
status.GetMakefile().IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("expected DIRECTORY, RELEASE, GUARD, RESULT_VARIABLE or ",
"TIMEOUT\nbut got: \"", args[i], "\"."));
cmStrCat("expected DIRECTORY, RELEASE, GUARD, RESULT_VARIABLE or "
"TIMEOUT\nbut got: \"",
args[i], "\"."));
return false;
}
}
+1 -1
View File
@@ -357,7 +357,7 @@ bool HandleInMode(std::vector<std::string> const& args,
} else {
makefile.IssueMessage(MessageType::FATAL_ERROR,
cmStrCat("Unknown argument:\n", " ", arg, '\n'));
cmStrCat("Unknown argument:\n ", arg, '\n'));
return true;
}
}
+2 -1
View File
@@ -5770,7 +5770,8 @@ void cmGeneratorTarget::CheckCxxModuleStatus(std::string const& config) const
cmStrCat("The target named \"", this->GetName(),
"\" has C++ sources that may use modules, but modules are not "
"supported by this generator:\n ",
this->GetGlobalGenerator()->GetName(), '\n',
this->GetGlobalGenerator()->GetName(),
"\n"
"Modules are supported only by Ninja, Ninja Multi-Config, "
"and Visual Studio generators for VS 17.4 and newer. "
"See the cmake-cxxmodules(7) manual for details. "
+2 -3
View File
@@ -450,9 +450,8 @@ bool cmGeneratorTarget::VerifyLinkItemColons(LinkItemRole role,
e = cmStrCat(e, "The link interface of target \"", this->GetName(),
"\" contains");
}
e =
cmStrCat(e, ":\n ", item.AsStr(), "\n", "but the target was not found. ",
missingTargetPossibleReasons);
e = cmStrCat(e, ":\n ", item.AsStr(), "\nbut the target was not found. ",
missingTargetPossibleReasons);
cmListFileBacktrace backtrace = item.Backtrace;
if (backtrace.Empty()) {
backtrace = this->GetBacktrace();
+8 -5
View File
@@ -101,11 +101,14 @@ bool cmGlobalGhsMultiGenerator::SetGeneratorToolset(std::string const& ts,
/* check if the toolset changed from last generate */
if (cmNonempty(prevTool) && !cmSystemTools::ComparePath(gbuild, *prevTool)) {
std::string const& e = cmStrCat(
"toolset build tool: ", gbuild, '\n',
"Does not match the previously used build tool: ", *prevTool, '\n',
"Either remove the CMakeCache.txt file and CMakeFiles "
"directory or choose a different binary directory.");
std::string const& e =
cmStrCat("toolset build tool: ", gbuild,
"\n"
"Does not match the previously used build tool: ",
*prevTool,
"\n"
"Either remove the CMakeCache.txt file and CMakeFiles "
"directory or choose a different binary directory.");
mf->IssueMessage(MessageType::FATAL_ERROR, e);
return false;
}
+4 -2
View File
@@ -297,8 +297,10 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
this->GetPlatformToolsetString(),
",version=", this->GeneratorToolsetVersion,
"\n"
"has multiple matches installed at\n",
" ", auxProps, "\n",
"has multiple matches installed at\n"
" ",
auxProps,
"\n"
"The toolset and version specification must resolve \n"
"to a single installed toolset"));
+1 -1
View File
@@ -2264,7 +2264,7 @@ void cmGlobalXCodeGenerator::AddCommandsToBuildPhase(
cdir = cmSystemTools::ConvertToOutputPath(cdir);
std::string makecmd = cmStrCat(
"make -C ", cdir, " -f ", cmSystemTools::ConvertToOutputPath(makefile),
"$CONFIGURATION", " OBJDIR=$(basename \"$OBJECT_FILE_DIR_normal\") all");
"$CONFIGURATION OBJDIR=$(basename \"$OBJECT_FILE_DIR_normal\") all");
buildphase->AddAttribute("shellScript", this->CreateString(makecmd));
buildphase->AddAttribute("showEnvVarsInLog", this->CreateString("0"));
}
+2 -1
View File
@@ -1604,7 +1604,8 @@ bool HandleFilesMode(std::vector<std::string> const& args,
if (gg->IsExportedTargetsFile(file)) {
helper.Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("The file\n ", file, '\n',
cmStrCat("The file\n ", file,
"\n"
"was generated by the export() command. "
"It may not be installed with the install() command. "
"Use the install(EXPORT) mechanism instead. "
+6 -3
View File
@@ -594,8 +594,10 @@ std::string GetScanCommand(
cm::optional<cm::string_view> srcOrigFile = cm::nullopt)
{
return cmStrCat(cmakeCmd, " -E cmake_ninja_depends --tdi=", tdi,
" --lang=", lang, " --src=", srcFile, " --out=$out",
" --dep=$DEP_FILE --obj=$OBJ_FILE --ddi=", ddiFile,
" --lang=", lang, " --src=", srcFile,
" --out=$out"
" --dep=$DEP_FILE --obj=$OBJ_FILE --ddi=",
ddiFile,
srcOrigFile ? cmStrCat(" --src-orig=", *srcOrigFile) : "");
}
@@ -1299,7 +1301,8 @@ void cmNinjaTargetGenerator::GenerateSwiftOutputFileMap(
}();
std::string mapFilePath =
cmStrCat(this->GeneratorTarget->GetSupportDirectory(), '/', config, '/',
cmStrCat(this->GeneratorTarget->GetSupportDirectory(), '/', config,
"/"
"output-file-map.json");
// build the global target dependencies
+1 -1
View File
@@ -225,7 +225,7 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf,
MessageType::FATAL_ERROR,
cmStrCat("An attempt was made to set the policy version of CMake to \"",
version_min,
"\" which is greater than this version of CMake. ",
"\" which is greater than this version of CMake. "
"This is not allowed because the greater version may have new "
"policies not known to this CMake. "
"You may need a newer CMake version to build this project."));
+2 -2
View File
@@ -143,8 +143,8 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer(
"AUTOGEN: No valid Qt version found for target ",
target->GetName(), ". ",
cmQtAutoGen::Tools(mocDisabled, uicDisabled, rccDisabled),
" disabled. Consider adding:\n", " find_package(Qt", version,
" COMPONENTS ", component, ")\n", "to your CMakeLists.txt file.");
" disabled. Consider adding:\n find_package(Qt", version,
" COMPONENTS ", component, ")\nto your CMakeLists.txt file.");
target->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, msg);
}
if (mocIsValid || uicIsValid || rccIsValid) {
+7 -5
View File
@@ -1166,7 +1166,8 @@ bool cmQtAutoGenInitializer::InitScanFiles()
this->Makefile->IssueMessage(
MessageType::AUTHOR_WARNING,
cmStrCat(
cmPolicies::GetPolicyWarning(cmPolicies::CMP0071), '\n',
cmPolicies::GetPolicyWarning(cmPolicies::CMP0071),
"\n"
"For compatibility, CMake is excluding the GENERATED source "
"file(s):\n",
files, "from processing by ",
@@ -1197,9 +1198,10 @@ bool cmQtAutoGenInitializer::InitScanFiles()
this->Makefile->IssueMessage(
MessageType::AUTHOR_WARNING,
cmStrCat(
cmPolicies::GetPolicyWarning(cmPolicies::CMP0100), '\n',
"For compatibility, CMake is excluding the header file(s):\n", files,
"from processing by ",
cmPolicies::GetPolicyWarning(cmPolicies::CMP0100),
"\n"
"For compatibility, CMake is excluding the header file(s):\n",
files, "from processing by ",
cmQtAutoGen::Tools(this->Moc.Enabled, this->Uic.Enabled, false),
". If any of the files should be processed, set CMP0100 to NEW. "
"If any of the files should not be processed, "
@@ -1233,7 +1235,7 @@ bool cmQtAutoGenInitializer::InitScanFiles()
if (this->MultiConfig && !this->GlobalGen->IsXcode() &&
this->UseBetterGraph) {
qrc.OutputFile = cmStrCat(this->Dir.Build, '/', qrc.QrcPathChecksum,
"_$<CONFIG>", "/qrc_", qrc.QrcName, ".cpp");
"_$<CONFIG>/qrc_", qrc.QrcName, ".cpp");
} else {
qrc.OutputFile = cmStrCat(this->Dir.Build, '/', qrc.QrcPathChecksum,
"/qrc_", qrc.QrcName, ".cpp");
+3 -3
View File
@@ -1302,7 +1302,7 @@ bool cmQtAutoMocUicT::JobEvalCacheMocT::EvalSource(
".\nRunning moc on the source\n ",
this->MessagePath(sourceFile.FileName), "!\nBetter include ",
this->MessagePath(sourceBase + ".moc"),
" for compatibility with regular mode.\n",
" for compatibility with regular mode.\n"
"This is a CMAKE_AUTOMOC_RELAXED_MODE warning.\n"));
// Create mapping
@@ -1370,7 +1370,7 @@ bool cmQtAutoMocUicT::JobEvalCacheMocT::EvalSource(
" macro.\nRunning moc on the header\n ",
this->MessagePath(headerHandle->FileName), "!\nBetter include ",
this->MessagePath("moc_" + incKey.Base + ".cpp"),
" for a compatibility with regular mode.\n",
" for a compatibility with regular mode.\n"
"This is a CMAKE_AUTOMOC_RELAXED_MODE warning.\n"));
} else {
this->Log().Warning(
@@ -1382,7 +1382,7 @@ bool cmQtAutoMocUicT::JobEvalCacheMocT::EvalSource(
".\nRunning moc on the header\n ",
this->MessagePath(headerHandle->FileName), "!\nBetter include ",
this->MessagePath("moc_" + incKey.Base + ".cpp"),
" for compatibility with regular mode.\n",
" for compatibility with regular mode.\n"
"This is a CMAKE_AUTOMOC_RELAXED_MODE warning.\n"));
}
// Create mapping
+3 -2
View File
@@ -511,8 +511,9 @@ bool cmQtAutoRccT::GenerateWrapper()
if (this->IsMultiConfig()) {
// Wrapper file content
std::string content =
cmStrCat("// This is an autogenerated configuration wrapper file.\n",
"// Changes will be overwritten.\n", "#include <",
cmStrCat("// This is an autogenerated configuration wrapper file.\n"
"// Changes will be overwritten.\n"
"#include <",
this->MultiConfigOutput(), ">\n");
// Compare with existing file content
+2 -1
View File
@@ -22,7 +22,8 @@ bool cmReturnCommand(std::vector<std::string> const& args,
status.GetMakefile().IssueMessage(
MessageType::AUTHOR_WARNING,
cmStrCat(
cmPolicies::GetPolicyWarning(cmPolicies::CMP0140), '\n',
cmPolicies::GetPolicyWarning(cmPolicies::CMP0140),
"\n"
"return() checks its arguments when the policy is set to NEW. "
"Since the policy is not set the OLD behavior will be used so "
"the arguments will be ignored."));
+1 -1
View File
@@ -429,7 +429,7 @@ bool TLL::HandleLibrary(ProcessingState currentProcessingState,
"Target \"", lib, "\" of type ",
cmState::GetTargetTypeName(tgt->GetType()),
" may not be linked into another target. One may link only to "
"INTERFACE, OBJECT, STATIC or SHARED libraries, or to ",
"INTERFACE, OBJECT, STATIC or SHARED libraries, or to "
"executables with the ENABLE_EXPORTS property set."));
}
+1 -1
View File
@@ -3450,7 +3450,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
if (configName == this->Configurations[0]) {
std::string message =
cmStrCat("For the target \"", this->GeneratorTarget->GetName(),
"\" the /clr compiler flag was added manually. ",
"\" the /clr compiler flag was added manually. "
"Set usage of C++/CLI by setting COMMON_LANGUAGE_RUNTIME "
"target property.");
this->Makefile->IssueMessage(MessageType::WARNING, message);
+35 -22
View File
@@ -2511,11 +2511,14 @@ int cmake::ActualConfigure()
cmValue genName = this->State->GetInitializedCacheValue("CMAKE_GENERATOR");
if (genName) {
if (!this->GlobalGenerator->MatchesGeneratorName(*genName)) {
std::string message = cmStrCat(
"Error: generator : ", this->GlobalGenerator->GetName(), '\n',
"Does not match the generator used previously: ", *genName, '\n',
"Either remove the CMakeCache.txt file and CMakeFiles "
"directory or choose a different binary directory.");
std::string message =
cmStrCat("Error: generator : ", this->GlobalGenerator->GetName(),
"\n"
"Does not match the generator used previously: ",
*genName,
"\n"
"Either remove the CMakeCache.txt file and CMakeFiles "
"directory or choose a different binary directory.");
cmSystemTools::Error(message);
return -2;
}
@@ -2541,11 +2544,14 @@ int cmake::ActualConfigure()
if (cmValue instance =
this->State->GetInitializedCacheValue("CMAKE_GENERATOR_INSTANCE")) {
if (this->GeneratorInstanceSet && this->GeneratorInstance != *instance) {
std::string message = cmStrCat(
"Error: generator instance: ", this->GeneratorInstance, '\n',
"Does not match the instance used previously: ", *instance, '\n',
"Either remove the CMakeCache.txt file and CMakeFiles "
"directory or choose a different binary directory.");
std::string message =
cmStrCat("Error: generator instance: ", this->GeneratorInstance,
"\n"
"Does not match the instance used previously: ",
*instance,
"\n"
"Either remove the CMakeCache.txt file and CMakeFiles "
"directory or choose a different binary directory.");
cmSystemTools::Error(message);
return -2;
}
@@ -2559,11 +2565,14 @@ int cmake::ActualConfigure()
this->State->GetInitializedCacheValue("CMAKE_GENERATOR_PLATFORM")) {
if (this->GeneratorPlatformSet &&
this->GeneratorPlatform != *platformName) {
std::string message = cmStrCat(
"Error: generator platform: ", this->GeneratorPlatform, '\n',
"Does not match the platform used previously: ", *platformName, '\n',
"Either remove the CMakeCache.txt file and CMakeFiles "
"directory or choose a different binary directory.");
std::string message =
cmStrCat("Error: generator platform: ", this->GeneratorPlatform,
"\n"
"Does not match the platform used previously: ",
*platformName,
"\n"
"Either remove the CMakeCache.txt file and CMakeFiles "
"directory or choose a different binary directory.");
cmSystemTools::Error(message);
return -2;
}
@@ -2576,8 +2585,11 @@ int cmake::ActualConfigure()
this->State->GetInitializedCacheValue("CMAKE_GENERATOR_TOOLSET")) {
if (this->GeneratorToolsetSet && this->GeneratorToolset != *tsName) {
std::string message =
cmStrCat("Error: generator toolset: ", this->GeneratorToolset, '\n',
"Does not match the toolset used previously: ", *tsName, '\n',
cmStrCat("Error: generator toolset: ", this->GeneratorToolset,
"\n"
"Does not match the toolset used previously: ",
*tsName,
"\n"
"Either remove the CMakeCache.txt file and CMakeFiles "
"directory or choose a different binary directory.");
cmSystemTools::Error(message);
@@ -2692,9 +2704,9 @@ int cmake::ActualConfigure()
if (this->Instrumentation->HasQuery()) {
std::string launcher;
if (mf->IsOn("CTEST_USE_LAUNCHERS")) {
launcher =
cmStrCat("\"", cmSystemTools::GetCTestCommand(), "\" --launch ",
"--current-build-dir <CMAKE_CURRENT_BINARY_DIR> ");
launcher = cmStrCat("\"", cmSystemTools::GetCTestCommand(),
"\" --launch "
"--current-build-dir <CMAKE_CURRENT_BINARY_DIR> ");
} else {
launcher =
cmStrCat("\"", cmSystemTools::GetCTestCommand(), "\" --instrument ");
@@ -2705,13 +2717,14 @@ int cmake::ActualConfigure()
this->State->SetGlobalProperty(
"RULE_LAUNCH_COMPILE",
cmStrCat(
launcher, "--command-type compile", common_args, "--config <CONFIG> ",
launcher, "--command-type compile", common_args,
"--config <CONFIG> "
"--output <OBJECT> --source <SOURCE> --language <LANGUAGE> -- "));
this->State->SetGlobalProperty(
"RULE_LAUNCH_LINK",
cmStrCat(
launcher, "--command-type link", common_args,
"--output <TARGET> --target-type <TARGET_TYPE> --config <CONFIG> ",
"--output <TARGET> --target-type <TARGET_TYPE> --config <CONFIG> "
"--language <LANGUAGE> --target-labels \"<TARGET_LABELS>\" -- "));
this->State->SetGlobalProperty(
"RULE_LAUNCH_CUSTOM",