summaryrefslogtreecommitdiff
path: root/Source/cmFindProgramCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-09-01 16:25:57 -0400
committerBrad King <brad.king@kitware.com>2015-09-02 10:17:22 -0400
commit8ea7611bc3650c75c86d22a3127cb117dbcaa9be (patch)
treee04eb16f45d1b9fc463ae82c4b0184ea04fabca1 /Source/cmFindProgramCommand.cxx
parentfc1990c93384d1d2122cd4e11398a8197b006504 (diff)
downloadcmake-8ea7611bc3650c75c86d22a3127cb117dbcaa9be.tar.gz
find_program: Optionally consider all names in each directory
When more than one value is given to the NAMES option this command by default will consider one name at a time and search every directory for it. Add a NAMES_PER_DIR option to tell this command to consider one directory at a time and search for all names in it.
Diffstat (limited to 'Source/cmFindProgramCommand.cxx')
-rw-r--r--Source/cmFindProgramCommand.cxx41
1 files changed, 41 insertions, 0 deletions
diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx
index c9bc56ded8..e64ed87f22 100644
--- a/Source/cmFindProgramCommand.cxx
+++ b/Source/cmFindProgramCommand.cxx
@@ -85,6 +85,11 @@ struct cmFindProgramHelper
}
};
+cmFindProgramCommand::cmFindProgramCommand()
+{
+ this->NamesPerDirAllowed = true;
+}
+
// cmFindProgramCommand
bool cmFindProgramCommand
::InitialPass(std::vector<std::string> const& argsIn, cmExecutionStatus &)
@@ -151,6 +156,42 @@ std::string cmFindProgramCommand::FindProgram()
//----------------------------------------------------------------------------
std::string cmFindProgramCommand::FindNormalProgram()
{
+ if(this->NamesPerDir)
+ {
+ return this->FindNormalProgramNamesPerDir();
+ }
+ else
+ {
+ return this->FindNormalProgramDirsPerName();
+ }
+}
+
+//----------------------------------------------------------------------------
+std::string cmFindProgramCommand::FindNormalProgramNamesPerDir()
+{
+ // Search for all names in each directory.
+ cmFindProgramHelper helper;
+ for (std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end() ; ++ni)
+ {
+ helper.AddName(*ni);
+ }
+ // Search every directory.
+ for (std::vector<std::string>::const_iterator
+ p = this->SearchPaths.begin(); p != this->SearchPaths.end(); ++p)
+ {
+ if(helper.CheckDirectory(*p))
+ {
+ return helper.BestPath;
+ }
+ }
+ // Couldn't find the program.
+ return "";
+}
+
+//----------------------------------------------------------------------------
+std::string cmFindProgramCommand::FindNormalProgramDirsPerName()
+{
// Search the entire path for each name.
cmFindProgramHelper helper;
for (std::vector<std::string>::const_iterator ni = this->Names.begin();