summaryrefslogtreecommitdiffstats
path: root/Source/cmFindProgramRule.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmFindProgramRule.cxx')
-rw-r--r--Source/cmFindProgramRule.cxx65
1 files changed, 65 insertions, 0 deletions
diff --git a/Source/cmFindProgramRule.cxx b/Source/cmFindProgramRule.cxx
new file mode 100644
index 0000000..432151f
--- /dev/null
+++ b/Source/cmFindProgramRule.cxx
@@ -0,0 +1,65 @@
+#include "cmFindProgramRule.h"
+#include <stdlib.h>
+#include <stdio.h>
+
+static void GetPath(std::vector<std::string>& path)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ char* pathSep = ";";
+#else
+ char* pathSep = ":";
+#endif
+ std::string pathEnv = getenv("PATH");
+ std::string::size_type start =0;
+ bool done = false;
+ while(!done)
+ {
+ std::string::size_type endpos = pathEnv.find(pathSep, start);
+ if(endpos != std::string::npos)
+ {
+ path.push_back(pathEnv.substr(start, endpos-start));
+ start = endpos+1;
+ }
+ else
+ {
+ done = true;
+ }
+ }
+}
+
+
+
+// cmFindProgramRule
+bool cmFindProgramRule::Invoke(std::vector<std::string>& args)
+{
+ if(args.size() < 2 )
+ {
+ this->SetError("called with incorrect number of arguments");
+ return false;
+ }
+
+ std::vector<std::string> path;
+ GetPath(path);
+ std::vector<std::string>::iterator i = args.begin();
+ const char* define = (*i).c_str();
+ i++;
+ for(; i != args.end(); ++i)
+ {
+ for(int k=0; k < path.size(); k++)
+ {
+ std::string tryPath = path[k];
+ tryPath += "/";
+ tryPath += *i;
+#ifdef _WIN32
+ tryPath += ".exe";
+#endif
+ if(cmSystemTools::FileExists(tryPath.c_str()))
+ {
+ m_Makefile->AddDefinition(define, tryPath.c_str());
+ return true;
+ }
+ }
+ }
+ return false;
+}
+