diff options
Diffstat (limited to 'Source/cmFindProgramCommand.cxx')
| -rw-r--r-- | Source/cmFindProgramCommand.cxx | 73 |
1 files changed, 37 insertions, 36 deletions
diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index 77728ec..c22462e 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -2,6 +2,9 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmFindProgramCommand.h" +#include <algorithm> +#include <string> + #include "cmMakefile.h" #include "cmMessageType.h" #include "cmPolicies.h" @@ -60,44 +63,42 @@ struct cmFindProgramHelper } bool CheckCompoundNames() { - for (std::string const& n : this->Names) { - // Only perform search relative to current directory if the file name - // contains a directory separator. - if (n.find('/') != std::string::npos) { - if (this->CheckDirectoryForName("", n)) { - return true; - } - } - } - return false; + return std::any_of(this->Names.begin(), this->Names.end(), + [this](std::string const& n) -> bool { + // Only perform search relative to current directory + // if the file name contains a directory separator. + return n.find('/') != std::string::npos && + this->CheckDirectoryForName("", n); + }); } bool CheckDirectory(std::string const& path) { - for (std::string const& n : this->Names) { - if (this->CheckDirectoryForName(path, n)) { - return true; - } - } - return false; + return std::any_of(this->Names.begin(), this->Names.end(), + [this, &path](std::string const& n) -> bool { + // Only perform search relative to current directory + // if the file name contains a directory separator. + return this->CheckDirectoryForName(path, n); + }); } bool CheckDirectoryForName(std::string const& path, std::string const& name) { - for (std::string const& ext : this->Extensions) { - if (!ext.empty() && cmHasSuffix(name, ext)) { - continue; - } - this->TestNameExt = cmStrCat(name, ext); - this->TestPath = - cmSystemTools::CollapseFullPath(this->TestNameExt, path); - bool exists = this->FileIsExecutable(this->TestPath); - exists ? this->DebugSearches.FoundAt(this->TestPath) - : this->DebugSearches.FailedAt(this->TestPath); - if (exists) { - this->BestPath = this->TestPath; - return true; - } - } - return false; + return std::any_of(this->Extensions.begin(), this->Extensions.end(), + [this, &path, &name](std::string const& ext) -> bool { + if (!ext.empty() && cmHasSuffix(name, ext)) { + return false; + } + this->TestNameExt = cmStrCat(name, ext); + this->TestPath = cmSystemTools::CollapseFullPath( + this->TestNameExt, path); + bool exists = this->FileIsExecutable(this->TestPath); + exists ? this->DebugSearches.FoundAt(this->TestPath) + : this->DebugSearches.FailedAt(this->TestPath); + if (exists) { + this->BestPath = this->TestPath; + return true; + } + return false; + }); } bool FileIsExecutable(std::string const& file) const { @@ -152,7 +153,7 @@ cmFindProgramCommand::cmFindProgramCommand(cmExecutionStatus& status) // cmFindProgramCommand bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn) { - this->DebugMode = ComputeIfDebugModeWanted(); + this->DebugMode = this->ComputeIfDebugModeWanted(); this->VariableDocumentation = "Path to a program."; this->CMakePathName = "PROGRAM"; // call cmFindBase::ParseArguments @@ -171,7 +172,7 @@ bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn) return true; } - std::string const result = FindProgram(); + std::string const result = this->FindProgram(); if (!result.empty()) { // Save the value in the cache this->Makefile->AddCacheDefinition(this->VariableName, result, @@ -198,7 +199,7 @@ std::string cmFindProgramCommand::FindProgram() std::string program; if (this->SearchAppBundleFirst || this->SearchAppBundleOnly) { - program = FindAppBundle(); + program = this->FindAppBundle(); } if (program.empty() && !this->SearchAppBundleOnly) { program = this->FindNormalProgram(); @@ -274,7 +275,7 @@ std::string cmFindProgramCommand::FindAppBundle() cmSystemTools::FindDirectory(appName, this->SearchPaths, true); if (!appPath.empty()) { - std::string executable = GetBundleExecutable(appPath); + std::string executable = this->GetBundleExecutable(appPath); if (!executable.empty()) { return cmSystemTools::CollapseFullPath(executable); } |
