From 5e8fa0b7bcdd8f4f1af2a61335df9a1c952dbbdf Mon Sep 17 00:00:00 2001 From: Vitaly Stakhovsky Date: Tue, 11 May 2021 11:20:00 -0400 Subject: Source: Minor code improvements --- Source/CTest/cmCTestBuildHandler.cxx | 5 ++--- Source/cmCMakePathCommand.cxx | 5 +++-- Source/cmCPluginAPI.cxx | 2 +- Source/cmDepends.cxx | 3 +-- Source/cmGlobalGenerator.cxx | 2 +- Source/cmGlobalNMakeMakefileGenerator.cxx | 4 +--- Source/cmLocalGenerator.cxx | 2 +- Source/cmMakefile.cxx | 6 +++--- Source/cmVisualStudio10TargetGenerator.cxx | 2 +- 9 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index 103dc1e..03caa63 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -3,7 +3,6 @@ #include "cmCTestBuildHandler.h" #include -#include #include #include @@ -657,14 +656,14 @@ bool cmCTestBuildHandler::IsLaunchedErrorFile(const char* fname) { // error-{hash}.xml return (cmHasLiteralPrefix(fname, "error-") && - strcmp(fname + strlen(fname) - 4, ".xml") == 0); + cmHasLiteralSuffix(fname, ".xml")); } bool cmCTestBuildHandler::IsLaunchedWarningFile(const char* fname) { // warning-{hash}.xml return (cmHasLiteralPrefix(fname, "warning-") && - strcmp(fname + strlen(fname) - 4, ".xml") == 0); + cmHasLiteralSuffix(fname, ".xml")); } //###################################################################### diff --git a/Source/cmCMakePathCommand.cxx b/Source/cmCMakePathCommand.cxx index 962fdcc..9a5fa7b 100644 --- a/Source/cmCMakePathCommand.cxx +++ b/Source/cmCMakePathCommand.cxx @@ -18,6 +18,7 @@ #include "cmCMakePath.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" +#include "cmProperty.h" #include "cmRange.h" #include "cmStringAlgorithms.h" #include "cmSubcommandTable.h" @@ -149,8 +150,8 @@ public: bool getInputPath(const std::string& arg, cmExecutionStatus& status, std::string& path) { - const auto* def = status.GetMakefile().GetDefinition(arg); - if (def == nullptr) { + cmProp def = status.GetMakefile().GetDefinition(arg); + if (!def) { status.SetError("undefined variable for input path."); return false; } diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 438a077..ace7382 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -734,7 +734,7 @@ void CCONV cmSourceFileSetName2(void* arg, const char* name, const char* dir, } sf->SourceName = name; std::string fname = sf->SourceName; - if (ext && strlen(ext)) { + if (cmNonempty(ext)) { fname += "."; fname += ext; } diff --git a/Source/cmDepends.cxx b/Source/cmDepends.cxx index 566c3bf..46c7e3e 100644 --- a/Source/cmDepends.cxx +++ b/Source/cmDepends.cxx @@ -229,11 +229,10 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends, void cmDepends::SetIncludePathFromLanguage(const std::string& lang) { // Look for the new per "TARGET_" variant first: - cmProp includePath = nullptr; std::string includePathVar = cmStrCat("CMAKE_", lang, "_TARGET_INCLUDE_PATH"); cmMakefile* mf = this->LocalGenerator->GetMakefile(); - includePath = mf->GetDefinition(includePathVar); + cmProp includePath = mf->GetDefinition(includePathVar); if (includePath) { cmExpandList(*includePath, this->IncludePath); } else { diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 55fba79..1357974 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2260,7 +2260,7 @@ bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root, // Check whether the genex expansion of the property agrees in all // configurations. - if (trueCount && falseCount) { + if (trueCount > 0 && falseCount > 0) { std::ostringstream e; e << "The EXCLUDE_FROM_ALL property of target \"" << target->GetName() << "\" varies by configuration. This is not supported by the \"" diff --git a/Source/cmGlobalNMakeMakefileGenerator.cxx b/Source/cmGlobalNMakeMakefileGenerator.cxx index 313f39b..f08b1da 100644 --- a/Source/cmGlobalNMakeMakefileGenerator.cxx +++ b/Source/cmGlobalNMakeMakefileGenerator.cxx @@ -43,9 +43,7 @@ bool cmGlobalNMakeMakefileGenerator::FindMakeProgram(cmMakefile* mf) return false; } if (cmProp nmakeCommand = mf->GetDefinition("CMAKE_MAKE_PROGRAM")) { - std::vector command; - command.emplace_back(*nmakeCommand); - command.emplace_back("-?"); + std::vector command{ *nmakeCommand, "-?" }; std::string out; std::string err; if (!cmSystemTools::RunSingleCommand(command, &out, &err, nullptr, nullptr, diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index db7357a..fbbdfca 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2786,7 +2786,7 @@ void cmLocalGenerator::IncludeFileInUnitySources( cmGeneratedFileStream& unity_file, std::string const& sf_full_path, cmProp beforeInclude, cmProp afterInclude, cmProp uniqueIdName) const { - if (uniqueIdName && !uniqueIdName->empty()) { + if (cmNonempty(uniqueIdName)) { std::string pathToHash; auto PathEqOrSubDir = [](std::string const& a, std::string const& b) { return (cmSystemTools::ComparePath(a, b) || diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5a37bb9..29f9e36 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2479,7 +2479,7 @@ const std::string& cmMakefile::GetRequiredDefinition( const std::string& name) const { static std::string const empty; - const std::string* def = this->GetDefinition(name); + cmProp def = this->GetDefinition(name); if (!def) { cmSystemTools::Error("Error required internal CMake variable not " "set, cmake may not be built correctly.\n" @@ -2553,7 +2553,7 @@ cmProp cmMakefile::GetDefinition(const std::string& name) const const std::string& cmMakefile::GetSafeDefinition(const std::string& name) const { static std::string const empty; - const std::string* def = this->GetDefinition(name); + cmProp def = this->GetDefinition(name); if (!def) { return empty; } @@ -3067,7 +3067,7 @@ MessageType cmMakefile::ExpandVariablesInStringNew( if (filename && variable == lineVar) { varresult = std::to_string(line); } else { - const std::string* def = this->GetDefinition(variable); + cmProp def = this->GetDefinition(variable); if (def) { varresult = *def; } else if (!this->SuppressSideEffects) { diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index ba0cf9c..12a3679 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -498,7 +498,7 @@ void cmVisualStudio10TargetGenerator::Generate() cmProp targetFramework = this->GeneratorTarget->GetProperty("DOTNET_TARGET_FRAMEWORK"); if (targetFramework) { - if (std::strchr(targetFramework->c_str(), ';') != nullptr) { + if (targetFramework->find(';') != std::string::npos) { e1.Element("TargetFrameworks", *targetFramework); } else { e1.Element("TargetFramework", *targetFramework); -- cgit v0.12