From 7e154ebd59724d43bf29a8e1c648d6cf7f0e61e4 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Fri, 17 Sep 2021 11:56:48 +0200 Subject: cmSystemTools::VersionCompare: use std::string for arguments --- Source/CPack/IFW/cmCPackIFWCommon.cxx | 8 ++--- Source/cmConditionEvaluator.cxx | 7 ++-- Source/cmGeneratorExpressionNode.cxx | 6 ++-- Source/cmGlobalNMakeMakefileGenerator.cxx | 2 +- Source/cmGlobalNinjaGenerator.cxx | 59 +++++++++++++++---------------- Source/cmLocalGenerator.cxx | 12 +++---- Source/cmMakefile.cxx | 3 +- Source/cmSystemTools.cxx | 28 ++++++++++----- Source/cmSystemTools.h | 5 ++- 9 files changed, 69 insertions(+), 61 deletions(-) diff --git a/Source/CPack/IFW/cmCPackIFWCommon.cxx b/Source/CPack/IFW/cmCPackIFWCommon.cxx index 177a959..c7ab994 100644 --- a/Source/CPack/IFW/cmCPackIFWCommon.cxx +++ b/Source/CPack/IFW/cmCPackIFWCommon.cxx @@ -51,7 +51,7 @@ bool cmCPackIFWCommon::IsVersionLess(const char* version) const } return cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, this->Generator->FrameworkVersion.data(), version); + cmSystemTools::OP_LESS, this->Generator->FrameworkVersion, version); } bool cmCPackIFWCommon::IsVersionGreater(const char* version) const @@ -61,8 +61,7 @@ bool cmCPackIFWCommon::IsVersionGreater(const char* version) const } return cmSystemTools::VersionCompare( - cmSystemTools::OP_GREATER, this->Generator->FrameworkVersion.data(), - version); + cmSystemTools::OP_GREATER, this->Generator->FrameworkVersion, version); } bool cmCPackIFWCommon::IsVersionEqual(const char* version) const @@ -72,8 +71,7 @@ bool cmCPackIFWCommon::IsVersionEqual(const char* version) const } return cmSystemTools::VersionCompare( - cmSystemTools::OP_EQUAL, this->Generator->FrameworkVersion.data(), - version); + cmSystemTools::OP_EQUAL, this->Generator->FrameworkVersion, version); } void cmCPackIFWCommon::ExpandListArgument( diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx index 68bc4d8..1d7696d 100644 --- a/Source/cmConditionEvaluator.cxx +++ b/Source/cmConditionEvaluator.cxx @@ -729,10 +729,9 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, keyVERSION_LESS_EQUAL, keyVERSION_GREATER, keyVERSION_GREATER_EQUAL, keyVERSION_EQUAL))) { const auto op = MATCH2CMPOP[matchNo - 1]; - const cmProp lhs = this->GetVariableOrString(*args.current); - const cmProp rhs = this->GetVariableOrString(*args.nextnext); - const auto result = - cmSystemTools::VersionCompare(op, lhs->c_str(), rhs->c_str()); + const std::string& lhs = this->GetVariableOrString(*args.current); + const std::string& rhs = this->GetVariableOrString(*args.nextnext); + const auto result = cmSystemTools::VersionCompare(op, lhs, rhs); newArgs.ReduceTwoArgs(result, args); } diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 3e90ead..4e06a07 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -771,8 +771,7 @@ struct CompilerVersionNode : public cmGeneratorExpressionNode } return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL, - parameters.front().c_str(), - compilerVersion.c_str()) + parameters.front(), compilerVersion) ? "1" : "0"; } @@ -830,8 +829,7 @@ struct VersionNode : public cmGeneratorExpressionNode const GeneratorExpressionContent* /*content*/, cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override { - return cmSystemTools::VersionCompare(Op, parameters.front().c_str(), - parameters[1].c_str()) + return cmSystemTools::VersionCompare(Op, parameters.front(), parameters[1]) ? "1" : "0"; } diff --git a/Source/cmGlobalNMakeMakefileGenerator.cxx b/Source/cmGlobalNMakeMakefileGenerator.cxx index f08b1da..5ca8d52 100644 --- a/Source/cmGlobalNMakeMakefileGenerator.cxx +++ b/Source/cmGlobalNMakeMakefileGenerator.cxx @@ -70,7 +70,7 @@ bool cmGlobalNMakeMakefileGenerator::FindMakeProgram(cmMakefile* mf) void cmGlobalNMakeMakefileGenerator::CheckNMakeFeatures() { this->NMakeSupportsUTF8 = !cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, this->NMakeVersion.c_str(), "9"); + cmSystemTools::OP_LESS, this->NMakeVersion, "9"); } void cmGlobalNMakeMakefileGenerator::GetDocumentation( diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index c6f82f9..6279d68 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -558,9 +558,8 @@ void cmGlobalNinjaGenerator::GetDocumentation(cmDocumentationEntry& entry) void cmGlobalNinjaGenerator::Generate() { // Check minimum Ninja version. - if (cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, - this->NinjaVersion.c_str(), - RequiredNinjaVersion().c_str())) { + if (cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, this->NinjaVersion, + RequiredNinjaVersion())) { std::ostringstream msg; msg << "The detected version of Ninja (" << this->NinjaVersion; msg << ") is less than the version of Ninja required by CMake ("; @@ -721,21 +720,21 @@ bool cmGlobalNinjaGenerator::FindMakeProgram(cmMakefile* mf) void cmGlobalNinjaGenerator::CheckNinjaFeatures() { - this->NinjaSupportsConsolePool = !cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), - RequiredNinjaVersionForConsolePool().c_str()); + this->NinjaSupportsConsolePool = + !cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, this->NinjaVersion, + RequiredNinjaVersionForConsolePool()); this->NinjaSupportsImplicitOuts = !cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), - cmGlobalNinjaGenerator::RequiredNinjaVersionForImplicitOuts().c_str()); - this->NinjaSupportsManifestRestat = !cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), - RequiredNinjaVersionForManifestRestat().c_str()); - this->NinjaSupportsMultilineDepfile = !cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), - RequiredNinjaVersionForMultilineDepfile().c_str()); - this->NinjaSupportsDyndeps = !cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), - RequiredNinjaVersionForDyndeps().c_str()); + cmSystemTools::OP_LESS, this->NinjaVersion, + cmGlobalNinjaGenerator::RequiredNinjaVersionForImplicitOuts()); + this->NinjaSupportsManifestRestat = + !cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, this->NinjaVersion, + RequiredNinjaVersionForManifestRestat()); + this->NinjaSupportsMultilineDepfile = + !cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, this->NinjaVersion, + RequiredNinjaVersionForMultilineDepfile()); + this->NinjaSupportsDyndeps = + !cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, this->NinjaVersion, + RequiredNinjaVersionForDyndeps()); if (!this->NinjaSupportsDyndeps) { // The ninja version number is not new enough to have upstream support. // Our ninja branch adds ".dyndep-#" to its version number, @@ -753,21 +752,21 @@ void cmGlobalNinjaGenerator::CheckNinjaFeatures() } this->NinjaSupportsUnconditionalRecompactTool = !cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), - RequiredNinjaVersionForUnconditionalRecompactTool().c_str()); - this->NinjaSupportsRestatTool = !cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), - RequiredNinjaVersionForRestatTool().c_str()); - this->NinjaSupportsMultipleOutputs = !cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), - RequiredNinjaVersionForMultipleOutputs().c_str()); + cmSystemTools::OP_LESS, this->NinjaVersion, + RequiredNinjaVersionForUnconditionalRecompactTool()); + this->NinjaSupportsRestatTool = + !cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, this->NinjaVersion, + RequiredNinjaVersionForRestatTool()); + this->NinjaSupportsMultipleOutputs = + !cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, this->NinjaVersion, + RequiredNinjaVersionForMultipleOutputs()); this->NinjaSupportsMetadataOnRegeneration = !cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), - RequiredNinjaVersionForMetadataOnRegeneration().c_str()); + cmSystemTools::OP_LESS, this->NinjaVersion, + RequiredNinjaVersionForMetadataOnRegeneration()); #ifdef _WIN32 - this->NinjaSupportsCodePage = !cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), - RequiredNinjaVersionForCodePage().c_str()); + this->NinjaSupportsCodePage = + !cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, this->NinjaVersion, + RequiredNinjaVersionForCodePage()); if (this->NinjaSupportsCodePage) { this->CheckNinjaCodePage(); } else { diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 5042874..4c3e8ec 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1961,10 +1961,10 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags, cmStrCat("CMAKE_", lang, "_SIMULATE_ID")); if (lang == "Swift") { if (cmProp v = target->GetProperty("Swift_LANGUAGE_VERSION")) { - if (cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL, - cmToCStr(this->Makefile->GetDefinition( - "CMAKE_Swift_COMPILER_VERSION")), - "4.2")) { + if (cmSystemTools::VersionCompare( + cmSystemTools::OP_GREATER_EQUAL, + this->Makefile->GetDefinition("CMAKE_Swift_COMPILER_VERSION"), + "4.2")) { this->AppendFlags(flags, "-swift-version " + *v); } } @@ -2622,8 +2622,8 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target) // MSVC 2008 is producing both .pdb and .idb files with /Zi. bool msvc2008OrLess = - cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, compilerVersion.c_str(), "16.0") && + cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, + compilerVersion, "16.0") && compilerId == "MSVC"; // but not when used via toolset -Tv90 if (this->Makefile->GetSafeDefinition( diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index ef31d76..f9b2562 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -926,8 +926,7 @@ void cmMakefile::Generate(cmLocalGenerator& lg) this->DoGenerate(lg); cmProp oldValue = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"); if (oldValue && - cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, oldValue->c_str(), - "2.4")) { + cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, oldValue, "2.4")) { this->GetCMakeInstance()->IssueMessage( MessageType::FATAL_ERROR, "You have set CMAKE_BACKWARDS_COMPATIBILITY to a CMake version less " diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index a20e787..27cb90f 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -2885,8 +2885,9 @@ bool cmSystemTools::SetRPath(std::string const& file, return false; } -bool cmSystemTools::VersionCompare(cmSystemTools::CompareOp op, - const char* lhss, const char* rhss) +namespace { +bool VersionCompare(cmSystemTools::CompareOp op, const char* lhss, + const char* rhss) { const char* endl = lhss; const char* endr = rhss; @@ -2919,26 +2920,37 @@ bool cmSystemTools::VersionCompare(cmSystemTools::CompareOp op, // lhs == rhs, so true if operation is EQUAL return (op & cmSystemTools::OP_EQUAL) != 0; } +} + +bool cmSystemTools::VersionCompare(cmSystemTools::CompareOp op, + const std::string& lhs, + const std::string& rhs) +{ + return ::VersionCompare(op, lhs.c_str(), rhs.c_str()); +} +bool cmSystemTools::VersionCompare(cmSystemTools::CompareOp op, + const std::string& lhs, const char rhs[]) +{ + return ::VersionCompare(op, lhs.c_str(), rhs); +} bool cmSystemTools::VersionCompareEqual(std::string const& lhs, std::string const& rhs) { - return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL, lhs.c_str(), - rhs.c_str()); + return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL, lhs, rhs); } bool cmSystemTools::VersionCompareGreater(std::string const& lhs, std::string const& rhs) { - return cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER, lhs.c_str(), - rhs.c_str()); + return cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER, lhs, rhs); } bool cmSystemTools::VersionCompareGreaterEq(std::string const& lhs, std::string const& rhs) { - return cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL, - lhs.c_str(), rhs.c_str()); + return cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL, lhs, + rhs); } static size_t cm_strverscmp_find_first_difference_or_end(const char* lhs, diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index be817b1..715724c 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -284,7 +284,10 @@ public: /** * Compare versions */ - static bool VersionCompare(CompareOp op, const char* lhs, const char* rhs); + static bool VersionCompare(CompareOp op, const std::string& lhs, + const std::string& rhs); + static bool VersionCompare(CompareOp op, const std::string& lhs, + const char rhs[]); static bool VersionCompareEqual(std::string const& lhs, std::string const& rhs); static bool VersionCompareGreater(std::string const& lhs, -- cgit v0.12