diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2023-07-24 17:53:46 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2023-07-24 19:20:53 (GMT) |
commit | c4bb7fd4f3957c06ba373352421d87b6c7d53e52 (patch) | |
tree | f20ae7eaf900f7611da5514293f284202e9c95d3 /Source/cmPolicies.cxx | |
parent | 59eda7fa0abf2a39980ee35f35a5e6ffac31891b (diff) | |
download | CMake-c4bb7fd4f3957c06ba373352421d87b6c7d53e52.zip CMake-c4bb7fd4f3957c06ba373352421d87b6c7d53e52.tar.gz CMake-c4bb7fd4f3957c06ba373352421d87b6c7d53e52.tar.bz2 |
cmPolicies: use `cmStrCat` for error message building
Diffstat (limited to 'Source/cmPolicies.cxx')
-rw-r--r-- | Source/cmPolicies.cxx | 152 |
1 files changed, 68 insertions, 84 deletions
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index c2d5f6d..d89c8c8 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -148,10 +148,10 @@ static bool GetPolicyDefault(cmMakefile* mf, std::string const& policy, } else if (defaultValue.empty()) { *defaultSetting = cmPolicies::WARN; } else { - std::ostringstream e; - e << defaultVar << " has value \"" << defaultValue - << R"(" but must be "OLD", "NEW", or "" (empty).)"; - mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); + mf->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat(defaultVar, " has value \"", defaultValue, + R"(" but must be "OLD", "NEW", or "" (empty).)")); return false; } @@ -170,11 +170,11 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf, unsigned int minTweak = 0; if (sscanf(version_min.c_str(), "%u.%u.%u.%u", &minMajor, &minMinor, &minPatch, &minTweak) < 2) { - std::ostringstream e; - e << "Invalid policy version value \"" << version_min - << "\". " - "A numeric major.minor[.patch[.tweak]] must be given."; - mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); + mf->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Invalid policy version value \"", version_min, + "\". " + "A numeric major.minor[.patch[.tweak]] must be given.")); return false; } @@ -200,14 +200,14 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf, minMinor == cmVersion::GetMinorVersion() && minPatch == cmVersion::GetPatchVersion() && minTweak > cmVersion::GetTweakVersion())) { - std::ostringstream e; - e << "An attempt was made to set the policy version of CMake to \"" - << version_min - << "\" which is greater than this version of CMake. " - "This is not allowed because the greater version may have new " - "policies not known to this CMake. " - "You may need a newer CMake version to build this project."; - mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); + mf->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("An attempt was made to set the policy version of CMake to \"", + version_min, + "\" which is greater than this version of CMake. ", + "This is not allowed because the greater version may have new " + "policies not known to this CMake. " + "You may need a newer CMake version to build this project.")); return false; } @@ -223,11 +223,11 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf, unsigned int maxTweak = 0; if (sscanf(version_max.c_str(), "%u.%u.%u.%u", &maxMajor, &maxMinor, &maxPatch, &maxTweak) < 2) { - std::ostringstream e; - e << "Invalid policy max version value \"" << version_max - << "\". " - "A numeric major.minor[.patch[.tweak]] must be given."; - mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); + mf->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Invalid policy max version value \"", version_max, + "\". " + "A numeric major.minor[.patch[.tweak]] must be given.")); return false; } @@ -237,11 +237,10 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf, minPatch > maxPatch) || (minMajor == maxMajor && minMinor == maxMinor && minPatch == maxPatch && minTweak > maxTweak)) { - std::ostringstream e; - e << "Policy VERSION range \"" << version_min << "..." << version_max - << "\"" - " specifies a larger minimum than maximum."; - mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); + mf->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Policy VERSION range \"", version_min, "...", version_max, + "\" specifies a larger minimum than maximum.")); return false; } @@ -331,61 +330,49 @@ bool cmPolicies::GetPolicyID(const char* id, cmPolicies::PolicyID& pid) //! return a warning string for a given policy std::string cmPolicies::GetPolicyWarning(cmPolicies::PolicyID id) { - std::ostringstream msg; - msg << "Policy " << idToString(id) - << " is not set: " - "" - << idToShortDescription(id) - << " " - "Run \"cmake --help-policy " - << idToString(id) - << "\" for " - "policy details. " - "Use the cmake_policy command to set the policy " - "and suppress this warning."; - return msg.str(); + return cmStrCat("Policy ", idToString(id), + " is not set: ", idToShortDescription(id), + " " + "Run \"cmake --help-policy ", + idToString(id), + "\" for " + "policy details. " + "Use the cmake_policy command to set the policy " + "and suppress this warning."); } std::string cmPolicies::GetPolicyDeprecatedWarning(cmPolicies::PolicyID id) { - std::ostringstream msg; - /* clang-format off */ - msg << - "The OLD behavior for policy " << idToString(id) << " " + return cmStrCat( + "The OLD behavior for policy ", idToString(id), + " " "will be removed from a future version of CMake.\n" "The cmake-policies(7) manual explains that the OLD behaviors of all " "policies are deprecated and that a policy should be set to OLD only " "under specific short-term circumstances. Projects should be ported " - "to the NEW behavior and not rely on setting a policy to OLD." - ; - /* clang-format on */ - return msg.str(); + "to the NEW behavior and not rely on setting a policy to OLD."); } //! return an error string for when a required policy is unspecified std::string cmPolicies::GetRequiredPolicyError(cmPolicies::PolicyID id) { - std::ostringstream error; - error << "Policy " << idToString(id) - << " is not set to NEW: " - "" - << idToShortDescription(id) - << " " - "Run \"cmake --help-policy " - << idToString(id) - << "\" for " - "policy details. " - "CMake now requires this policy to be set to NEW by the project. " - "The policy may be set explicitly using the code\n" - " cmake_policy(SET " - << idToString(id) - << " NEW)\n" - "or by upgrading all policies with the code\n" - " cmake_policy(VERSION " - << idToVersion(id) - << ") # or later\n" - "Run \"cmake --help-command cmake_policy\" for more information."; - return error.str(); + return cmStrCat( + "Policy ", idToString(id), + " is not set to NEW: ", idToShortDescription(id), + " " + "Run \"cmake --help-policy ", + idToString(id), + "\" for policy details. " + "CMake now requires this policy to be set to NEW by the project. " + "The policy may be set explicitly using the code\n" + " cmake_policy(SET ", + idToString(id), + " NEW)\n" + "or by upgrading all policies with the code\n" + " cmake_policy(VERSION ", + idToVersion(id), + ") # or later\n" + "Run \"cmake --help-command cmake_policy\" for more information."); } //! Get the default status for a policy @@ -398,21 +385,18 @@ cmPolicies::PolicyStatus cmPolicies::GetPolicyStatus( std::string cmPolicies::GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id) { std::string pid = idToString(id); - std::ostringstream e; - e << "Policy " << pid - << " may not be set to OLD behavior because this " - "version of CMake no longer supports it. " - "The policy was introduced in " - "CMake version " - << idToVersion(id) - << ", and use of NEW behavior is now required." - "\n" - "Please either update your CMakeLists.txt files to conform to " - "the new behavior or use an older version of CMake that still " - "supports the old behavior. " - "Run cmake --help-policy " - << pid << " for more information."; - return e.str(); + return cmStrCat( + "Policy ", pid, + " may not be set to OLD behavior because this " + "version of CMake no longer supports it. " + "The policy was introduced in CMake version ", + idToVersion(id), + ", and use of NEW behavior is now required." + "\n" + "Please either update your CMakeLists.txt files to conform to " + "the new behavior or use an older version of CMake that still " + "supports the old behavior. Run cmake --help-policy ", + pid, " for more information."); } cmPolicies::PolicyStatus cmPolicies::PolicyMap::Get( |