Merge topic 'various-refactorings'

8352a2d12f cmFileCommand.cxx: Optimize `cmStrCat()` calls
e2c9bb7f54 cmFindBase.cxx: Optimize `cmStrCat()` calls
16a1fa9e35 cmFindBase.cxx: Check `DebugMode` and exit early to reduce indentation
6751b3d9b4 cmLocalGenerator.cxx: Optimize `std::ostream::operator<<()` calls
11bf70f968 FindPackageHandleStandardArgs: Remove the unneeded symbol from the message

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !10013
This commit is contained in:
Brad King
2024-11-20 14:33:50 +00:00
committed by Kitware Robot
4 changed files with 82 additions and 85 deletions

View File

@@ -531,7 +531,7 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
endif()
endforeach()
set(COMPONENT_MSG "${FOUND_COMPONENTS_MSG} ${MISSING_COMPONENTS_MSG}")
string(APPEND DETAILS "[c${COMPONENT_MSG}]")
string(APPEND DETAILS "[${COMPONENT_MSG}]")
endif()
# version handling:

View File

@@ -1104,7 +1104,7 @@ bool HandleRPathChangeCommand(std::vector<std::string> const& args,
if (!cmSystemTools::ChangeRPath(file, *oldRPath, *newRPath,
removeEnvironmentRPath, &emsg, &changed)) {
status.SetError(cmStrCat("RPATH_CHANGE could not write new RPATH:\n ",
*newRPath, "\nto the file:\n ", file, "\n",
*newRPath, "\nto the file:\n ", file, '\n',
emsg));
success = false;
}
@@ -1159,7 +1159,7 @@ bool HandleRPathSetCommand(std::vector<std::string> const& args,
if (!cmSystemTools::SetRPath(file, *newRPath, &emsg, &changed)) {
status.SetError(cmStrCat("RPATH_SET could not write new RPATH:\n ",
*newRPath, "\nto the file:\n ", file, "\n",
*newRPath, "\nto the file:\n ", file, '\n',
emsg));
success = false;
}
@@ -1209,7 +1209,7 @@ bool HandleRPathRemoveCommand(std::vector<std::string> const& args,
if (!cmSystemTools::RemoveRPath(file, &emsg, &removed)) {
status.SetError(
cmStrCat("RPATH_REMOVE could not remove RPATH from file: \n ", file,
"\n", emsg));
'\n', emsg));
success = false;
}
if (success) {
@@ -1538,7 +1538,7 @@ bool HandleRename(std::vector<std::string> const& args,
break;
}
status.SetError(cmStrCat("RENAME failed to rename\n ", oldname, "\nto\n ",
newname, "\nbecause: ", err, "\n"));
newname, "\nbecause: ", err, '\n'));
return false;
}
@@ -1631,7 +1631,7 @@ bool HandleCopyFile(std::vector<std::string> const& args,
status.GetMakefile().AddDefinition(arguments.Result, err);
} else {
status.SetError(cmStrCat("COPY_FILE failed to copy\n ", oldname,
"\nto\n ", newname, "\nbecause: ", err, "\n"));
"\nto\n ", newname, "\nbecause: ", err, '\n'));
result = false;
}
}
@@ -1822,7 +1822,7 @@ public:
if (updated) {
status =
cmStrCat("[", this->Text, " ", this->CurrentPercentage, "% complete]");
cmStrCat('[', this->Text, ' ', this->CurrentPercentage, "% complete]");
}
return updated;
@@ -2334,7 +2334,7 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
"set environment variable CMAKE_TLS_VERIFY=0 to suppress it.");
}
status.GetMakefile().AddDefinition(
statusVar, cmStrCat(static_cast<int>(res), ";\"", std::move(m), "\""));
statusVar, cmStrCat(static_cast<int>(res), ";\"", std::move(m), '"'));
}
::curl_global_cleanup();
@@ -2735,7 +2735,7 @@ bool HandleUploadCommand(std::vector<std::string> const& args,
"set environment variable CMAKE_TLS_VERIFY=0 to suppress it.");
}
status.GetMakefile().AddDefinition(
statusVar, cmStrCat(static_cast<int>(res), ";\"", std::move(m), "\""));
statusVar, cmStrCat(static_cast<int>(res), ";\"", std::move(m), '"'));
}
::curl_global_cleanup();
@@ -3090,7 +3090,7 @@ bool HandleLockCommand(std::vector<std::string> const& args,
if (resultVariable.empty() && !fileLockResult.IsOk()) {
status.GetMakefile().IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("error locking file\n \"", path, "\"\n", result, "."));
cmStrCat("error locking file\n \"", path, "\"\n", result, '.'));
cmSystemTools::SetFatalErrorOccurred();
return false;
}
@@ -3339,7 +3339,7 @@ bool HandleGetRuntimeDependenciesCommand(std::vector<std::string> const& args,
platform)) {
status.SetError(
cmStrCat("GET_RUNTIME_DEPENDENCIES is not supported on system \"",
platform, "\""));
platform, '"'));
cmSystemTools::SetFatalErrorOccurred();
return false;
}
@@ -3406,7 +3406,7 @@ bool HandleGetRuntimeDependenciesCommand(std::vector<std::string> const& args,
parser.Parse(cmMakeRange(args).advance(1), &unrecognizedArguments);
auto argIt = unrecognizedArguments.begin();
if (argIt != unrecognizedArguments.end()) {
status.SetError(cmStrCat("Unrecognized argument: \"", *argIt, "\""));
status.SetError(cmStrCat("Unrecognized argument: \"", *argIt, '"'));
cmSystemTools::SetFatalErrorOccurred();
return false;
}
@@ -3538,7 +3538,7 @@ bool HandleConfigureCommand(std::vector<std::string> const& args,
auto argIt = unrecognizedArguments.begin();
if (argIt != unrecognizedArguments.end()) {
status.SetError(
cmStrCat("CONFIGURE Unrecognized argument: \"", *argIt, "\""));
cmStrCat("CONFIGURE Unrecognized argument: \"", *argIt, '"'));
cmSystemTools::SetFatalErrorOccurred();
return false;
}
@@ -3672,7 +3672,7 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args,
parser.Parse(cmMakeRange(args).advance(1), &unrecognizedArguments);
auto argIt = unrecognizedArguments.begin();
if (argIt != unrecognizedArguments.end()) {
status.SetError(cmStrCat("Unrecognized argument: \"", *argIt, "\""));
status.SetError(cmStrCat("Unrecognized argument: \"", *argIt, '"'));
cmSystemTools::SetFatalErrorOccurred();
return false;
}
@@ -3801,7 +3801,7 @@ bool HandleArchiveExtractCommand(std::vector<std::string> const& args,
parser.Parse(cmMakeRange(args).advance(1), &unrecognizedArguments);
auto argIt = unrecognizedArguments.begin();
if (argIt != unrecognizedArguments.end()) {
status.SetError(cmStrCat("Unrecognized argument: \"", *argIt, "\""));
status.SetError(cmStrCat("Unrecognized argument: \"", *argIt, '"'));
cmSystemTools::SetFatalErrorOccurred();
return false;
}
@@ -3826,7 +3826,7 @@ bool HandleArchiveExtractCommand(std::vector<std::string> const& args,
if (cmSystemTools::FileIsFullPath(parsedArgs.Destination)) {
destDir = parsedArgs.Destination;
} else {
destDir = cmStrCat(destDir, "/", parsedArgs.Destination);
destDir = cmStrCat(destDir, '/', parsedArgs.Destination);
}
if (!cmSystemTools::MakeDirectory(destDir)) {
@@ -3837,7 +3837,7 @@ bool HandleArchiveExtractCommand(std::vector<std::string> const& args,
if (!cmSystemTools::FileIsFullPath(inFile)) {
inFile =
cmStrCat(cmSystemTools::GetLogicalWorkingDirectory(), "/", inFile);
cmStrCat(cmSystemTools::GetLogicalWorkingDirectory(), '/', inFile);
}
}

View File

@@ -611,65 +611,62 @@ cmFindBaseDebugState::cmFindBaseDebugState(std::string commandName,
cmFindBaseDebugState::~cmFindBaseDebugState()
{
if (this->FindCommand->DebugMode) {
std::string buffer =
cmStrCat(this->CommandName, " called with the following settings:\n");
buffer += cmStrCat(" VAR: ", this->FindCommand->VariableName, "\n");
buffer += cmStrCat(
" NAMES: ", cmWrap("\"", this->FindCommand->Names, "\"", "\n "),
"\n");
buffer += cmStrCat(
" Documentation: ", this->FindCommand->VariableDocumentation, "\n");
buffer += " Framework\n";
buffer += cmStrCat(" Only Search Frameworks: ",
this->FindCommand->SearchFrameworkOnly, "\n");
buffer += cmStrCat(" Search Frameworks Last: ",
this->FindCommand->SearchFrameworkLast, "\n");
buffer += cmStrCat(" Search Frameworks First: ",
this->FindCommand->SearchFrameworkFirst, "\n");
buffer += " AppBundle\n";
buffer += cmStrCat(" Only Search AppBundle: ",
this->FindCommand->SearchAppBundleOnly, "\n");
buffer += cmStrCat(" Search AppBundle Last: ",
this->FindCommand->SearchAppBundleLast, "\n");
buffer += cmStrCat(" Search AppBundle First: ",
this->FindCommand->SearchAppBundleFirst, "\n");
if (this->FindCommand->NoDefaultPath) {
buffer += " NO_DEFAULT_PATH Enabled\n";
} else {
buffer += cmStrCat(
" CMAKE_FIND_USE_CMAKE_PATH: ", !this->FindCommand->NoCMakePath, "\n",
" CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: ",
!this->FindCommand->NoCMakeEnvironmentPath, "\n",
" CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: ",
!this->FindCommand->NoSystemEnvironmentPath, "\n",
" CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: ",
!this->FindCommand->NoCMakeSystemPath, "\n",
" CMAKE_FIND_USE_INSTALL_PREFIX: ",
!this->FindCommand->NoCMakeInstallPath, "\n");
}
buffer +=
cmStrCat(this->CommandName, " considered the following locations:\n");
for (auto const& state : this->FailedSearchLocations) {
std::string path = cmStrCat(" ", state.path);
if (!state.regexName.empty()) {
path = cmStrCat(path, "/", state.regexName);
}
buffer += cmStrCat(path, "\n");
}
if (!this->FoundSearchLocation.path.empty()) {
buffer += cmStrCat("The item was found at\n ",
this->FoundSearchLocation.path, "\n");
} else {
buffer += "The item was not found.\n";
}
this->FindCommand->DebugMessage(buffer);
if (!this->FindCommand->DebugMode) {
return;
}
// clang-format off
auto buffer =
cmStrCat(
this->CommandName, " called with the following settings:"
"\n VAR: ", this->FindCommand->VariableName,
"\n NAMES: ", cmWrap('"', this->FindCommand->Names, '"', "\n "),
"\n Documentation: ", this->FindCommand->VariableDocumentation,
"\n Framework"
"\n Only Search Frameworks: ", this->FindCommand->SearchFrameworkOnly,
"\n Search Frameworks Last: ", this->FindCommand->SearchFrameworkLast,
"\n Search Frameworks First: ", this->FindCommand->SearchFrameworkFirst,
"\n AppBundle"
"\n Only Search AppBundle: ", this->FindCommand->SearchAppBundleOnly,
"\n Search AppBundle Last: ", this->FindCommand->SearchAppBundleLast,
"\n Search AppBundle First: ", this->FindCommand->SearchAppBundleFirst,
"\n"
);
// clang-format on
if (this->FindCommand->NoDefaultPath) {
buffer += " NO_DEFAULT_PATH Enabled\n";
} else {
// clang-format off
buffer += cmStrCat(
" CMAKE_FIND_USE_CMAKE_PATH: ", !this->FindCommand->NoCMakePath,
"\n CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: ", !this->FindCommand->NoCMakeEnvironmentPath,
"\n CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: ", !this->FindCommand->NoSystemEnvironmentPath,
"\n CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: ", !this->FindCommand->NoCMakeSystemPath,
"\n CMAKE_FIND_USE_INSTALL_PREFIX: ", !this->FindCommand->NoCMakeInstallPath,
"\n"
);
// clang-format on
}
buffer +=
cmStrCat(this->CommandName, " considered the following locations:\n");
for (auto const& state : this->FailedSearchLocations) {
std::string path = cmStrCat(" ", state.path);
if (!state.regexName.empty()) {
path = cmStrCat(path, '/', state.regexName);
}
buffer += cmStrCat(path, '\n');
}
if (!this->FoundSearchLocation.path.empty()) {
buffer += cmStrCat("The item was found at\n ",
this->FoundSearchLocation.path, '\n');
} else {
buffer += "The item was not found.\n";
}
this->FindCommand->DebugMessage(buffer);
}
void cmFindBaseDebugState::FoundAt(std::string const& path,

View File

@@ -291,14 +291,14 @@ void cmLocalGenerator::ComputeObjectMaxPath()
std::ostringstream w;
w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
<< ", which is less than the minimum of 128. "
<< "The value will be ignored.";
"The value will be ignored.";
this->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
} else {
std::ostringstream w;
w << "CMAKE_OBJECT_PATH_MAX is set to \"" << *plen
<< "\", which fails to parse as a positive integer. "
<< "The value will be ignored.";
"The value will be ignored.";
this->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
}
@@ -4429,10 +4429,10 @@ bool cmLocalGenerator::CheckDefinition(std::string const& define) const
std::ostringstream e;
/* clang-format off */
e << "WARNING: Function-style preprocessor definitions may not be "
<< "passed on the compiler command line because many compilers "
<< "do not support it.\n"
<< "CMake is dropping a preprocessor definition: " << define << "\n"
<< "Consider defining the macro in a (configured) header file.\n";
"passed on the compiler command line because many compilers "
"do not support it.\n"
"CMake is dropping a preprocessor definition: " << define << "\n"
"Consider defining the macro in a (configured) header file.\n";
/* clang-format on */
cmSystemTools::Message(e.str());
return false;
@@ -4444,10 +4444,10 @@ bool cmLocalGenerator::CheckDefinition(std::string const& define) const
std::ostringstream e;
/* clang-format off */
e << "WARNING: Preprocessor definitions containing '#' may not be "
<< "passed on the compiler command line because many compilers "
<< "do not support it.\n"
<< "CMake is dropping a preprocessor definition: " << define << "\n"
<< "Consider defining the macro in a (configured) header file.\n";
"passed on the compiler command line because many compilers "
"do not support it.\n"
"CMake is dropping a preprocessor definition: " << define << "\n"
"Consider defining the macro in a (configured) header file.\n";
/* clang-format on */
cmSystemTools::Message(e.str());
return false;