Refactor: Use cmStrCat to construct error strings

Replace string construction using std::stringstream with cmStrCat and
cmWrap.
This commit is contained in:
Asit Dhal
2019-09-15 19:11:02 +02:00
committed by Brad King
parent 1423507a71
commit 9dba84cfa5
31 changed files with 545 additions and 797 deletions
+5 -8
View File
@@ -321,10 +321,9 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
} }
// No command for this output exists. // No command for this output exists.
std::ostringstream e; status.SetError(
e << "given APPEND option with output\n\"" << output[0] cmStrCat("given APPEND option with output\n\"", output[0],
<< "\"\nwhich is not already a custom command output."; "\"\nwhich is not already a custom command output."));
status.SetError(e.str());
return false; return false;
} }
@@ -407,10 +406,8 @@ bool cmAddCustomCommandCommandCheckOutputs(
// Make sure the output file name has no invalid characters. // Make sure the output file name has no invalid characters.
std::string::size_type pos = o.find_first_of("#<>"); std::string::size_type pos = o.find_first_of("#<>");
if (pos != std::string::npos) { if (pos != std::string::npos) {
std::ostringstream msg; status.SetError(cmStrCat("called with OUTPUT containing a \"", o[pos],
msg << "called with OUTPUT containing a \"" << o[pos] "\". This character is not allowed."));
<< "\". This character is not allowed.";
status.SetError(msg.str());
return false; return false;
} }
} }
+6 -10
View File
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmAddCustomTargetCommand.h" #include "cmAddCustomTargetCommand.h"
#include <sstream>
#include <utility> #include <utility>
#include "cmCustomCommandLines.h" #include "cmCustomCommandLines.h"
@@ -29,11 +28,9 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args,
// Check the target name. // Check the target name.
if (targetName.find_first_of("/\\") != std::string::npos) { if (targetName.find_first_of("/\\") != std::string::npos) {
std::ostringstream e; status.SetError(cmStrCat("called with invalid target name \"", targetName,
e << "called with invalid target name \"" << targetName "\". Target names may not contain a slash. "
<< "\". Target names may not contain a slash. " "Use ADD_CUSTOM_COMMAND to generate files."));
<< "Use ADD_CUSTOM_COMMAND to generate files.";
status.SetError(e.str());
return false; return false;
} }
@@ -153,10 +150,9 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args,
std::string::size_type pos = targetName.find_first_of("#<>"); std::string::size_type pos = targetName.find_first_of("#<>");
if (pos != std::string::npos) { if (pos != std::string::npos) {
std::ostringstream msg; status.SetError(cmStrCat("called with target name containing a \"",
msg << "called with target name containing a \"" << targetName[pos] targetName[pos],
<< "\". This character is not allowed."; "\". This character is not allowed."));
status.SetError(msg.str());
return false; return false;
} }
+16 -14
View File
@@ -2,12 +2,11 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmAddDependenciesCommand.h" #include "cmAddDependenciesCommand.h"
#include <sstream>
#include "cmExecutionStatus.h" #include "cmExecutionStatus.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmMessageType.h" #include "cmMessageType.h"
#include "cmRange.h" #include "cmRange.h"
#include "cmStringAlgorithms.h"
#include "cmTarget.h" #include "cmTarget.h"
bool cmAddDependenciesCommand(std::vector<std::string> const& args, bool cmAddDependenciesCommand(std::vector<std::string> const& args,
@@ -21,10 +20,10 @@ bool cmAddDependenciesCommand(std::vector<std::string> const& args,
cmMakefile& mf = status.GetMakefile(); cmMakefile& mf = status.GetMakefile();
std::string const& target_name = args[0]; std::string const& target_name = args[0];
if (mf.IsAlias(target_name)) { if (mf.IsAlias(target_name)) {
std::ostringstream e; mf.IssueMessage(
e << "Cannot add target-level dependencies to alias target \"" MessageType::FATAL_ERROR,
<< target_name << "\".\n"; cmStrCat("Cannot add target-level dependencies to alias target \"",
mf.IssueMessage(MessageType::FATAL_ERROR, e.str()); target_name, "\".\n"));
} }
if (cmTarget* target = mf.FindTargetToUse(target_name)) { if (cmTarget* target = mf.FindTargetToUse(target_name)) {
@@ -33,14 +32,17 @@ bool cmAddDependenciesCommand(std::vector<std::string> const& args,
target->AddUtility(arg, &mf); target->AddUtility(arg, &mf);
} }
} else { } else {
std::ostringstream e; mf.IssueMessage(
e << "Cannot add target-level dependencies to non-existent target \"" MessageType::FATAL_ERROR,
<< target_name << "\".\n" cmStrCat(
<< "The add_dependencies works for top-level logical targets created " "Cannot add target-level dependencies to non-existent "
<< "by the add_executable, add_library, or add_custom_target commands. " "target \"",
<< "If you want to add file-level dependencies see the DEPENDS option " target_name,
<< "of the add_custom_target and add_custom_command commands."; "\".\nThe add_dependencies works for "
mf.IssueMessage(MessageType::FATAL_ERROR, e.str()); "top-level logical targets created by the add_executable, "
"add_library, or add_custom_target commands. If you want to add "
"file-level dependencies see the DEPENDS option of the "
"add_custom_target and add_custom_command commands."));
} }
return true; return true;
+16 -22
View File
@@ -2,13 +2,12 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmAddExecutableCommand.h" #include "cmAddExecutableCommand.h"
#include <sstream>
#include "cmExecutionStatus.h" #include "cmExecutionStatus.h"
#include "cmGeneratorExpression.h" #include "cmGeneratorExpression.h"
#include "cmGlobalGenerator.h" #include "cmGlobalGenerator.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmStateTypes.h" #include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmTarget.h" #include "cmTarget.h"
bool cmAddExecutableCommand(std::vector<std::string> const& args, bool cmAddExecutableCommand(std::vector<std::string> const& args,
@@ -99,34 +98,30 @@ bool cmAddExecutableCommand(std::vector<std::string> const& args,
std::string const& aliasedName = *s; std::string const& aliasedName = *s;
if (mf.IsAlias(aliasedName)) { if (mf.IsAlias(aliasedName)) {
std::ostringstream e; status.SetError(cmStrCat("cannot create ALIAS target \"", exename,
e << "cannot create ALIAS target \"" << exename << "\" because target \"" "\" because target \"", aliasedName,
<< aliasedName << "\" is itself an ALIAS."; "\" is itself an ALIAS."));
status.SetError(e.str());
return false; return false;
} }
cmTarget* aliasedTarget = mf.FindTargetToUse(aliasedName, true); cmTarget* aliasedTarget = mf.FindTargetToUse(aliasedName, true);
if (!aliasedTarget) { if (!aliasedTarget) {
std::ostringstream e; status.SetError(cmStrCat("cannot create ALIAS target \"", exename,
e << "cannot create ALIAS target \"" << exename << "\" because target \"" "\" because target \"", aliasedName,
<< aliasedName << "\" does not already exist."; "\" does not already exist."));
status.SetError(e.str());
return false; return false;
} }
cmStateEnums::TargetType type = aliasedTarget->GetType(); cmStateEnums::TargetType type = aliasedTarget->GetType();
if (type != cmStateEnums::EXECUTABLE) { if (type != cmStateEnums::EXECUTABLE) {
std::ostringstream e; status.SetError(cmStrCat("cannot create ALIAS target \"", exename,
e << "cannot create ALIAS target \"" << exename << "\" because target \"" "\" because target \"", aliasedName,
<< aliasedName << "\" is not an executable."; "\" is not an executable."));
status.SetError(e.str());
return false; return false;
} }
if (aliasedTarget->IsImported() && if (aliasedTarget->IsImported() &&
!aliasedTarget->IsImportedGloballyVisible()) { !aliasedTarget->IsImportedGloballyVisible()) {
std::ostringstream e; status.SetError(cmStrCat("cannot create ALIAS target \"", exename,
e << "cannot create ALIAS target \"" << exename << "\" because target \"" "\" because target \"", aliasedName,
<< aliasedName << "\" is imported but not globally visible."; "\" is imported but not globally visible."));
status.SetError(e.str());
return false; return false;
} }
mf.AddAlias(exename, aliasedName); mf.AddAlias(exename, aliasedName);
@@ -137,10 +132,9 @@ bool cmAddExecutableCommand(std::vector<std::string> const& args,
if (importTarget) { if (importTarget) {
// Make sure the target does not already exist. // Make sure the target does not already exist.
if (mf.FindTargetToUse(exename)) { if (mf.FindTargetToUse(exename)) {
std::ostringstream e; status.SetError(cmStrCat(
e << "cannot create imported target \"" << exename "cannot create imported target \"", exename,
<< "\" because another target with the same name already exists."; "\" because another target with the same name already exists."));
status.SetError(e.str());
return false; return false;
} }
+26 -36
View File
@@ -2,8 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmAddLibraryCommand.h" #include "cmAddLibraryCommand.h"
#include <sstream>
#include "cmAlgorithms.h" #include "cmAlgorithms.h"
#include "cmExecutionStatus.h" #include "cmExecutionStatus.h"
#include "cmGeneratorExpression.h" #include "cmGeneratorExpression.h"
@@ -184,20 +182,16 @@ bool cmAddLibraryCommand(std::vector<std::string> const& args,
std::string const& aliasedName = *s; std::string const& aliasedName = *s;
if (mf.IsAlias(aliasedName)) { if (mf.IsAlias(aliasedName)) {
std::ostringstream e; status.SetError(cmStrCat("cannot create ALIAS target \"", libName,
e << "cannot create ALIAS target \"" << libName << "\" because target \"" "\" because target \"", aliasedName,
<< aliasedName << "\" is itself an ALIAS."; "\" is itself an ALIAS."));
status.SetError(e.str());
return false; return false;
} }
cmTarget* aliasedTarget = mf.FindTargetToUse(aliasedName, true); cmTarget* aliasedTarget = mf.FindTargetToUse(aliasedName, true);
if (!aliasedTarget) { if (!aliasedTarget) {
std::ostringstream e; status.SetError(cmStrCat("cannot create ALIAS target \"", libName,
e << "cannot create ALIAS target \"" << libName << "\" because target \"" "\" because target \"", aliasedName,
<< aliasedName "\" does not already exist."));
<< "\" does not already "
"exist.";
status.SetError(e.str());
return false; return false;
} }
cmStateEnums::TargetType aliasedType = aliasedTarget->GetType(); cmStateEnums::TargetType aliasedType = aliasedTarget->GetType();
@@ -208,18 +202,16 @@ bool cmAddLibraryCommand(std::vector<std::string> const& args,
aliasedType != cmStateEnums::INTERFACE_LIBRARY && aliasedType != cmStateEnums::INTERFACE_LIBRARY &&
!(aliasedType == cmStateEnums::UNKNOWN_LIBRARY && !(aliasedType == cmStateEnums::UNKNOWN_LIBRARY &&
aliasedTarget->IsImported())) { aliasedTarget->IsImported())) {
std::ostringstream e; status.SetError(cmStrCat("cannot create ALIAS target \"", libName,
e << "cannot create ALIAS target \"" << libName << "\" because target \"" "\" because target \"", aliasedName,
<< aliasedName << "\" is not a library."; "\" is not a library."));
status.SetError(e.str());
return false; return false;
} }
if (aliasedTarget->IsImported() && if (aliasedTarget->IsImported() &&
!aliasedTarget->IsImportedGloballyVisible()) { !aliasedTarget->IsImportedGloballyVisible()) {
std::ostringstream e; status.SetError(cmStrCat("cannot create ALIAS target \"", libName,
e << "cannot create ALIAS target \"" << libName << "\" because target \"" "\" because target \"", aliasedName,
<< aliasedName << "\" is imported but not globally visible."; "\" is imported but not globally visible."));
status.SetError(e.str());
return false; return false;
} }
mf.AddAlias(libName, aliasedName); mf.AddAlias(libName, aliasedName);
@@ -238,12 +230,13 @@ bool cmAddLibraryCommand(std::vector<std::string> const& args,
if ((type == cmStateEnums::SHARED_LIBRARY || if ((type == cmStateEnums::SHARED_LIBRARY ||
type == cmStateEnums::MODULE_LIBRARY) && type == cmStateEnums::MODULE_LIBRARY) &&
!mf.GetState()->GetGlobalPropertyAsBool("TARGET_SUPPORTS_SHARED_LIBS")) { !mf.GetState()->GetGlobalPropertyAsBool("TARGET_SUPPORTS_SHARED_LIBS")) {
std::ostringstream w; mf.IssueMessage(
w << "ADD_LIBRARY called with " MessageType::AUTHOR_WARNING,
<< (type == cmStateEnums::SHARED_LIBRARY ? "SHARED" : "MODULE") cmStrCat(
<< " option but the target platform does not support dynamic linking. " "ADD_LIBRARY called with ",
"Building a STATIC library instead. This may lead to problems."; (type == cmStateEnums::SHARED_LIBRARY ? "SHARED" : "MODULE"),
mf.IssueMessage(MessageType::AUTHOR_WARNING, w.str()); " option but the target platform does not support dynamic linking. ",
"Building a STATIC library instead. This may lead to problems."));
type = cmStateEnums::STATIC_LIBRARY; type = cmStateEnums::STATIC_LIBRARY;
} }
@@ -266,19 +259,17 @@ bool cmAddLibraryCommand(std::vector<std::string> const& args,
} }
if (type == cmStateEnums::INTERFACE_LIBRARY) { if (type == cmStateEnums::INTERFACE_LIBRARY) {
if (!cmGeneratorExpression::IsValidTargetName(libName)) { if (!cmGeneratorExpression::IsValidTargetName(libName)) {
std::ostringstream e; status.SetError(cmStrCat(
e << "Invalid name for IMPORTED INTERFACE library target: " << libName; "Invalid name for IMPORTED INTERFACE library target: ", libName));
status.SetError(e.str());
return false; return false;
} }
} }
// Make sure the target does not already exist. // Make sure the target does not already exist.
if (mf.FindTargetToUse(libName)) { if (mf.FindTargetToUse(libName)) {
std::ostringstream e; status.SetError(cmStrCat(
e << "cannot create imported target \"" << libName "cannot create imported target \"", libName,
<< "\" because another target with the same name already exists."; "\" because another target with the same name already exists."));
status.SetError(e.str());
return false; return false;
} }
@@ -309,9 +300,8 @@ bool cmAddLibraryCommand(std::vector<std::string> const& args,
if (type == cmStateEnums::INTERFACE_LIBRARY) { if (type == cmStateEnums::INTERFACE_LIBRARY) {
if (!cmGeneratorExpression::IsValidTargetName(libName) || if (!cmGeneratorExpression::IsValidTargetName(libName) ||
libName.find("::") != std::string::npos) { libName.find("::") != std::string::npos) {
std::ostringstream e; status.SetError(
e << "Invalid name for INTERFACE library target: " << libName; cmStrCat("Invalid name for INTERFACE library target: ", libName));
status.SetError(e.str());
return false; return false;
} }
+7 -8
View File
@@ -3,7 +3,6 @@
#include "cmAddSubDirectoryCommand.h" #include "cmAddSubDirectoryCommand.h"
#include <cstring> #include <cstring>
#include <sstream>
#include "cmExecutionStatus.h" #include "cmExecutionStatus.h"
#include "cmMakefile.h" #include "cmMakefile.h"
@@ -64,13 +63,13 @@ bool cmAddSubDirectoryCommand(std::vector<std::string> const& args,
// error. // error.
if (!cmSystemTools::IsSubDirectory(srcPath, if (!cmSystemTools::IsSubDirectory(srcPath,
mf.GetCurrentSourceDirectory())) { mf.GetCurrentSourceDirectory())) {
std::ostringstream e; status.SetError(
e << "not given a binary directory but the given source directory " cmStrCat("not given a binary directory but the given source ",
<< "\"" << srcPath << "\" is not a subdirectory of \"" "directory \"", srcPath, "\" is not a subdirectory of \"",
<< mf.GetCurrentSourceDirectory() << "\". " mf.GetCurrentSourceDirectory(),
<< "When specifying an out-of-tree source a binary directory " "\". When specifying an "
<< "must be explicitly specified."; "out-of-tree source a binary directory must be explicitly "
status.SetError(e.str()); "specified."));
return false; return false;
} }
+6 -13
View File
@@ -2,10 +2,9 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmAddTestCommand.h" #include "cmAddTestCommand.h"
#include <sstream>
#include "cmExecutionStatus.h" #include "cmExecutionStatus.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmStringAlgorithms.h"
#include "cmTest.h" #include "cmTest.h"
#include "cmTestGenerator.h" #include "cmTestGenerator.h"
@@ -38,10 +37,8 @@ bool cmAddTestCommand(std::vector<std::string> const& args,
// If the test was already added by a new-style signature do not // If the test was already added by a new-style signature do not
// allow it to be duplicated. // allow it to be duplicated.
if (!test->GetOldStyle()) { if (!test->GetOldStyle()) {
std::ostringstream e; status.SetError(cmStrCat(" given test name \"", args[0],
e << " given test name \"" << args[0] "\" which already exists in this directory."));
<< "\" which already exists in this directory.";
status.SetError(e.str());
return false; return false;
} }
} else { } else {
@@ -110,9 +107,7 @@ bool cmAddTestCommandHandleNameMode(std::vector<std::string> const& args,
working_directory = args[i]; working_directory = args[i];
doing = DoingNone; doing = DoingNone;
} else { } else {
std::ostringstream e; status.SetError(cmStrCat(" given unknown argument:\n ", args[i], "\n"));
e << " given unknown argument:\n " << args[i] << "\n";
status.SetError(e.str());
return false; return false;
} }
} }
@@ -133,10 +128,8 @@ bool cmAddTestCommandHandleNameMode(std::vector<std::string> const& args,
// Require a unique test name within the directory. // Require a unique test name within the directory.
if (mf.GetTest(name)) { if (mf.GetTest(name)) {
std::ostringstream e; status.SetError(cmStrCat(" given test NAME \"", name,
e << " given test NAME \"" << name "\" which already exists in this directory."));
<< "\" which already exists in this directory.";
status.SetError(e.str());
return false; return false;
} }
+21 -26
View File
@@ -2,14 +2,13 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCMakePolicyCommand.h" #include "cmCMakePolicyCommand.h"
#include <sstream>
#include "cmExecutionStatus.h" #include "cmExecutionStatus.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmMessageType.h" #include "cmMessageType.h"
#include "cmPolicies.h" #include "cmPolicies.h"
#include "cmState.h" #include "cmState.h"
#include "cmStateTypes.h" #include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
namespace { namespace {
bool HandleSetMode(std::vector<std::string> const& args, bool HandleSetMode(std::vector<std::string> const& args,
@@ -60,9 +59,7 @@ bool cmCMakePolicyCommand(std::vector<std::string> const& args,
return HandleGetWarningMode(args, status); return HandleGetWarningMode(args, status);
} }
std::ostringstream e; status.SetError(cmStrCat("given unknown first argument \"", args[0], "\""));
e << "given unknown first argument \"" << args[0] << "\"";
status.SetError(e.str());
return false; return false;
} }
@@ -82,9 +79,8 @@ bool HandleSetMode(std::vector<std::string> const& args,
} else if (args[2] == "NEW") { } else if (args[2] == "NEW") {
policyStatus = cmPolicies::NEW; policyStatus = cmPolicies::NEW;
} else { } else {
std::ostringstream e; status.SetError(
e << "SET given unrecognized policy status \"" << args[2] << "\""; cmStrCat("SET given unrecognized policy status \"", args[2], "\""));
status.SetError(e.str());
return false; return false;
} }
@@ -128,10 +124,9 @@ bool HandleGetMode(std::vector<std::string> const& args,
// Lookup the policy number. // Lookup the policy number.
cmPolicies::PolicyID pid; cmPolicies::PolicyID pid;
if (!cmPolicies::GetPolicyID(id.c_str(), pid)) { if (!cmPolicies::GetPolicyID(id.c_str(), pid)) {
std::ostringstream e; status.SetError(
e << "GET given policy \"" << id << "\" which is not known to this " cmStrCat("GET given policy \"", id,
<< "version of CMake."; "\" which is not known to this version of CMake."));
status.SetError(e.str());
return false; return false;
} }
@@ -155,12 +150,14 @@ bool HandleGetMode(std::vector<std::string> const& args,
case cmPolicies::REQUIRED_ALWAYS: case cmPolicies::REQUIRED_ALWAYS:
// The policy is required to be set before anything needs it. // The policy is required to be set before anything needs it.
{ {
std::ostringstream e; status.GetMakefile().IssueMessage(
e << cmPolicies::GetRequiredPolicyError(pid) << "\n" MessageType::FATAL_ERROR,
<< "The call to cmake_policy(GET " << id << " ...) at which this " cmStrCat(
<< "error appears requests the policy, and this version of CMake " cmPolicies::GetRequiredPolicyError(pid), "\n",
<< "requires that the policy be set to NEW before it is checked."; "The call to cmake_policy(GET ", id,
status.GetMakefile().IssueMessage(MessageType::FATAL_ERROR, e.str()); " ...) at which this "
"error appears requests the policy, and this version of CMake ",
"requires that the policy be set to NEW before it is checked."));
} }
} }
@@ -188,10 +185,9 @@ bool HandleVersionMode(std::vector<std::string> const& args,
: std::string(); : std::string();
if (dd != std::string::npos && if (dd != std::string::npos &&
(version_min.empty() || version_max.empty())) { (version_min.empty() || version_max.empty())) {
std::ostringstream e; status.SetError(
e << "VERSION \"" << version_string cmStrCat("VERSION \"", version_string,
<< R"(" does not have a version on both sides of "...".)"; R"(" does not have a version on both sides of "...".)"));
status.SetError(e.str());
return false; return false;
} }
@@ -215,10 +211,9 @@ bool HandleGetWarningMode(std::vector<std::string> const& args,
// Lookup the policy number. // Lookup the policy number.
cmPolicies::PolicyID pid; cmPolicies::PolicyID pid;
if (!cmPolicies::GetPolicyID(id.c_str(), pid)) { if (!cmPolicies::GetPolicyID(id.c_str(), pid)) {
std::ostringstream e; status.SetError(
e << "GET_WARNING given policy \"" << id cmStrCat("GET_WARNING given policy \"", id,
<< "\" which is not known to this version of CMake."; "\" which is not known to this version of CMake."));
status.SetError(e.str());
return false; return false;
} }
+3 -9
View File
@@ -2,8 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmConfigureFileCommand.h" #include "cmConfigureFileCommand.h"
#include <sstream>
#include "cmExecutionStatus.h" #include "cmExecutionStatus.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmMessageType.h" #include "cmMessageType.h"
@@ -26,13 +24,9 @@ bool cmConfigureFileCommand(std::vector<std::string> const& args,
// If the input location is a directory, error out. // If the input location is a directory, error out.
if (cmSystemTools::FileIsDirectory(inputFile)) { if (cmSystemTools::FileIsDirectory(inputFile)) {
std::ostringstream e; status.SetError(cmStrCat("input location\n ", inputFile,
/* clang-format off */ "\n"
e << "input location\n" "is a directory but a file was expected."));
<< " " << inputFile << "\n"
<< "is a directory but a file was expected.";
/* clang-format on */
status.SetError(e.str());
return false; return false;
} }
+102 -159
View File
@@ -274,9 +274,8 @@ bool HandleHashCommand(std::vector<std::string> const& args,
{ {
#if !defined(CMAKE_BOOTSTRAP) #if !defined(CMAKE_BOOTSTRAP)
if (args.size() != 3) { if (args.size() != 3) {
std::ostringstream e; status.SetError(
e << args[0] << " requires a file name and output variable"; cmStrCat(args[0], " requires a file name and output variable"));
status.SetError(e.str());
return false; return false;
} }
@@ -287,16 +286,12 @@ bool HandleHashCommand(std::vector<std::string> const& args,
status.GetMakefile().AddDefinition(args[2], out); status.GetMakefile().AddDefinition(args[2], out);
return true; return true;
} }
std::ostringstream e; status.SetError(cmStrCat(args[0], " failed to read file \"", args[1],
e << args[0] << " failed to read file \"" << args[1] "\": ", cmSystemTools::GetLastSystemError()));
<< "\": " << cmSystemTools::GetLastSystemError();
status.SetError(e.str());
} }
return false; return false;
#else #else
std::ostringstream e; status.SetError(cmStrCat(args[0], " not available during bootstrap"));
e << args[0] << " not available during bootstrap";
status.SetError(e.str());
return false; return false;
#endif #endif
} }
@@ -376,30 +371,24 @@ bool HandleStringsCommand(std::vector<std::string> const& args,
} else if (arg_mode == arg_limit_input) { } else if (arg_mode == arg_limit_input) {
if (sscanf(args[i].c_str(), "%d", &limit_input) != 1 || if (sscanf(args[i].c_str(), "%d", &limit_input) != 1 ||
limit_input < 0) { limit_input < 0) {
std::ostringstream e; status.SetError(cmStrCat("STRINGS option LIMIT_INPUT value \"",
e << "STRINGS option LIMIT_INPUT value \"" << args[i] args[i], "\" is not an unsigned integer."));
<< "\" is not an unsigned integer.";
status.SetError(e.str());
return false; return false;
} }
arg_mode = arg_none; arg_mode = arg_none;
} else if (arg_mode == arg_limit_output) { } else if (arg_mode == arg_limit_output) {
if (sscanf(args[i].c_str(), "%d", &limit_output) != 1 || if (sscanf(args[i].c_str(), "%d", &limit_output) != 1 ||
limit_output < 0) { limit_output < 0) {
std::ostringstream e; status.SetError(cmStrCat("STRINGS option LIMIT_OUTPUT value \"",
e << "STRINGS option LIMIT_OUTPUT value \"" << args[i] args[i], "\" is not an unsigned integer."));
<< "\" is not an unsigned integer.";
status.SetError(e.str());
return false; return false;
} }
arg_mode = arg_none; arg_mode = arg_none;
} else if (arg_mode == arg_limit_count) { } else if (arg_mode == arg_limit_count) {
int count; int count;
if (sscanf(args[i].c_str(), "%d", &count) != 1 || count < 0) { if (sscanf(args[i].c_str(), "%d", &count) != 1 || count < 0) {
std::ostringstream e; status.SetError(cmStrCat("STRINGS option LIMIT_COUNT value \"",
e << "STRINGS option LIMIT_COUNT value \"" << args[i] args[i], "\" is not an unsigned integer."));
<< "\" is not an unsigned integer.";
status.SetError(e.str());
return false; return false;
} }
limit_count = count; limit_count = count;
@@ -407,10 +396,8 @@ bool HandleStringsCommand(std::vector<std::string> const& args,
} else if (arg_mode == arg_length_minimum) { } else if (arg_mode == arg_length_minimum) {
int len; int len;
if (sscanf(args[i].c_str(), "%d", &len) != 1 || len < 0) { if (sscanf(args[i].c_str(), "%d", &len) != 1 || len < 0) {
std::ostringstream e; status.SetError(cmStrCat("STRINGS option LENGTH_MINIMUM value \"",
e << "STRINGS option LENGTH_MINIMUM value \"" << args[i] args[i], "\" is not an unsigned integer."));
<< "\" is not an unsigned integer.";
status.SetError(e.str());
return false; return false;
} }
minlen = len; minlen = len;
@@ -418,20 +405,16 @@ bool HandleStringsCommand(std::vector<std::string> const& args,
} else if (arg_mode == arg_length_maximum) { } else if (arg_mode == arg_length_maximum) {
int len; int len;
if (sscanf(args[i].c_str(), "%d", &len) != 1 || len < 0) { if (sscanf(args[i].c_str(), "%d", &len) != 1 || len < 0) {
std::ostringstream e; status.SetError(cmStrCat("STRINGS option LENGTH_MAXIMUM value \"",
e << "STRINGS option LENGTH_MAXIMUM value \"" << args[i] args[i], "\" is not an unsigned integer."));
<< "\" is not an unsigned integer.";
status.SetError(e.str());
return false; return false;
} }
maxlen = len; maxlen = len;
arg_mode = arg_none; arg_mode = arg_none;
} else if (arg_mode == arg_regex) { } else if (arg_mode == arg_regex) {
if (!regex.compile(args[i])) { if (!regex.compile(args[i])) {
std::ostringstream e; status.SetError(cmStrCat("STRINGS option REGEX value \"", args[i],
e << "STRINGS option REGEX value \"" << args[i] "\" could not be compiled."));
<< "\" could not be compiled.";
status.SetError(e.str());
return false; return false;
} }
have_regex = true; have_regex = true;
@@ -448,16 +431,14 @@ bool HandleStringsCommand(std::vector<std::string> const& args,
} else if (args[i] == "UTF-32BE") { } else if (args[i] == "UTF-32BE") {
encoding = encoding_utf32be; encoding = encoding_utf32be;
} else { } else {
std::ostringstream e; status.SetError(cmStrCat("STRINGS option ENCODING \"", args[i],
e << "STRINGS option ENCODING \"" << args[i] << "\" not recognized."; "\" not recognized."));
status.SetError(e.str());
return false; return false;
} }
arg_mode = arg_none; arg_mode = arg_none;
} else { } else {
std::ostringstream e; status.SetError(
e << "STRINGS given unknown argument \"" << args[i] << "\""; cmStrCat("STRINGS given unknown argument \"", args[i], "\""));
status.SetError(e.str());
return false; return false;
} }
} }
@@ -479,9 +460,8 @@ bool HandleStringsCommand(std::vector<std::string> const& args,
cmsys::ifstream fin(fileName.c_str()); cmsys::ifstream fin(fileName.c_str());
#endif #endif
if (!fin) { if (!fin) {
std::ostringstream e; status.SetError(
e << "STRINGS file \"" << fileName << "\" cannot be read."; cmStrCat("STRINGS file \"", fileName, "\" cannot be read."));
status.SetError(e.str());
return false; return false;
} }
@@ -963,9 +943,7 @@ bool HandleDifferentCommand(std::vector<std::string> const& args,
file_rhs = args[i].c_str(); file_rhs = args[i].c_str();
doing = DoingNone; doing = DoingNone;
} else { } else {
std::ostringstream e; status.SetError(cmStrCat("DIFFERENT given unknown argument ", args[i]));
e << "DIFFERENT given unknown argument " << args[i];
status.SetError(e.str());
return false; return false;
} }
} }
@@ -1027,9 +1005,8 @@ bool HandleRPathChangeCommand(std::vector<std::string> const& args,
newRPath = args[i].c_str(); newRPath = args[i].c_str();
doing = DoingNone; doing = DoingNone;
} else { } else {
std::ostringstream e; status.SetError(
e << "RPATH_CHANGE given unknown argument " << args[i]; cmStrCat("RPATH_CHANGE given unknown argument ", args[i]));
status.SetError(e.str());
return false; return false;
} }
} }
@@ -1046,9 +1023,8 @@ bool HandleRPathChangeCommand(std::vector<std::string> const& args,
return false; return false;
} }
if (!cmSystemTools::FileExists(file, true)) { if (!cmSystemTools::FileExists(file, true)) {
std::ostringstream e; status.SetError(
e << "RPATH_CHANGE given FILE \"" << file << "\" that does not exist."; cmStrCat("RPATH_CHANGE given FILE \"", file, "\" that does not exist."));
status.SetError(e.str());
return false; return false;
} }
bool success = true; bool success = true;
@@ -1058,15 +1034,9 @@ bool HandleRPathChangeCommand(std::vector<std::string> const& args,
if (!cmSystemTools::ChangeRPath(file, oldRPath, newRPath, if (!cmSystemTools::ChangeRPath(file, oldRPath, newRPath,
removeEnvironmentRPath, &emsg, &changed)) { removeEnvironmentRPath, &emsg, &changed)) {
std::ostringstream e; status.SetError(cmStrCat("RPATH_CHANGE could not write new RPATH:\n ",
/* clang-format off */ newRPath, "\nto the file:\n ", file, "\n",
e << "RPATH_CHANGE could not write new RPATH:\n" emsg));
<< " " << newRPath << "\n"
<< "to the file:\n"
<< " " << file << "\n"
<< emsg;
/* clang-format on */
status.SetError(e.str());
success = false; success = false;
} }
if (success) { if (success) {
@@ -1098,9 +1068,8 @@ bool HandleRPathRemoveCommand(std::vector<std::string> const& args,
file = args[i]; file = args[i];
doing = DoingNone; doing = DoingNone;
} else { } else {
std::ostringstream e; status.SetError(
e << "RPATH_REMOVE given unknown argument " << args[i]; cmStrCat("RPATH_REMOVE given unknown argument ", args[i]));
status.SetError(e.str());
return false; return false;
} }
} }
@@ -1109,9 +1078,8 @@ bool HandleRPathRemoveCommand(std::vector<std::string> const& args,
return false; return false;
} }
if (!cmSystemTools::FileExists(file, true)) { if (!cmSystemTools::FileExists(file, true)) {
std::ostringstream e; status.SetError(
e << "RPATH_REMOVE given FILE \"" << file << "\" that does not exist."; cmStrCat("RPATH_REMOVE given FILE \"", file, "\" that does not exist."));
status.SetError(e.str());
return false; return false;
} }
bool success = true; bool success = true;
@@ -1119,13 +1087,9 @@ bool HandleRPathRemoveCommand(std::vector<std::string> const& args,
std::string emsg; std::string emsg;
bool removed; bool removed;
if (!cmSystemTools::RemoveRPath(file, &emsg, &removed)) { if (!cmSystemTools::RemoveRPath(file, &emsg, &removed)) {
std::ostringstream e; status.SetError(
/* clang-format off */ cmStrCat("RPATH_REMOVE could not remove RPATH from file: \n ", file,
e << "RPATH_REMOVE could not remove RPATH from file:\n" "\n", emsg));
<< " " << file << "\n"
<< emsg;
/* clang-format on */
status.SetError(e.str());
success = false; success = false;
} }
if (success) { if (success) {
@@ -1164,9 +1128,8 @@ bool HandleRPathCheckCommand(std::vector<std::string> const& args,
rpath = args[i].c_str(); rpath = args[i].c_str();
doing = DoingNone; doing = DoingNone;
} else { } else {
std::ostringstream e; status.SetError(
e << "RPATH_CHECK given unknown argument " << args[i]; cmStrCat("RPATH_CHECK given unknown argument ", args[i]));
status.SetError(e.str());
return false; return false;
} }
} }
@@ -1215,9 +1178,8 @@ bool HandleReadElfCommand(std::vector<std::string> const& args,
Arguments const arguments = parser.Parse(cmMakeRange(args).advance(2)); Arguments const arguments = parser.Parse(cmMakeRange(args).advance(2));
if (!cmSystemTools::FileExists(fileNameArg, true)) { if (!cmSystemTools::FileExists(fileNameArg, true)) {
std::ostringstream e; status.SetError(cmStrCat("READ_ELF given FILE \"", fileNameArg,
e << "READ_ELF given FILE \"" << fileNameArg << "\" that does not exist."; "\" that does not exist."));
status.SetError(e.str());
return false; return false;
} }
@@ -1311,15 +1273,8 @@ bool HandleRename(std::vector<std::string> const& args,
if (!cmSystemTools::RenameFile(oldname, newname)) { if (!cmSystemTools::RenameFile(oldname, newname)) {
std::string err = cmSystemTools::GetLastSystemError(); std::string err = cmSystemTools::GetLastSystemError();
std::ostringstream e; status.SetError(cmStrCat("RENAME failed to rename\n ", oldname,
/* clang-format off */ "\nto\n ", newname, "\nbecause: ", err, "\n"));
e << "RENAME failed to rename\n"
<< " " << oldname << "\n"
<< "to\n"
<< " " << newname << "\n"
<< "because: " << err << "\n";
/* clang-format on */
status.SetError(e.str());
return false; return false;
} }
return true; return true;
@@ -1494,10 +1449,8 @@ public:
bool updated = (OldPercentage != this->CurrentPercentage); bool updated = (OldPercentage != this->CurrentPercentage);
if (updated) { if (updated) {
std::ostringstream oss; status =
oss << "[" << this->Text << " " << this->CurrentPercentage cmStrCat("[", this->Text, " ", this->CurrentPercentage, "% complete]");
<< "% complete]";
status = oss.str();
} }
return updated; return updated;
@@ -1743,9 +1696,7 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
msg = cmStrCat("returning early; file already exists with expected ", msg = cmStrCat("returning early; file already exists with expected ",
hashMatchMSG, '"'); hashMatchMSG, '"');
if (!statusVar.empty()) { if (!statusVar.empty()) {
std::ostringstream result; status.GetMakefile().AddDefinition(statusVar, cmStrCat(0, ";\"", msg));
result << 0 << ";\"" << msg;
status.GetMakefile().AddDefinition(statusVar, result.str());
} }
return true; return true;
} }
@@ -1891,10 +1842,9 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
::curl_easy_cleanup(curl); ::curl_easy_cleanup(curl);
if (!statusVar.empty()) { if (!statusVar.empty()) {
std::ostringstream result; status.GetMakefile().AddDefinition(
result << static_cast<int>(res) << ";\"" << ::curl_easy_strerror(res) statusVar,
<< "\""; cmStrCat(static_cast<int>(res), ";\"", ::curl_easy_strerror(res), "\""));
status.GetMakefile().AddDefinition(statusVar, result.str());
} }
::curl_global_cleanup(); ::curl_global_cleanup();
@@ -1914,14 +1864,6 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
} }
if (expectedHash != actualHash) { if (expectedHash != actualHash) {
std::ostringstream oss;
oss << "DOWNLOAD HASH mismatch" << std::endl
<< " for file: [" << file << "]" << std::endl
<< " expected hash: [" << expectedHash << "]" << std::endl
<< " actual hash: [" << actualHash << "]" << std::endl
<< " status: [" << static_cast<int>(res) << ";\""
<< ::curl_easy_strerror(res) << "\"]" << std::endl;
if (!statusVar.empty() && res == 0) { if (!statusVar.empty() && res == 0) {
status.GetMakefile().AddDefinition(statusVar, status.GetMakefile().AddDefinition(statusVar,
"1;HASH mismatch: " "1;HASH mismatch: "
@@ -1930,7 +1872,19 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
" actual: " + actualHash); " actual: " + actualHash);
} }
status.SetError(oss.str()); status.SetError(cmStrCat("DOWNLOAD HASH mismatch\n"
" for file: [",
file,
"]\n"
" expected hash: [",
expectedHash,
"]\n"
" actual hash: [",
actualHash,
"]\n"
" status: [",
static_cast<int>(res), ";\"",
::curl_easy_strerror(res), "\"]\n"));
return false; return false;
} }
} }
@@ -2180,10 +2134,9 @@ bool HandleUploadCommand(std::vector<std::string> const& args,
::curl_easy_cleanup(curl); ::curl_easy_cleanup(curl);
if (!statusVar.empty()) { if (!statusVar.empty()) {
std::ostringstream result; status.GetMakefile().AddDefinition(
result << static_cast<int>(res) << ";\"" << ::curl_easy_strerror(res) statusVar,
<< "\""; cmStrCat(static_cast<int>(res), ";\"", ::curl_easy_strerror(res), "\""));
status.GetMakefile().AddDefinition(statusVar, result.str());
} }
::curl_global_cleanup(); ::curl_global_cleanup();
@@ -2322,9 +2275,9 @@ bool HandleLockCommand(std::vector<std::string> const& args,
} else if (args[i] == "PROCESS") { } else if (args[i] == "PROCESS") {
guard = GUARD_PROCESS; guard = GUARD_PROCESS;
} else { } else {
std::ostringstream e; status.GetMakefile().IssueMessage(
e << merr << ", but got:\n \"" << args[i] << "\"."; MessageType::FATAL_ERROR,
status.GetMakefile().IssueMessage(MessageType::FATAL_ERROR, e.str()); cmStrCat(merr, ", but got:\n \"", args[i], "\"."));
return false; return false;
} }
@@ -2346,17 +2299,18 @@ bool HandleLockCommand(std::vector<std::string> const& args,
} }
long scanned; long scanned;
if (!cmStrToLong(args[i], &scanned) || scanned < 0) { if (!cmStrToLong(args[i], &scanned) || scanned < 0) {
std::ostringstream e; status.GetMakefile().IssueMessage(
e << "TIMEOUT value \"" << args[i] << "\" is not an unsigned integer."; MessageType::FATAL_ERROR,
status.GetMakefile().IssueMessage(MessageType::FATAL_ERROR, e.str()); cmStrCat("TIMEOUT value \"", args[i],
"\" is not an unsigned integer."));
return false; return false;
} }
timeout = static_cast<unsigned long>(scanned); timeout = static_cast<unsigned long>(scanned);
} else { } else {
std::ostringstream e; status.GetMakefile().IssueMessage(
e << "expected DIRECTORY, RELEASE, GUARD, RESULT_VARIABLE or TIMEOUT\n"; MessageType::FATAL_ERROR,
e << "but got: \"" << args[i] << "\"."; cmStrCat("expected DIRECTORY, RELEASE, GUARD, RESULT_VARIABLE or ",
status.GetMakefile().IssueMessage(MessageType::FATAL_ERROR, e.str()); "TIMEOUT\nbut got: \"", args[i], "\"."));
return false; return false;
} }
} }
@@ -2375,18 +2329,19 @@ bool HandleLockCommand(std::vector<std::string> const& args,
// Create file and directories if needed // Create file and directories if needed
std::string parentDir = cmSystemTools::GetParentDirectory(path); std::string parentDir = cmSystemTools::GetParentDirectory(path);
if (!cmSystemTools::MakeDirectory(parentDir)) { if (!cmSystemTools::MakeDirectory(parentDir)) {
std::ostringstream e; status.GetMakefile().IssueMessage(
e << "directory\n \"" << parentDir << "\"\ncreation failed "; MessageType::FATAL_ERROR,
e << "(check permissions)."; cmStrCat("directory\n \"", parentDir,
status.GetMakefile().IssueMessage(MessageType::FATAL_ERROR, e.str()); "\"\ncreation failed (check permissions)."));
cmSystemTools::SetFatalErrorOccured(); cmSystemTools::SetFatalErrorOccured();
return false; return false;
} }
FILE* file = cmsys::SystemTools::Fopen(path, "w"); FILE* file = cmsys::SystemTools::Fopen(path, "w");
if (!file) { if (!file) {
std::ostringstream e; status.GetMakefile().IssueMessage(
e << "file\n \"" << path << "\"\ncreation failed (check permissions)."; MessageType::FATAL_ERROR,
status.GetMakefile().IssueMessage(MessageType::FATAL_ERROR, e.str()); cmStrCat("file\n \"", path,
"\"\ncreation failed (check permissions)."));
cmSystemTools::SetFatalErrorOccured(); cmSystemTools::SetFatalErrorOccured();
return false; return false;
} }
@@ -2419,9 +2374,9 @@ bool HandleLockCommand(std::vector<std::string> const& args,
const std::string result = fileLockResult.GetOutputMessage(); const std::string result = fileLockResult.GetOutputMessage();
if (resultVariable.empty() && !fileLockResult.IsOk()) { if (resultVariable.empty() && !fileLockResult.IsOk()) {
std::ostringstream e; status.GetMakefile().IssueMessage(
e << "error locking file\n \"" << path << "\"\n" << result << "."; MessageType::FATAL_ERROR,
status.GetMakefile().IssueMessage(MessageType::FATAL_ERROR, e.str()); cmStrCat("error locking file\n \"", path, "\"\n", result, "."));
cmSystemTools::SetFatalErrorOccured(); cmSystemTools::SetFatalErrorOccured();
return false; return false;
} }
@@ -2485,9 +2440,8 @@ bool HandleSizeCommand(std::vector<std::string> const& args,
cmExecutionStatus& status) cmExecutionStatus& status)
{ {
if (args.size() != 3) { if (args.size() != 3) {
std::ostringstream e; status.SetError(
e << args[0] << " requires a file name and output variable"; cmStrCat(args[0], " requires a file name and output variable"));
status.SetError(e.str());
return false; return false;
} }
@@ -2498,9 +2452,8 @@ bool HandleSizeCommand(std::vector<std::string> const& args,
const std::string& outputVariable = args[argsIndex++]; const std::string& outputVariable = args[argsIndex++];
if (!cmSystemTools::FileExists(filename, true)) { if (!cmSystemTools::FileExists(filename, true)) {
std::ostringstream e; status.SetError(
e << "SIZE requested of path that is not readable:\n " << filename; cmStrCat("SIZE requested of path that is not readable:\n ", filename));
status.SetError(e.str());
return false; return false;
} }
@@ -2514,9 +2467,8 @@ bool HandleReadSymlinkCommand(std::vector<std::string> const& args,
cmExecutionStatus& status) cmExecutionStatus& status)
{ {
if (args.size() != 3) { if (args.size() != 3) {
std::ostringstream e; status.SetError(
e << args[0] << " requires a file name and output variable"; cmStrCat(args[0], " requires a file name and output variable"));
status.SetError(e.str());
return false; return false;
} }
@@ -2525,10 +2477,8 @@ bool HandleReadSymlinkCommand(std::vector<std::string> const& args,
std::string result; std::string result;
if (!cmSystemTools::ReadSymlink(filename, result)) { if (!cmSystemTools::ReadSymlink(filename, result)) {
std::ostringstream e; status.SetError(cmStrCat(
e << "READ_SYMLINK requested of path that is not a symlink:\n " "READ_SYMLINK requested of path that is not a symlink:\n ", filename));
<< filename;
status.SetError(e.str());
return false; return false;
} }
@@ -2655,10 +2605,9 @@ bool HandleGetRuntimeDependenciesCommand(std::vector<std::string> const& args,
std::string platform = std::string platform =
status.GetMakefile().GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME"); status.GetMakefile().GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME");
if (!supportedPlatforms.count(platform)) { if (!supportedPlatforms.count(platform)) {
std::ostringstream e; status.SetError(
e << "GET_RUNTIME_DEPENDENCIES is not supported on system \"" << platform cmStrCat("GET_RUNTIME_DEPENDENCIES is not supported on system \"",
<< "\""; platform, "\""));
status.SetError(e.str());
cmSystemTools::SetFatalErrorOccured(); cmSystemTools::SetFatalErrorOccured();
return false; return false;
} }
@@ -2718,17 +2667,13 @@ bool HandleGetRuntimeDependenciesCommand(std::vector<std::string> const& args,
&keywordsMissingValues); &keywordsMissingValues);
auto argIt = unrecognizedArguments.begin(); auto argIt = unrecognizedArguments.begin();
if (argIt != unrecognizedArguments.end()) { if (argIt != unrecognizedArguments.end()) {
std::ostringstream e; status.SetError(cmStrCat("Unrecognized argument: \"", *argIt, "\""));
e << "Unrecognized argument: \"" << *argIt << "\"";
status.SetError(e.str());
cmSystemTools::SetFatalErrorOccured(); cmSystemTools::SetFatalErrorOccured();
return false; return false;
} }
argIt = keywordsMissingValues.begin(); argIt = keywordsMissingValues.begin();
if (argIt != keywordsMissingValues.end()) { if (argIt != keywordsMissingValues.end()) {
std::ostringstream e; status.SetError(cmStrCat("Keyword missing value: ", *argIt));
e << "Keyword missing value: " << *argIt;
status.SetError(e.str());
cmSystemTools::SetFatalErrorOccured(); cmSystemTools::SetFatalErrorOccured();
return false; return false;
} }
@@ -2792,9 +2737,7 @@ bool HandleGetRuntimeDependenciesCommand(std::vector<std::string> const& args,
} else { } else {
auto it = archive.GetUnresolvedPaths().begin(); auto it = archive.GetUnresolvedPaths().begin();
assert(it != archive.GetUnresolvedPaths().end()); assert(it != archive.GetUnresolvedPaths().end());
std::ostringstream e; status.SetError(cmStrCat("Could not resolve file ", *it));
e << "Could not resolve file " << *it;
status.SetError(e.str());
cmSystemTools::SetFatalErrorOccured(); cmSystemTools::SetFatalErrorOccured();
return false; return false;
} }
+21 -24
View File
@@ -348,11 +348,10 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
} else if (doing == DoingConfigs) { } else if (doing == DoingConfigs) {
if (args[i].find_first_of(":/\\") != std::string::npos || if (args[i].find_first_of(":/\\") != std::string::npos ||
cmSystemTools::GetFilenameLastExtension(args[i]) != ".cmake") { cmSystemTools::GetFilenameLastExtension(args[i]) != ".cmake") {
std::ostringstream e; this->SetError(cmStrCat(
e << "given CONFIGS option followed by invalid file name \"" << args[i] "given CONFIGS option followed by invalid file name \"", args[i],
<< "\". The names given must be file names without " "\". The names given must be file names without "
<< "a path and with a \".cmake\" extension."; "a path and with a \".cmake\" extension."));
this->SetError(e.str());
return false; return false;
} }
this->Configs.push_back(args[i]); this->Configs.push_back(args[i]);
@@ -360,9 +359,8 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
haveVersion = true; haveVersion = true;
this->Version = args[i]; this->Version = args[i];
} else { } else {
std::ostringstream e; this->SetError(
e << "called with invalid argument \"" << args[i] << "\""; cmStrCat("called with invalid argument \"", args[i], "\""));
this->SetError(e.str());
return false; return false;
} }
} }
@@ -372,10 +370,10 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
optionalComponents.begin(), optionalComponents.end(), optionalComponents.begin(), optionalComponents.end(),
std::back_inserter(doubledComponents)); std::back_inserter(doubledComponents));
if (!doubledComponents.empty()) { if (!doubledComponents.empty()) {
std::ostringstream e; this->SetError(
e << "called with components that are both required and optional:\n"; cmStrCat("called with components that are both required and "
e << cmWrap(" ", doubledComponents, "", "\n") << "\n"; "optional:\n",
this->SetError(e.str()); cmWrap(" ", doubledComponents, "", "\n"), "\n"));
return false; return false;
} }
@@ -459,11 +457,10 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
cmStrCat("CMAKE_DISABLE_FIND_PACKAGE_", this->Name); cmStrCat("CMAKE_DISABLE_FIND_PACKAGE_", this->Name);
if (this->Makefile->IsOn(disableFindPackageVar)) { if (this->Makefile->IsOn(disableFindPackageVar)) {
if (this->Required) { if (this->Required) {
std::ostringstream e; this->SetError(
e << "for module " << this->Name << " called with REQUIRED, but " cmStrCat("for module ", this->Name, " called with REQUIRED, but ",
<< disableFindPackageVar disableFindPackageVar,
<< " is enabled. A REQUIRED package cannot be disabled."; " is enabled. A REQUIRED package cannot be disabled."));
this->SetError(e.str());
return false; return false;
} }
@@ -701,9 +698,9 @@ bool cmFindPackageCommand::FindModule(bool& found)
this->Makefile->GetPolicyStatus(it->second); this->Makefile->GetPolicyStatus(it->second);
switch (status) { switch (status) {
case cmPolicies::WARN: { case cmPolicies::WARN: {
std::ostringstream e; this->Makefile->IssueMessage(
e << cmPolicies::GetPolicyWarning(it->second) << "\n"; MessageType::AUTHOR_WARNING,
this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str()); cmStrCat(cmPolicies::GetPolicyWarning(it->second), "\n"));
CM_FALLTHROUGH; CM_FALLTHROUGH;
} }
case cmPolicies::OLD: case cmPolicies::OLD:
@@ -934,10 +931,10 @@ bool cmFindPackageCommand::HandlePackageMode(
} }
// output result if in config mode but not in quiet mode // output result if in config mode but not in quiet mode
else if (!this->Quiet) { else if (!this->Quiet) {
std::ostringstream aw; this->Makefile->DisplayStatus(cmStrCat("Could NOT find ", this->Name,
aw << "Could NOT find " << this->Name << " (missing: " << this->Name " (missing: ", this->Name,
<< "_DIR)"; "_DIR)"),
this->Makefile->DisplayStatus(aw.str(), -1); -1);
} }
} }
+6 -9
View File
@@ -4,7 +4,6 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <sstream>
#include <utility> #include <utility>
#include "cm_memory.hxx" #include "cm_memory.hxx"
@@ -146,10 +145,9 @@ bool cmForEachCommand(std::vector<std::string> const& args,
} }
if ((start > stop && step > 0) || (start < stop && step < 0) || if ((start > stop && step > 0) || (start < stop && step < 0) ||
step == 0) { step == 0) {
std::ostringstream str; status.SetError(
str << "called with incorrect range specification: start "; cmStrCat("called with incorrect range specification: start ", start,
str << start << ", stop " << stop << ", step " << step; ", stop ", stop, ", step ", step));
status.SetError(str.str());
return false; return false;
} }
std::vector<std::string> range; std::vector<std::string> range;
@@ -204,10 +202,9 @@ bool HandleInMode(std::vector<std::string> const& args, cmMakefile& makefile)
cmExpandList(value, fb->Args, true); cmExpandList(value, fb->Args, true);
} }
} else { } else {
std::ostringstream e; makefile.IssueMessage(
e << "Unknown argument:\n" MessageType::FATAL_ERROR,
<< " " << args[i] << "\n"; cmStrCat("Unknown argument:\n", " ", args[i], "\n"));
makefile.IssueMessage(MessageType::FATAL_ERROR, e.str());
return true; return true;
} }
} }
+13 -23
View File
@@ -2,8 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGetPropertyCommand.h" #include "cmGetPropertyCommand.h"
#include <sstream>
#include "cmExecutionStatus.h" #include "cmExecutionStatus.h"
#include "cmGlobalGenerator.h" #include "cmGlobalGenerator.h"
#include "cmInstalledFile.h" #include "cmInstalledFile.h"
@@ -99,11 +97,11 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args,
} else if (args[1] == "INSTALL") { } else if (args[1] == "INSTALL") {
scope = cmProperty::INSTALL; scope = cmProperty::INSTALL;
} else { } else {
std::ostringstream e; status.SetError(cmStrCat(
e << "given invalid scope " << args[1] << ". " "given invalid scope ", args[1],
<< "Valid scopes are " ". "
<< "GLOBAL, DIRECTORY, TARGET, SOURCE, TEST, VARIABLE, CACHE, INSTALL."; "Valid scopes are "
status.SetError(e.str()); "GLOBAL, DIRECTORY, TARGET, SOURCE, TEST, VARIABLE, CACHE, INSTALL."));
return false; return false;
} }
@@ -138,9 +136,7 @@ bool cmGetPropertyCommand(std::vector<std::string> const& args,
doing = DoingNone; doing = DoingNone;
propertyName = args[i]; propertyName = args[i];
} else { } else {
std::ostringstream e; status.SetError(cmStrCat("given invalid argument \"", args[i], "\"."));
e << "given invalid argument \"" << args[i] << "\".";
status.SetError(e.str());
return false; return false;
} }
} }
@@ -331,10 +327,8 @@ bool HandleTargetMode(cmExecutionStatus& status, const std::string& name,
} }
return StoreResult(infoType, status.GetMakefile(), variable, prop_cstr); return StoreResult(infoType, status.GetMakefile(), variable, prop_cstr);
} }
std::ostringstream e; status.SetError(cmStrCat("could not find TARGET ", name,
e << "could not find TARGET " << name ". Perhaps it has not yet been created."));
<< ". Perhaps it has not yet been created.";
status.SetError(e.str());
return false; return false;
} }
@@ -352,9 +346,8 @@ bool HandleSourceMode(cmExecutionStatus& status, const std::string& name,
return StoreResult(infoType, status.GetMakefile(), variable, return StoreResult(infoType, status.GetMakefile(), variable,
sf->GetPropertyForUser(propertyName)); sf->GetPropertyForUser(propertyName));
} }
std::ostringstream e; status.SetError(
e << "given SOURCE name that could not be found or created: " << name; cmStrCat("given SOURCE name that could not be found or created: ", name));
status.SetError(e.str());
return false; return false;
} }
@@ -374,9 +367,7 @@ bool HandleTestMode(cmExecutionStatus& status, const std::string& name,
} }
// If not found it is an error. // If not found it is an error.
std::ostringstream e; status.SetError(cmStrCat("given TEST name that does not exist: ", name));
e << "given TEST name that does not exist: " << name;
status.SetError(e.str());
return false; return false;
} }
@@ -431,9 +422,8 @@ bool HandleInstallMode(cmExecutionStatus& status, const std::string& name,
return StoreResult(infoType, status.GetMakefile(), variable, return StoreResult(infoType, status.GetMakefile(), variable,
isSet ? value.c_str() : nullptr); isSet ? value.c_str() : nullptr);
} }
std::ostringstream e; status.SetError(
e << "given INSTALL name that could not be found or created: " << name; cmStrCat("given INSTALL name that could not be found or created: ", name));
status.SetError(e.str());
return false; return false;
} }
} }
+124 -190
View File
@@ -293,9 +293,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
if (!unknownArgs.empty()) { if (!unknownArgs.empty()) {
// Unknown argument. // Unknown argument.
std::ostringstream e; this->SetError(
e << "TARGETS given unknown argument \"" << unknownArgs[0] << "\"."; cmStrCat("TARGETS given unknown argument \"", unknownArgs[0], "\"."));
this->SetError(e.str());
return false; return false;
} }
@@ -391,9 +390,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
for (std::string const& tgt : targetList) { for (std::string const& tgt : targetList) {
if (this->Makefile->IsAlias(tgt)) { if (this->Makefile->IsAlias(tgt)) {
std::ostringstream e; this->SetError(
e << "TARGETS given target \"" << tgt << "\" which is an alias."; cmStrCat("TARGETS given target \"", tgt, "\" which is an alias."));
this->SetError(e.str());
return false; return false;
} }
// Lookup this target in the current directory. // Lookup this target in the current directory.
@@ -414,19 +412,17 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
target->GetType() != cmStateEnums::MODULE_LIBRARY && target->GetType() != cmStateEnums::MODULE_LIBRARY &&
target->GetType() != cmStateEnums::OBJECT_LIBRARY && target->GetType() != cmStateEnums::OBJECT_LIBRARY &&
target->GetType() != cmStateEnums::INTERFACE_LIBRARY) { target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
std::ostringstream e; this->SetError(
e << "TARGETS given target \"" << tgt cmStrCat("TARGETS given target \"", tgt,
<< "\" which is not an executable, library, or module."; "\" which is not an executable, library, or module."));
this->SetError(e.str());
return false; return false;
} }
// Store the target in the list to be installed. // Store the target in the list to be installed.
targets.push_back(target); targets.push_back(target);
} else { } else {
// Did not find the target. // Did not find the target.
std::ostringstream e; this->SetError(
e << "TARGETS given target \"" << tgt << "\" which does not exist."; cmStrCat("TARGETS given target \"", tgt, "\" which does not exist."));
this->SetError(e.str());
return false; return false;
} }
} }
@@ -507,11 +503,10 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
frameworkGenerator = CreateInstallTargetGenerator( frameworkGenerator = CreateInstallTargetGenerator(
target, frameworkArgs, false, this->Makefile->GetBacktrace()); target, frameworkArgs, false, this->Makefile->GetBacktrace());
} else { } else {
std::ostringstream e; this->SetError(
e << "TARGETS given no FRAMEWORK DESTINATION for shared library " cmStrCat("TARGETS given no FRAMEWORK DESTINATION for shared "
"FRAMEWORK target \"" "library FRAMEWORK target \"",
<< target.GetName() << "\"."; target.GetName(), "\"."));
this->SetError(e.str());
return false; return false;
} }
} else { } else {
@@ -549,11 +544,11 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
frameworkGenerator = CreateInstallTargetGenerator( frameworkGenerator = CreateInstallTargetGenerator(
target, frameworkArgs, false, this->Makefile->GetBacktrace()); target, frameworkArgs, false, this->Makefile->GetBacktrace());
} else { } else {
std::ostringstream e; this->SetError(
e << "TARGETS given no FRAMEWORK DESTINATION for static library " cmStrCat("TARGETS given no FRAMEWORK DESTINATION for static "
"FRAMEWORK target \"" "library FRAMEWORK target \"",
<< target.GetName() << "\"."; target.GetName(), "\"."));
this->SetError(e.str());
return false; return false;
} }
} else { } else {
@@ -572,10 +567,10 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
namelinkOnly = namelinkOnly =
(namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly); (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
} else { } else {
std::ostringstream e; this->SetError(
e << "TARGETS given no LIBRARY DESTINATION for module target \"" cmStrCat("TARGETS given no LIBRARY DESTINATION for module "
<< target.GetName() << "\"."; "target \"",
this->SetError(e.str()); target.GetName(), "\"."));
return false; return false;
} }
} break; } break;
@@ -586,10 +581,9 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
std::string reason; std::string reason;
if (!this->Makefile->GetGlobalGenerator() if (!this->Makefile->GetGlobalGenerator()
->HasKnownObjectFileLocation(&reason)) { ->HasKnownObjectFileLocation(&reason)) {
std::ostringstream e; this->SetError(
e << "TARGETS given OBJECT library \"" << target.GetName() cmStrCat("TARGETS given OBJECT library \"", target.GetName(),
<< "\" whose objects may not be installed" << reason << "."; "\" whose objects may not be installed", reason, "."));
this->SetError(e.str());
return false; return false;
} }
@@ -619,11 +613,9 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
} }
} }
if (!bundleGenerator) { if (!bundleGenerator) {
std::ostringstream e; this->SetError(cmStrCat("TARGETS given no BUNDLE DESTINATION for "
e << "TARGETS given no BUNDLE DESTINATION for MACOSX_BUNDLE " "MACOSX_BUNDLE executable target \"",
"executable target \"" target.GetName(), "\"."));
<< target.GetName() << "\".";
this->SetError(e.str());
return false; return false;
} }
} else { } else {
@@ -708,10 +700,10 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
resourceGenerator = CreateInstallFilesGenerator( resourceGenerator = CreateInstallFilesGenerator(
this->Makefile, absFiles, resourceArgs, false); this->Makefile, absFiles, resourceArgs, false);
} else { } else {
std::ostringstream e; cmSystemTools::Message(
e << "INSTALL TARGETS - target " << target.GetName() << " has " cmStrCat("INSTALL TARGETS - target ", target.GetName(),
<< "RESOURCE files but no RESOURCE DESTINATION."; " has RESOURCE files but no RESOURCE DESTINATION."),
cmSystemTools::Message(e.str(), "Warning"); "Warning");
} }
} }
} }
@@ -820,17 +812,15 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
if (!unknownArgs.empty()) { if (!unknownArgs.empty()) {
// Unknown argument. // Unknown argument.
std::ostringstream e; this->SetError(
e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\"."; cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\"."));
this->SetError(e.str());
return false; return false;
} }
std::string type = ica.GetType(); std::string type = ica.GetType();
if (!type.empty() && allowedTypes.count(type) == 0) { if (!type.empty() && allowedTypes.count(type) == 0) {
std::ostringstream e; this->SetError(
e << args[0] << " given non-type \"" << type << "\" with TYPE argument."; cmStrCat(args[0], " given non-type \"", type, "\" with TYPE argument."));
this->SetError(e.str());
return false; return false;
} }
@@ -843,9 +833,8 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
if (!ica.GetRename().empty() && filesVector.size() > 1) { if (!ica.GetRename().empty() && filesVector.size() > 1) {
// The rename option works only with one file. // The rename option works only with one file.
std::ostringstream e; this->SetError(
e << args[0] << " given RENAME option with more than one file."; cmStrCat(args[0], " given RENAME option with more than one file."));
this->SetError(e.str());
return false; return false;
} }
@@ -897,20 +886,16 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
} }
if (!type.empty() && !ica.GetDestination().empty()) { if (!type.empty() && !ica.GetDestination().empty()) {
std::ostringstream e; this->SetError(cmStrCat(args[0],
e << args[0] " given both TYPE and DESTINATION arguments. "
<< " given both TYPE and DESTINATION arguments. You may only specify " "You may only specify one."));
"one.";
this->SetError(e.str());
return false; return false;
} }
std::string destination = this->GetDestinationForType(&ica, type); std::string destination = this->GetDestinationForType(&ica, type);
if (destination.empty()) { if (destination.empty()) {
// A destination is required. // A destination is required.
std::ostringstream e; this->SetError(cmStrCat(args[0], " given no DESTINATION!"));
e << args[0] << " given no DESTINATION!";
this->SetError(e.str());
return false; return false;
} }
@@ -959,10 +944,8 @@ bool cmInstallCommand::HandleDirectoryMode(
for (unsigned int i = 1; i < args.size(); ++i) { for (unsigned int i = 1; i < args.size(); ++i) {
if (args[i] == "DESTINATION") { if (args[i] == "DESTINATION") {
if (in_match_mode) { if (in_match_mode) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " does not allow \"", args[i],
e << args[0] << " does not allow \"" << args[i] "\" after PATTERN or REGEX."));
<< "\" after PATTERN or REGEX.";
this->SetError(e.str());
return false; return false;
} }
@@ -970,10 +953,8 @@ bool cmInstallCommand::HandleDirectoryMode(
doing = DoingDestination; doing = DoingDestination;
} else if (args[i] == "TYPE") { } else if (args[i] == "TYPE") {
if (in_match_mode) { if (in_match_mode) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " does not allow \"", args[i],
e << args[0] << " does not allow \"" << args[i] "\" after PATTERN or REGEX."));
<< "\" after PATTERN or REGEX.";
this->SetError(e.str());
return false; return false;
} }
@@ -981,10 +962,8 @@ bool cmInstallCommand::HandleDirectoryMode(
doing = DoingType; doing = DoingType;
} else if (args[i] == "OPTIONAL") { } else if (args[i] == "OPTIONAL") {
if (in_match_mode) { if (in_match_mode) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " does not allow \"", args[i],
e << args[0] << " does not allow \"" << args[i] "\" after PATTERN or REGEX."));
<< "\" after PATTERN or REGEX.";
this->SetError(e.str());
return false; return false;
} }
@@ -993,10 +972,8 @@ bool cmInstallCommand::HandleDirectoryMode(
doing = DoingNone; doing = DoingNone;
} else if (args[i] == "MESSAGE_NEVER") { } else if (args[i] == "MESSAGE_NEVER") {
if (in_match_mode) { if (in_match_mode) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " does not allow \"", args[i],
e << args[0] << " does not allow \"" << args[i] "\" after PATTERN or REGEX."));
<< "\" after PATTERN or REGEX.";
this->SetError(e.str());
return false; return false;
} }
@@ -1014,20 +991,16 @@ bool cmInstallCommand::HandleDirectoryMode(
} else if (args[i] == "EXCLUDE") { } else if (args[i] == "EXCLUDE") {
// Add this property to the current match rule. // Add this property to the current match rule.
if (!in_match_mode || doing == DoingPattern || doing == DoingRegex) { if (!in_match_mode || doing == DoingPattern || doing == DoingRegex) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " does not allow \"", args[i],
e << args[0] << " does not allow \"" << args[i] "\" before a PATTERN or REGEX is given."));
<< "\" before a PATTERN or REGEX is given.";
this->SetError(e.str());
return false; return false;
} }
literal_args += " EXCLUDE"; literal_args += " EXCLUDE";
doing = DoingNone; doing = DoingNone;
} else if (args[i] == "PERMISSIONS") { } else if (args[i] == "PERMISSIONS") {
if (!in_match_mode) { if (!in_match_mode) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " does not allow \"", args[i],
e << args[0] << " does not allow \"" << args[i] "\" before a PATTERN or REGEX is given."));
<< "\" before a PATTERN or REGEX is given.";
this->SetError(e.str());
return false; return false;
} }
@@ -1036,10 +1009,8 @@ bool cmInstallCommand::HandleDirectoryMode(
doing = DoingPermsMatch; doing = DoingPermsMatch;
} else if (args[i] == "FILE_PERMISSIONS") { } else if (args[i] == "FILE_PERMISSIONS") {
if (in_match_mode) { if (in_match_mode) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " does not allow \"", args[i],
e << args[0] << " does not allow \"" << args[i] "\" after PATTERN or REGEX."));
<< "\" after PATTERN or REGEX.";
this->SetError(e.str());
return false; return false;
} }
@@ -1047,10 +1018,8 @@ bool cmInstallCommand::HandleDirectoryMode(
doing = DoingPermsFile; doing = DoingPermsFile;
} else if (args[i] == "DIRECTORY_PERMISSIONS") { } else if (args[i] == "DIRECTORY_PERMISSIONS") {
if (in_match_mode) { if (in_match_mode) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " does not allow \"", args[i],
e << args[0] << " does not allow \"" << args[i] "\" after PATTERN or REGEX."));
<< "\" after PATTERN or REGEX.";
this->SetError(e.str());
return false; return false;
} }
@@ -1058,10 +1027,8 @@ bool cmInstallCommand::HandleDirectoryMode(
doing = DoingPermsDir; doing = DoingPermsDir;
} else if (args[i] == "USE_SOURCE_PERMISSIONS") { } else if (args[i] == "USE_SOURCE_PERMISSIONS") {
if (in_match_mode) { if (in_match_mode) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " does not allow \"", args[i],
e << args[0] << " does not allow \"" << args[i] "\" after PATTERN or REGEX."));
<< "\" after PATTERN or REGEX.";
this->SetError(e.str());
return false; return false;
} }
@@ -1070,10 +1037,8 @@ bool cmInstallCommand::HandleDirectoryMode(
doing = DoingNone; doing = DoingNone;
} else if (args[i] == "FILES_MATCHING") { } else if (args[i] == "FILES_MATCHING") {
if (in_match_mode) { if (in_match_mode) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " does not allow \"", args[i],
e << args[0] << " does not allow \"" << args[i] "\" after PATTERN or REGEX."));
<< "\" after PATTERN or REGEX.";
this->SetError(e.str());
return false; return false;
} }
@@ -1082,10 +1047,8 @@ bool cmInstallCommand::HandleDirectoryMode(
doing = DoingNone; doing = DoingNone;
} else if (args[i] == "CONFIGURATIONS") { } else if (args[i] == "CONFIGURATIONS") {
if (in_match_mode) { if (in_match_mode) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " does not allow \"", args[i],
e << args[0] << " does not allow \"" << args[i] "\" after PATTERN or REGEX."));
<< "\" after PATTERN or REGEX.";
this->SetError(e.str());
return false; return false;
} }
@@ -1093,10 +1056,8 @@ bool cmInstallCommand::HandleDirectoryMode(
doing = DoingConfigurations; doing = DoingConfigurations;
} else if (args[i] == "COMPONENT") { } else if (args[i] == "COMPONENT") {
if (in_match_mode) { if (in_match_mode) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " does not allow \"", args[i],
e << args[0] << " does not allow \"" << args[i] "\" after PATTERN or REGEX."));
<< "\" after PATTERN or REGEX.";
this->SetError(e.str());
return false; return false;
} }
@@ -1104,10 +1065,8 @@ bool cmInstallCommand::HandleDirectoryMode(
doing = DoingComponent; doing = DoingComponent;
} else if (args[i] == "EXCLUDE_FROM_ALL") { } else if (args[i] == "EXCLUDE_FROM_ALL") {
if (in_match_mode) { if (in_match_mode) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " does not allow \"", args[i],
e << args[0] << " does not allow \"" << args[i] "\" after PATTERN or REGEX."));
<< "\" after PATTERN or REGEX.";
this->SetError(e.str());
return false; return false;
} }
exclude_from_all = true; exclude_from_all = true;
@@ -1124,10 +1083,8 @@ bool cmInstallCommand::HandleDirectoryMode(
// Make sure the name is a directory. // Make sure the name is a directory.
if (cmSystemTools::FileExists(dir) && if (cmSystemTools::FileExists(dir) &&
!cmSystemTools::FileIsDirectory(dir)) { !cmSystemTools::FileIsDirectory(dir)) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " given non-directory \"", args[i],
e << args[0] << " given non-directory \"" << args[i] "\" to install."));
<< "\" to install.";
this->SetError(e.str());
return false; return false;
} }
@@ -1140,10 +1097,8 @@ bool cmInstallCommand::HandleDirectoryMode(
doing = DoingNone; doing = DoingNone;
} else if (doing == DoingType) { } else if (doing == DoingType) {
if (allowedTypes.count(args[i]) == 0) { if (allowedTypes.count(args[i]) == 0) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " given non-type \"", args[i],
e << args[0] << " given non-type \"" << args[i] "\" with TYPE argument."));
<< "\" with TYPE argument.";
this->SetError(e.str());
return false; return false;
} }
@@ -1179,36 +1134,30 @@ bool cmInstallCommand::HandleDirectoryMode(
// Check the requested permission. // Check the requested permission.
if (!cmInstallCommandArguments::CheckPermissions(args[i], if (!cmInstallCommandArguments::CheckPermissions(args[i],
permissions_file)) { permissions_file)) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " given invalid file permission \"",
e << args[0] << " given invalid file permission \"" << args[i] args[i], "\"."));
<< "\".";
this->SetError(e.str());
return false; return false;
} }
} else if (doing == DoingPermsDir) { } else if (doing == DoingPermsDir) {
// Check the requested permission. // Check the requested permission.
if (!cmInstallCommandArguments::CheckPermissions(args[i], if (!cmInstallCommandArguments::CheckPermissions(args[i],
permissions_dir)) { permissions_dir)) {
std::ostringstream e; this->SetError(cmStrCat(
e << args[0] << " given invalid directory permission \"" << args[i] args[0], " given invalid directory permission \"", args[i], "\"."));
<< "\".";
this->SetError(e.str());
return false; return false;
} }
} else if (doing == DoingPermsMatch) { } else if (doing == DoingPermsMatch) {
// Check the requested permission. // Check the requested permission.
if (!cmInstallCommandArguments::CheckPermissions(args[i], if (!cmInstallCommandArguments::CheckPermissions(args[i],
literal_args)) { literal_args)) {
std::ostringstream e; this->SetError(
e << args[0] << " given invalid permission \"" << args[i] << "\"."; cmStrCat(args[0], " given invalid permission \"", args[i], "\"."));
this->SetError(e.str());
return false; return false;
} }
} else { } else {
// Unknown argument. // Unknown argument.
std::ostringstream e; this->SetError(
e << args[0] << " given unknown argument \"" << args[i] << "\"."; cmStrCat(args[0], " given unknown argument \"", args[i], "\"."));
this->SetError(e.str());
return false; return false;
} }
} }
@@ -1226,19 +1175,15 @@ bool cmInstallCommand::HandleDirectoryMode(
if (!destination) { if (!destination) {
if (type.empty()) { if (type.empty()) {
// A destination is required. // A destination is required.
std::ostringstream e; this->SetError(cmStrCat(args[0], " given no DESTINATION!"));
e << args[0] << " given no DESTINATION!";
this->SetError(e.str());
return false; return false;
} }
destinationStr = this->GetDestinationForType(nullptr, type); destinationStr = this->GetDestinationForType(nullptr, type);
destination = destinationStr.c_str(); destination = destinationStr.c_str();
} else if (!type.empty()) { } else if (!type.empty()) {
std::ostringstream e; this->SetError(cmStrCat(args[0],
e << args[0] " given both TYPE and DESTINATION "
<< " given both TYPE and DESTINATION arguments. You may only specify " "arguments. You may only specify one."));
"one.";
this->SetError(e.str());
return false; return false;
} }
@@ -1280,9 +1225,8 @@ bool cmInstallCommand::HandleExportAndroidMKMode(
if (!unknownArgs.empty()) { if (!unknownArgs.empty()) {
// Unknown argument. // Unknown argument.
std::ostringstream e; this->SetError(
e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\"."; cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\"."));
this->SetError(e.str());
return false; return false;
} }
@@ -1293,39 +1237,35 @@ bool cmInstallCommand::HandleExportAndroidMKMode(
// Make sure there is a destination. // Make sure there is a destination.
if (ica.GetDestination().empty()) { if (ica.GetDestination().empty()) {
// A destination is required. // A destination is required.
std::ostringstream e; this->SetError(cmStrCat(args[0], " given no DESTINATION!"));
e << args[0] << " given no DESTINATION!";
this->SetError(e.str());
return false; return false;
} }
// Check the file name. // Check the file name.
std::string fname = filename; std::string fname = filename;
if (fname.find_first_of(":/\\") != std::string::npos) { if (fname.find_first_of(":/\\") != std::string::npos) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " given invalid export file name \"",
e << args[0] << " given invalid export file name \"" << fname << "\". " fname,
<< "The FILE argument may not contain a path. " "\". The FILE argument may not contain a path. "
<< "Specify the path in the DESTINATION argument."; "Specify the path in the DESTINATION argument."));
this->SetError(e.str());
return false; return false;
} }
// Check the file extension. // Check the file extension.
if (!fname.empty() && if (!fname.empty() &&
cmSystemTools::GetFilenameLastExtension(fname) != ".mk") { cmSystemTools::GetFilenameLastExtension(fname) != ".mk") {
std::ostringstream e; this->SetError(cmStrCat(
e << args[0] << " given invalid export file name \"" << fname << "\". " args[0], " given invalid export file name \"", fname,
<< "The FILE argument must specify a name ending in \".mk\"."; R"(". The FILE argument must specify a name ending in ".mk".)"));
this->SetError(e.str());
return false; return false;
} }
if (fname.find_first_of(":/\\") != std::string::npos) { if (fname.find_first_of(":/\\") != std::string::npos) {
std::ostringstream e; this->SetError(
e << args[0] << " given export name \"" << exp << "\". " cmStrCat(args[0], " given export name \"", exp,
<< "This name cannot be safely converted to a file name. " "\". "
<< "Specify a different export name or use the FILE option to set " "This name cannot be safely converted to a file name. "
<< "a file name explicitly."; "Specify a different export name or use the FILE option to set "
this->SetError(e.str()); "a file name explicitly."));
return false; return false;
} }
// Use the default name // Use the default name
@@ -1375,9 +1315,8 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
if (!unknownArgs.empty()) { if (!unknownArgs.empty()) {
// Unknown argument. // Unknown argument.
std::ostringstream e; this->SetError(
e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\"."; cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\"."));
this->SetError(e.str());
return false; return false;
} }
@@ -1388,30 +1327,28 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
// Make sure there is a destination. // Make sure there is a destination.
if (ica.GetDestination().empty()) { if (ica.GetDestination().empty()) {
// A destination is required. // A destination is required.
std::ostringstream e; this->SetError(cmStrCat(args[0], " given no DESTINATION!"));
e << args[0] << " given no DESTINATION!";
this->SetError(e.str());
return false; return false;
} }
// Check the file name. // Check the file name.
std::string fname = filename; std::string fname = filename;
if (fname.find_first_of(":/\\") != std::string::npos) { if (fname.find_first_of(":/\\") != std::string::npos) {
std::ostringstream e; this->SetError(cmStrCat(args[0], " given invalid export file name \"",
e << args[0] << " given invalid export file name \"" << fname << "\". " fname,
<< "The FILE argument may not contain a path. " "\". "
<< "Specify the path in the DESTINATION argument."; "The FILE argument may not contain a path. "
this->SetError(e.str()); "Specify the path in the DESTINATION argument."));
return false; return false;
} }
// Check the file extension. // Check the file extension.
if (!fname.empty() && if (!fname.empty() &&
cmSystemTools::GetFilenameLastExtension(fname) != ".cmake") { cmSystemTools::GetFilenameLastExtension(fname) != ".cmake") {
std::ostringstream e; this->SetError(
e << args[0] << " given invalid export file name \"" << fname << "\". " cmStrCat(args[0], " given invalid export file name \"", fname,
<< "The FILE argument must specify a name ending in \".cmake\"."; "\". "
this->SetError(e.str()); "The FILE argument must specify a name ending in \".cmake\"."));
return false; return false;
} }
@@ -1420,12 +1357,12 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
fname = cmStrCat(exp, ".cmake"); fname = cmStrCat(exp, ".cmake");
if (fname.find_first_of(":/\\") != std::string::npos) { if (fname.find_first_of(":/\\") != std::string::npos) {
std::ostringstream e; this->SetError(cmStrCat(
e << args[0] << " given export name \"" << exp << "\". " args[0], " given export name \"", exp,
<< "This name cannot be safely converted to a file name. " "\". "
<< "Specify a different export name or use the FILE option to set " "This name cannot be safely converted to a file name. "
<< "a file name explicitly."; "Specify a different export name or use the FILE option to set "
this->SetError(e.str()); "a file name explicitly."));
return false; return false;
} }
} }
@@ -1441,12 +1378,10 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
tgt->GetPolicyStatusCMP0022() != cmPolicies::OLD); tgt->GetPolicyStatusCMP0022() != cmPolicies::OLD);
if (!newCMP0022Behavior) { if (!newCMP0022Behavior) {
std::ostringstream e; this->SetError(cmStrCat(
e << "INSTALL(EXPORT) given keyword \"" "INSTALL(EXPORT) given keyword \""
<< "EXPORT_LINK_INTERFACE_LIBRARIES" "EXPORT_LINK_INTERFACE_LIBRARIES\", but target \"",
<< "\", but target \"" << te->TargetName te->TargetName, "\" does not have policy CMP0022 set to NEW."));
<< "\" does not have policy CMP0022 set to NEW.";
this->SetError(e.str());
return false; return false;
} }
} }
@@ -1480,9 +1415,8 @@ bool cmInstallCommand::MakeFilesFullPath(
// Make sure the file is not a directory. // Make sure the file is not a directory.
if (gpos == std::string::npos && cmSystemTools::FileIsDirectory(file)) { if (gpos == std::string::npos && cmSystemTools::FileIsDirectory(file)) {
std::ostringstream e; this->SetError(
e << modeName << " given directory \"" << relFile << "\" to install."; cmStrCat(modeName, " given directory \"", relFile, "\" to install."));
this->SetError(e.str());
return false; return false;
} }
// Store the file for installation. // Store the file for installation.
+42 -69
View File
@@ -158,10 +158,8 @@ bool HandleGetCommand(std::vector<std::string> const& args,
item = static_cast<int>(nitem) + item; item = static_cast<int>(nitem) + item;
} }
if (item < 0 || nitem <= static_cast<size_t>(item)) { if (item < 0 || nitem <= static_cast<size_t>(item)) {
std::ostringstream str; status.SetError(cmStrCat("index: ", item, " out of range (-", nitem,
str << "index: " << item << " out of range (-" << nitem << ", " ", ", nitem - 1, ")"));
<< nitem - 1 << ")";
status.SetError(str.str());
return false; return false;
} }
value += varArgsExpanded[item]; value += varArgsExpanded[item];
@@ -366,9 +364,7 @@ bool HandleInsertCommand(std::vector<std::string> const& args,
if ((!GetList(varArgsExpanded, listName, status.GetMakefile()) || if ((!GetList(varArgsExpanded, listName, status.GetMakefile()) ||
varArgsExpanded.empty()) && varArgsExpanded.empty()) &&
item != 0) { item != 0) {
std::ostringstream str; status.SetError(cmStrCat("index: ", item, " out of range (0, 0)"));
str << "index: " << item << " out of range (0, 0)";
status.SetError(str.str());
return false; return false;
} }
@@ -378,10 +374,9 @@ bool HandleInsertCommand(std::vector<std::string> const& args,
item = static_cast<int>(nitem) + item; item = static_cast<int>(nitem) + item;
} }
if (item < 0 || nitem < static_cast<size_t>(item)) { if (item < 0 || nitem < static_cast<size_t>(item)) {
std::ostringstream str; status.SetError(cmStrCat("index: ", item, " out of range (-",
str << "index: " << item << " out of range (-" << varArgsExpanded.size() varArgsExpanded.size(), ", ",
<< ", " << varArgsExpanded.size() << ")"; varArgsExpanded.size(), ")"));
status.SetError(str.str());
return false; return false;
} }
} }
@@ -398,10 +393,8 @@ bool HandleJoinCommand(std::vector<std::string> const& args,
cmExecutionStatus& status) cmExecutionStatus& status)
{ {
if (args.size() != 4) { if (args.size() != 4) {
std::ostringstream error; status.SetError(cmStrCat("sub-command JOIN requires three arguments (",
error << "sub-command JOIN requires three arguments (" << args.size() - 1 args.size() - 1, " found)."));
<< " found).";
status.SetError(error.str());
return false; return false;
} }
@@ -596,11 +589,9 @@ protected:
index = static_cast<int>(count) + index; index = static_cast<int>(count) + index;
} }
if (index < 0 || count <= static_cast<std::size_t>(index)) { if (index < 0 || count <= static_cast<std::size_t>(index)) {
std::ostringstream str; throw transform_error(cmStrCat(
str << "sub-command TRANSFORM, selector " << this->Tag "sub-command TRANSFORM, selector ", this->Tag, ", index: ", index,
<< ", index: " << index << " out of range (-" << count << ", " " out of range (-", count, ", ", count - 1, ")."));
<< count - 1 << ").";
throw transform_error(str.str());
} }
return index; return index;
} }
@@ -681,17 +672,14 @@ public:
makefile->ClearMatches(); makefile->ClearMatches();
if (!this->ReplaceHelper.IsRegularExpressionValid()) { if (!this->ReplaceHelper.IsRegularExpressionValid()) {
std::ostringstream error; throw transform_error(
error cmStrCat("sub-command TRANSFORM, action REPLACE: Failed to compile "
<< "sub-command TRANSFORM, action REPLACE: Failed to compile regex \"" "regex \"",
<< arguments[0] << "\"."; arguments[0], "\"."));
throw transform_error(error.str());
} }
if (!this->ReplaceHelper.IsReplaceExpressionValid()) { if (!this->ReplaceHelper.IsReplaceExpressionValid()) {
std::ostringstream error; throw transform_error(cmStrCat("sub-command TRANSFORM, action REPLACE: ",
error << "sub-command TRANSFORM, action REPLACE: " this->ReplaceHelper.GetError(), "."));
<< this->ReplaceHelper.GetError() << ".";
throw transform_error(error.str());
} }
} }
@@ -701,10 +689,8 @@ public:
std::string output; std::string output;
if (!this->ReplaceHelper.Replace(input, output)) { if (!this->ReplaceHelper.Replace(input, output)) {
std::ostringstream error; throw transform_error(cmStrCat("sub-command TRANSFORM, action REPLACE: ",
error << "sub-command TRANSFORM, action REPLACE: " this->ReplaceHelper.GetError(), "."));
<< this->ReplaceHelper.GetError() << ".";
throw transform_error(error.str());
} }
return output; return output;
@@ -839,19 +825,17 @@ bool HandleTransformCommand(std::vector<std::string> const& args,
auto descriptor = descriptors.find(args[index]); auto descriptor = descriptors.find(args[index]);
if (descriptor == descriptors.end()) { if (descriptor == descriptors.end()) {
std::ostringstream error; status.SetError(
error << " sub-command TRANSFORM, " << args[index] << " invalid action."; cmStrCat(" sub-command TRANSFORM, ", args[index], " invalid action."));
status.SetError(error.str());
return false; return false;
} }
// Action arguments // Action arguments
index += 1; index += 1;
if (args.size() < index + descriptor->Arity) { if (args.size() < index + descriptor->Arity) {
std::ostringstream error; status.SetError(cmStrCat("sub-command TRANSFORM, action ",
error << "sub-command TRANSFORM, action " << descriptor->Name descriptor->Name, " expects ", descriptor->Arity,
<< " expects " << descriptor->Arity << " argument(s)."; " argument(s)."));
status.SetError(error.str());
return false; return false;
} }
@@ -881,10 +865,10 @@ bool HandleTransformCommand(std::vector<std::string> const& args,
while (args.size() > index) { while (args.size() > index) {
if ((args[index] == REGEX || args[index] == AT || args[index] == FOR) && if ((args[index] == REGEX || args[index] == AT || args[index] == FOR) &&
command.Selector) { command.Selector) {
std::ostringstream error; status.SetError(
error << "sub-command TRANSFORM, selector already specified (" cmStrCat("sub-command TRANSFORM, selector already specified (",
<< command.Selector->Tag << ")."; command.Selector->Tag, ")."));
status.SetError(error.str());
return false; return false;
} }
@@ -898,11 +882,10 @@ bool HandleTransformCommand(std::vector<std::string> const& args,
command.Selector = cm::make_unique<TransformSelectorRegex>(args[index]); command.Selector = cm::make_unique<TransformSelectorRegex>(args[index]);
if (!command.Selector->Validate()) { if (!command.Selector->Validate()) {
std::ostringstream error; status.SetError(
error << "sub-command TRANSFORM, selector REGEX failed to compile " cmStrCat("sub-command TRANSFORM, selector REGEX failed to compile "
"regex \""; "regex \"",
error << args[index] << "\"."; args[index], "\"."));
status.SetError(error.str());
return false; return false;
} }
@@ -1020,11 +1003,9 @@ bool HandleTransformCommand(std::vector<std::string> const& args,
continue; continue;
} }
std::ostringstream error; status.SetError(cmStrCat("sub-command TRANSFORM, '",
error << "sub-command TRANSFORM, '" cmJoin(cmMakeRange(args).advance(index), " "),
<< cmJoin(cmMakeRange(args).advance(index), " ") "': unexpected argument(s)."));
<< "': unexpected argument(s).";
status.SetError(error.str());
return false; return false;
} }
@@ -1261,10 +1242,8 @@ bool HandleSublistCommand(std::vector<std::string> const& args,
cmExecutionStatus& status) cmExecutionStatus& status)
{ {
if (args.size() != 5) { if (args.size() != 5) {
std::ostringstream error; status.SetError(cmStrCat("sub-command SUBLIST requires four arguments (",
error << "sub-command SUBLIST requires four arguments (" << args.size() - 1 args.size() - 1, " found)."));
<< " found).";
status.SetError(error.str());
return false; return false;
} }
@@ -1285,16 +1264,12 @@ bool HandleSublistCommand(std::vector<std::string> const& args,
using size_type = decltype(varArgsExpanded)::size_type; using size_type = decltype(varArgsExpanded)::size_type;
if (start < 0 || size_type(start) >= varArgsExpanded.size()) { if (start < 0 || size_type(start) >= varArgsExpanded.size()) {
std::ostringstream error; status.SetError(cmStrCat("begin index: ", start, " is out of range 0 - ",
error << "begin index: " << start << " is out of range 0 - " varArgsExpanded.size() - 1));
<< varArgsExpanded.size() - 1;
status.SetError(error.str());
return false; return false;
} }
if (length < -1) { if (length < -1) {
std::ostringstream error; status.SetError(cmStrCat("length: ", length, " should be -1 or greater"));
error << "length: " << length << " should be -1 or greater";
status.SetError(error.str());
return false; return false;
} }
@@ -1344,10 +1319,8 @@ bool HandleRemoveAtCommand(std::vector<std::string> const& args,
item = static_cast<int>(nitem) + item; item = static_cast<int>(nitem) + item;
} }
if (item < 0 || nitem <= static_cast<size_t>(item)) { if (item < 0 || nitem <= static_cast<size_t>(item)) {
std::ostringstream str; status.SetError(cmStrCat("index: ", item, " out of range (-", nitem,
str << "index: " << item << " out of range (-" << nitem << ", " ", ", nitem - 1, ")"));
<< nitem - 1 << ")";
status.SetError(str.str());
return false; return false;
} }
removed.push_back(static_cast<size_t>(item)); removed.push_back(static_cast<size_t>(item));
+3 -4
View File
@@ -7,7 +7,7 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <sstream>
#include <utility> #include <utility>
#include "cm_memory.hxx" #include "cm_memory.hxx"
@@ -207,9 +207,8 @@ bool cmLoadCommandCommand(std::vector<std::string> const& args,
// Try to find the program. // Try to find the program.
std::string fullPath = cmSystemTools::FindFile(moduleName, path); std::string fullPath = cmSystemTools::FindFile(moduleName, path);
if (fullPath.empty()) { if (fullPath.empty()) {
std::ostringstream e; status.SetError(cmStrCat("Attempt to load command failed from file \"",
e << "Attempt to load command failed from file \"" << moduleName << "\""; moduleName, "\""));
status.SetError(e.str());
return false; return false;
} }
+7 -9
View File
@@ -2,8 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmOptionCommand.h" #include "cmOptionCommand.h"
#include <sstream>
#include "cmExecutionStatus.h" #include "cmExecutionStatus.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmMessageType.h" #include "cmMessageType.h"
@@ -74,13 +72,13 @@ bool cmOptionCommand(std::vector<std::string> const& args,
const auto* existsAfterSet = const auto* existsAfterSet =
status.GetMakefile().GetStateSnapshot().GetDefinition(args[0]); status.GetMakefile().GetStateSnapshot().GetDefinition(args[0]);
if (!existsAfterSet) { if (!existsAfterSet) {
std::ostringstream w; status.GetMakefile().IssueMessage(
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0077) MessageType::AUTHOR_WARNING,
<< "\n" cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0077),
"For compatibility with older versions of CMake, option " "\n"
"is clearing the normal variable '" "For compatibility with older versions of CMake, option "
<< args[0] << "'."; "is clearing the normal variable '",
status.GetMakefile().IssueMessage(MessageType::AUTHOR_WARNING, w.str()); args[0], "'."));
} }
} }
return true; return true;
+7 -7
View File
@@ -465,14 +465,14 @@ void cmOrderDirectories::FindImplicitConflicts()
} }
// Warn about the conflicts. // Warn about the conflicts.
std::ostringstream w;
w << "Cannot generate a safe " << this->Purpose << " for target "
<< this->Target->GetName()
<< " because files in some directories may conflict with "
<< " libraries in implicit directories:\n"
<< text << "Some of these libraries may not be found correctly.";
this->GlobalGenerator->GetCMakeInstance()->IssueMessage( this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
MessageType::WARNING, w.str(), this->Target->GetBacktrace()); MessageType::WARNING,
cmStrCat("Cannot generate a safe ", this->Purpose, " for target ",
this->Target->GetName(),
" because files in some directories may "
"conflict with libraries in implicit directories:\n",
text, "Some of these libraries may not be found correctly."),
this->Target->GetBacktrace());
} }
void cmOrderDirectories::OrderDirectories() void cmOrderDirectories::OrderDirectories()
+4 -5
View File
@@ -8,7 +8,6 @@
#include <cstdio> #include <cstdio>
#include <functional> #include <functional>
#include <limits> #include <limits>
#include <sstream>
#include <utility> #include <utility>
#include "cmMakefile.h" #include "cmMakefile.h"
@@ -320,10 +319,10 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
} }
} }
if (!vw.empty()) { if (!vw.empty()) {
std::ostringstream w; this->Makefile->IssueMessage(
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0048) MessageType::AUTHOR_WARNING,
<< "\nThe following variable(s) would be set to empty:" << vw; cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0048),
this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); "\nThe following variable(s) would be set to empty:", vw));
} }
} }
+2 -4
View File
@@ -3,10 +3,10 @@
#include "cmSeparateArgumentsCommand.h" #include "cmSeparateArgumentsCommand.h"
#include <algorithm> #include <algorithm>
#include <sstream>
#include "cmExecutionStatus.h" #include "cmExecutionStatus.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h" #include "cmSystemTools.h"
// cmSeparateArgumentsCommand // cmSeparateArgumentsCommand
@@ -56,9 +56,7 @@ bool cmSeparateArgumentsCommand(std::vector<std::string> const& args,
command = arg; command = arg;
doing = DoingNone; doing = DoingNone;
} else { } else {
std::ostringstream e; status.SetError(cmStrCat("given unknown argument ", arg));
e << "given unknown argument " << arg;
status.SetError(e.str());
return false; return false;
} }
} }
+22 -34
View File
@@ -100,11 +100,10 @@ bool cmSetPropertyCommand(std::vector<std::string> const& args,
} else if (scopeName == "INSTALL") { } else if (scopeName == "INSTALL") {
scope = cmProperty::INSTALL; scope = cmProperty::INSTALL;
} else { } else {
std::ostringstream e; status.SetError(cmStrCat("given invalid scope ", scopeName,
e << "given invalid scope " << scopeName << ". " ". "
<< "Valid scopes are GLOBAL, DIRECTORY, " "Valid scopes are GLOBAL, DIRECTORY, "
"TARGET, SOURCE, TEST, CACHE, INSTALL."; "TARGET, SOURCE, TEST, CACHE, INSTALL."));
status.SetError(e.str());
return false; return false;
} }
@@ -149,9 +148,7 @@ bool cmSetPropertyCommand(std::vector<std::string> const& args,
propertyValue += arg; propertyValue += arg;
remove = false; remove = false;
} else { } else {
std::ostringstream e; status.SetError(cmStrCat("given invalid argument \"", arg, "\"."));
e << "given invalid argument \"" << arg << "\".";
status.SetError(e.str());
return false; return false;
} }
} }
@@ -293,10 +290,8 @@ bool HandleTargetMode(cmExecutionStatus& status,
return false; return false;
} }
} else { } else {
std::ostringstream e; status.SetError(cmStrCat("could not find TARGET ", name,
e << "could not find TARGET " << name ". Perhaps it has not yet been created."));
<< ". Perhaps it has not yet been created.";
status.SetError(e.str());
return false; return false;
} }
} }
@@ -340,9 +335,8 @@ bool HandleSourceMode(cmExecutionStatus& status,
return false; return false;
} }
} else { } else {
std::ostringstream e; status.SetError(cmStrCat(
e << "given SOURCE name that could not be found or created: " << name; "given SOURCE name that could not be found or created: ", name));
status.SetError(e.str());
return false; return false;
} }
} }
@@ -428,26 +422,23 @@ bool HandleCacheMode(cmExecutionStatus& status,
{ {
if (propertyName == "ADVANCED") { if (propertyName == "ADVANCED") {
if (!remove && !cmIsOn(propertyValue) && !cmIsOff(propertyValue)) { if (!remove && !cmIsOn(propertyValue) && !cmIsOff(propertyValue)) {
std::ostringstream e; status.SetError(cmStrCat("given non-boolean value \"", propertyValue,
e << "given non-boolean value \"" << propertyValue R"(" for CACHE property "ADVANCED". )"));
<< R"(" for CACHE property "ADVANCED". )";
status.SetError(e.str());
return false; return false;
} }
} else if (propertyName == "TYPE") { } else if (propertyName == "TYPE") {
if (!cmState::IsCacheEntryType(propertyValue)) { if (!cmState::IsCacheEntryType(propertyValue)) {
std::ostringstream e; status.SetError(
e << "given invalid CACHE entry TYPE \"" << propertyValue << "\""; cmStrCat("given invalid CACHE entry TYPE \"", propertyValue, "\""));
status.SetError(e.str());
return false; return false;
} }
} else if (propertyName != "HELPSTRING" && propertyName != "STRINGS" && } else if (propertyName != "HELPSTRING" && propertyName != "STRINGS" &&
propertyName != "VALUE") { propertyName != "VALUE") {
std::ostringstream e; status.SetError(
e << "given invalid CACHE property " << propertyName << ". " cmStrCat("given invalid CACHE property ", propertyName,
<< "Settable CACHE properties are: " ". "
<< "ADVANCED, HELPSTRING, STRINGS, TYPE, and VALUE."; "Settable CACHE properties are: "
status.SetError(e.str()); "ADVANCED, HELPSTRING, STRINGS, TYPE, and VALUE."));
return false; return false;
} }
@@ -462,10 +453,8 @@ bool HandleCacheMode(cmExecutionStatus& status,
return false; return false;
} }
} else { } else {
std::ostringstream e; status.SetError(cmStrCat("could not find CACHE variable ", name,
e << "could not find CACHE variable " << name ". Perhaps it has not yet been created."));
<< ". Perhaps it has not yet been created.";
status.SetError(e.str());
return false; return false;
} }
} }
@@ -511,9 +500,8 @@ bool HandleInstallMode(cmExecutionStatus& status,
return false; return false;
} }
} else { } else {
std::ostringstream e; status.SetError(cmStrCat(
e << "given INSTALL name that could not be found or created: " << name; "given INSTALL name that could not be found or created: ", name));
status.SetError(e.str());
return false; return false;
} }
} }
+9 -23
View File
@@ -11,7 +11,6 @@
#include <cstdlib> #include <cstdlib>
#include <iterator> #include <iterator>
#include <memory> #include <memory>
#include <sstream>
#include "cm_static_string_view.hxx" #include "cm_static_string_view.hxx"
@@ -46,9 +45,8 @@ bool HandleHashCommand(std::vector<std::string> const& args,
{ {
#if !defined(CMAKE_BOOTSTRAP) #if !defined(CMAKE_BOOTSTRAP)
if (args.size() != 3) { if (args.size() != 3) {
std::ostringstream e; status.SetError(
e << args[0] << " requires an output variable and an input string"; cmStrCat(args[0], " requires an output variable and an input string"));
status.SetError(e.str());
return false; return false;
} }
@@ -60,9 +58,7 @@ bool HandleHashCommand(std::vector<std::string> const& args,
} }
return false; return false;
#else #else
std::ostringstream e; status.SetError(cmStrCat(args[0], " not available during bootstrap"));
e << args[0] << " not available during bootstrap";
status.SetError(e.str().c_str());
return false; return false;
#endif #endif
} }
@@ -148,9 +144,7 @@ bool HandleConfigureCommand(std::vector<std::string> const& args,
} else if (args[i] == "ESCAPE_QUOTES") { } else if (args[i] == "ESCAPE_QUOTES") {
escapeQuotes = true; escapeQuotes = true;
} else { } else {
std::ostringstream err; status.SetError(cmStrCat("Unrecognized argument \"", args[i], "\""));
err << "Unrecognized argument \"" << args[i] << "\"";
status.SetError(err.str());
return false; return false;
} }
} }
@@ -377,9 +371,7 @@ bool HandleFindCommand(std::vector<std::string> const& args,
pos = sstring.rfind(schar); pos = sstring.rfind(schar);
} }
if (std::string::npos != pos) { if (std::string::npos != pos) {
std::ostringstream s; status.GetMakefile().AddDefinition(outvar, std::to_string(pos));
s << pos;
status.GetMakefile().AddDefinition(outvar, s.str());
return true; return true;
} }
@@ -474,16 +466,12 @@ bool HandleSubstringCommand(std::vector<std::string> const& args,
size_t stringLength = stringValue.size(); size_t stringLength = stringValue.size();
int intStringLength = static_cast<int>(stringLength); int intStringLength = static_cast<int>(stringLength);
if (begin < 0 || begin > intStringLength) { if (begin < 0 || begin > intStringLength) {
std::ostringstream ostr; status.SetError(
ostr << "begin index: " << begin << " is out of range 0 - " cmStrCat("begin index: ", begin, " is out of range 0 - ", stringLength));
<< stringLength;
status.SetError(ostr.str());
return false; return false;
} }
if (end < -1) { if (end < -1) {
std::ostringstream ostr; status.SetError(cmStrCat("end index: ", end, " should be -1 or greater"));
ostr << "end index: " << end << " should be -1 or greater";
status.SetError(ostr.str());
return false; return false;
} }
@@ -915,9 +903,7 @@ bool HandleUuidCommand(std::vector<std::string> const& args,
status.GetMakefile().AddDefinition(outputVariable, uuid); status.GetMakefile().AddDefinition(outputVariable, uuid);
return true; return true;
#else #else
std::ostringstream e; status.SetError(cmStrCat(args[0], " not available during bootstrap"));
e << args[0] << " not available during bootstrap";
status.SetError(e.str().c_str());
return false; return false;
#endif #endif
} }
+4 -7
View File
@@ -2,8 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmTargetCompileDefinitionsCommand.h" #include "cmTargetCompileDefinitionsCommand.h"
#include <sstream>
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmMessageType.h" #include "cmMessageType.h"
#include "cmStringAlgorithms.h" #include "cmStringAlgorithms.h"
@@ -20,11 +18,10 @@ bool cmTargetCompileDefinitionsCommand::InitialPass(
void cmTargetCompileDefinitionsCommand::HandleMissingTarget( void cmTargetCompileDefinitionsCommand::HandleMissingTarget(
const std::string& name) const std::string& name)
{ {
std::ostringstream e; this->Makefile->IssueMessage(
e << "Cannot specify compile definitions for target \"" << name MessageType::FATAL_ERROR,
<< "\" " cmStrCat("Cannot specify compile definitions for target \"", name,
"which is not built by this project."; "\" which is not built by this project."));
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
} }
std::string cmTargetCompileDefinitionsCommand::Join( std::string cmTargetCompileDefinitionsCommand::Join(
+4 -7
View File
@@ -2,8 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmTargetCompileFeaturesCommand.h" #include "cmTargetCompileFeaturesCommand.h"
#include <sstream>
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmMessageType.h" #include "cmMessageType.h"
#include "cmStringAlgorithms.h" #include "cmStringAlgorithms.h"
@@ -20,11 +18,10 @@ bool cmTargetCompileFeaturesCommand::InitialPass(
void cmTargetCompileFeaturesCommand::HandleMissingTarget( void cmTargetCompileFeaturesCommand::HandleMissingTarget(
const std::string& name) const std::string& name)
{ {
std::ostringstream e; this->Makefile->IssueMessage(
e << "Cannot specify compile features for target \"" << name MessageType::FATAL_ERROR,
<< "\" " cmStrCat("Cannot specify compile features for target \"", name,
"which is not built by this project."; "\" which is not built by this project."));
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
} }
std::string cmTargetCompileFeaturesCommand::Join( std::string cmTargetCompileFeaturesCommand::Join(
+4 -6
View File
@@ -2,8 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmTargetCompileOptionsCommand.h" #include "cmTargetCompileOptionsCommand.h"
#include <sstream>
#include "cmListFileCache.h" #include "cmListFileCache.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmMessageType.h" #include "cmMessageType.h"
@@ -21,10 +19,10 @@ bool cmTargetCompileOptionsCommand::InitialPass(
void cmTargetCompileOptionsCommand::HandleMissingTarget( void cmTargetCompileOptionsCommand::HandleMissingTarget(
const std::string& name) const std::string& name)
{ {
std::ostringstream e; this->Makefile->IssueMessage(
e << "Cannot specify compile options for target \"" << name MessageType::FATAL_ERROR,
<< "\" which is not built by this project."; cmStrCat("Cannot specify compile options for target \"", name,
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); "\" which is not built by this project."));
} }
std::string cmTargetCompileOptionsCommand::Join( std::string cmTargetCompileOptionsCommand::Join(
+4 -5
View File
@@ -3,7 +3,6 @@
#include "cmTargetIncludeDirectoriesCommand.h" #include "cmTargetIncludeDirectoriesCommand.h"
#include <set> #include <set>
#include <sstream>
#include "cmGeneratorExpression.h" #include "cmGeneratorExpression.h"
#include "cmListFileCache.h" #include "cmListFileCache.h"
@@ -25,10 +24,10 @@ bool cmTargetIncludeDirectoriesCommand::InitialPass(
void cmTargetIncludeDirectoriesCommand::HandleMissingTarget( void cmTargetIncludeDirectoriesCommand::HandleMissingTarget(
const std::string& name) const std::string& name)
{ {
std::ostringstream e; this->Makefile->IssueMessage(
e << "Cannot specify include directories for target \"" << name MessageType::FATAL_ERROR,
<< "\" which is not built by this project."; cmStrCat("Cannot specify include directories for target \"", name,
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); "\" which is not built by this project."));
} }
std::string cmTargetIncludeDirectoriesCommand::Join( std::string cmTargetIncludeDirectoriesCommand::Join(
+4 -6
View File
@@ -2,8 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmTargetLinkDirectoriesCommand.h" #include "cmTargetLinkDirectoriesCommand.h"
#include <sstream>
#include "cmGeneratorExpression.h" #include "cmGeneratorExpression.h"
#include "cmListFileCache.h" #include "cmListFileCache.h"
#include "cmMakefile.h" #include "cmMakefile.h"
@@ -23,10 +21,10 @@ bool cmTargetLinkDirectoriesCommand::InitialPass(
void cmTargetLinkDirectoriesCommand::HandleMissingTarget( void cmTargetLinkDirectoriesCommand::HandleMissingTarget(
const std::string& name) const std::string& name)
{ {
std::ostringstream e; this->Makefile->IssueMessage(
e << "Cannot specify link directories for target \"" << name MessageType::FATAL_ERROR,
<< "\" which is not built by this project."; cmStrCat("Cannot specify link directories for target \"", name,
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); "\" which is not built by this project."));
} }
std::string cmTargetLinkDirectoriesCommand::Join( std::string cmTargetLinkDirectoriesCommand::Join(
+39 -35
View File
@@ -256,10 +256,11 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
// Make sure the last argument was not a library type specifier. // Make sure the last argument was not a library type specifier.
if (haveLLT) { if (haveLLT) {
std::ostringstream e; this->Makefile->IssueMessage(
e << "The \"" << cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[llt] MessageType::FATAL_ERROR,
<< "\" argument must be followed by a library."; cmStrCat("The \"",
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[llt],
"\" argument must be followed by a library."));
cmSystemTools::SetFatalErrorOccured(); cmSystemTools::SetFatalErrorOccured();
} }
@@ -284,14 +285,14 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
void cmTargetLinkLibrariesCommand::LinkLibraryTypeSpecifierWarning(int left, void cmTargetLinkLibrariesCommand::LinkLibraryTypeSpecifierWarning(int left,
int right) int right)
{ {
std::ostringstream w; this->Makefile->IssueMessage(
w << "Link library type specifier \"" MessageType::AUTHOR_WARNING,
<< cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[left] cmStrCat(
<< "\" is followed by specifier \"" "Link library type specifier \"",
<< cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[right] cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[left],
<< "\" instead of a library name. " "\" is followed by specifier \"",
<< "The first specifier will be ignored."; cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[right],
this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); "\" instead of a library name. The first specifier will be ignored."));
} }
bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib, bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
@@ -404,12 +405,13 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
this->CurrentProcessingState != ProcessingPlainLinkInterface) { this->CurrentProcessingState != ProcessingPlainLinkInterface) {
if (rejectRemoteLinking) { if (rejectRemoteLinking) {
std::ostringstream e; this->Makefile->IssueMessage(
e << "Attempt to add link library \"" << lib << "\" to target \"" MessageType::FATAL_ERROR,
<< this->Target->GetName() cmStrCat("Attempt to add link library \"", lib, "\" to target \"",
<< "\" which is not built in this directory.\n" this->Target->GetName(),
<< "This is allowed only when policy CMP0079 is set to NEW."; "\" which is not built in this "
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); "directory.\nThis is allowed only when policy CMP0079 "
"is set to NEW."));
return false; return false;
} }
@@ -421,29 +423,31 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
(tgt->GetType() != cmStateEnums::OBJECT_LIBRARY) && (tgt->GetType() != cmStateEnums::OBJECT_LIBRARY) &&
(tgt->GetType() != cmStateEnums::INTERFACE_LIBRARY) && (tgt->GetType() != cmStateEnums::INTERFACE_LIBRARY) &&
!tgt->IsExecutableWithExports()) { !tgt->IsExecutableWithExports()) {
std::ostringstream e; this->Makefile->IssueMessage(
e << "Target \"" << lib << "\" of type " MessageType::FATAL_ERROR,
<< cmState::GetTargetTypeName(tgt->GetType()) cmStrCat(
<< " may not be linked into another target. One may link only to " "Target \"", lib, "\" of type ",
"INTERFACE, OBJECT, STATIC or SHARED libraries, or to executables " cmState::GetTargetTypeName(tgt->GetType()),
"with the ENABLE_EXPORTS property set."; " may not be linked into another target. One may link only to "
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); "INTERFACE, OBJECT, STATIC or SHARED libraries, or to ",
"executables with the ENABLE_EXPORTS property set."));
} }
this->Target->AddLinkLibrary(*this->Makefile, lib, libRef, llt); this->Target->AddLinkLibrary(*this->Makefile, lib, libRef, llt);
} }
if (warnRemoteInterface) { if (warnRemoteInterface) {
std::ostringstream w; this->Makefile->IssueMessage(
/* clang-format off */ MessageType::AUTHOR_WARNING,
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0079) << "\n" cmStrCat(
"Target\n " << this->Target->GetName() << "\nis not created in this " cmPolicies::GetPolicyWarning(cmPolicies::CMP0079), "\nTarget\n ",
"directory. For compatibility with older versions of CMake, link " this->Target->GetName(),
"library\n " << lib << "\nwill be looked up in the directory in " "\nis not created in this "
"which the target was created rather than in this calling " "directory. For compatibility with older versions of CMake, link "
"directory."; "library\n ",
/* clang-format on */ lib,
this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str()); "\nwill be looked up in the directory in which "
"the target was created rather than in this calling directory."));
} }
// Handle (additional) case where the command was called with PRIVATE / // Handle (additional) case where the command was called with PRIVATE /
+4 -6
View File
@@ -2,8 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmTargetLinkOptionsCommand.h" #include "cmTargetLinkOptionsCommand.h"
#include <sstream>
#include "cmListFileCache.h" #include "cmListFileCache.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmMessageType.h" #include "cmMessageType.h"
@@ -20,10 +18,10 @@ bool cmTargetLinkOptionsCommand::InitialPass(
void cmTargetLinkOptionsCommand::HandleMissingTarget(const std::string& name) void cmTargetLinkOptionsCommand::HandleMissingTarget(const std::string& name)
{ {
std::ostringstream e; this->Makefile->IssueMessage(
e << "Cannot specify link options for target \"" << name MessageType::FATAL_ERROR,
<< "\" which is not built by this project."; cmStrCat("Cannot specify link options for target \"", name,
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); "\" which is not built by this project."));
} }
std::string cmTargetLinkOptionsCommand::Join( std::string cmTargetLinkOptionsCommand::Join(
+4 -5
View File
@@ -30,11 +30,10 @@ void cmTargetSourcesCommand::HandleInterfaceContent(
void cmTargetSourcesCommand::HandleMissingTarget(const std::string& name) void cmTargetSourcesCommand::HandleMissingTarget(const std::string& name)
{ {
std::ostringstream e; this->Makefile->IssueMessage(
e << "Cannot specify sources for target \"" << name MessageType::FATAL_ERROR,
<< "\" " cmStrCat("Cannot specify sources for target \"", name,
"which is not built by this project."; "\" which is not built by this project."));
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
} }
std::string cmTargetSourcesCommand::Join( std::string cmTargetSourcesCommand::Join(
+10 -14
View File
@@ -3,13 +3,13 @@
#include "cmVariableWatchCommand.h" #include "cmVariableWatchCommand.h"
#include <memory> #include <memory>
#include <sstream>
#include <utility> #include <utility>
#include "cmExecutionStatus.h" #include "cmExecutionStatus.h"
#include "cmListFileCache.h" #include "cmListFileCache.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmMessageType.h" #include "cmMessageType.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include "cmVariableWatch.h" #include "cmVariableWatch.h"
#include "cmake.h" #include "cmake.h"
@@ -58,22 +58,20 @@ static void cmVariableWatchCommandVariableAccessed(const std::string& variable,
newLFF.Line = 9999; newLFF.Line = 9999;
cmExecutionStatus status(*makefile); cmExecutionStatus status(*makefile);
if (!makefile->ExecuteCommand(newLFF, status)) { if (!makefile->ExecuteCommand(newLFF, status)) {
std::ostringstream error; cmSystemTools::Error(
error << "Error in cmake code at\nUnknown:0:\n" cmStrCat("Error in cmake code at\nUnknown:0:\nA command failed "
<< "A command failed during the invocation of callback \"" "during the invocation of callback \"",
<< data->Command << "\"."; data->Command, "\"."));
cmSystemTools::Error(error.str());
data->InCallback = false; data->InCallback = false;
return; return;
} }
processed = true; processed = true;
} }
if (!processed) { if (!processed) {
std::ostringstream msg; makefile->IssueMessage(
msg << "Variable \"" << variable << "\" was accessed using " MessageType::LOG,
<< accessString << " with value \"" << (newValue ? newValue : "") cmStrCat("Variable \"", variable, "\" was accessed using ", accessString,
<< "\"."; " with value \"", (newValue ? newValue : ""), "\"."));
makefile->IssueMessage(MessageType::LOG, msg.str());
} }
data->InCallback = false; data->InCallback = false;
@@ -134,9 +132,7 @@ bool cmVariableWatchCommand(std::vector<std::string> const& args,
command = args[1]; command = args[1];
} }
if (variable == "CMAKE_CURRENT_LIST_FILE") { if (variable == "CMAKE_CURRENT_LIST_FILE") {
std::ostringstream ostr; status.SetError(cmStrCat("cannot be set on the variable: ", variable));
ostr << "cannot be set on the variable: " << variable;
status.SetError(ostr.str());
return false; return false;
} }