summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/SystemTools.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r--Source/kwsys/SystemTools.cxx60
1 files changed, 44 insertions, 16 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index e30cc51..abc3cd1 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -1923,21 +1923,35 @@ kwsys_stl::string SystemTools::FindProgram(
{
return "";
}
+ std::string ext = SystemTools::GetExecutableExtension();
+ if(ext.size())
+ {
+ unsigned int len = strlen(name);
+ if(len > ext.size())
+ {
+ if(strcmp(name+(len-ext.size()), ext.c_str()) == 0)
+ {
+ ext = ""; // name already has Executable extension
+ }
+ }
+ }
// See if the executable exists as written.
if(SystemTools::FileExists(name) &&
!SystemTools::FileIsDirectory(name))
{
return SystemTools::CollapseFullPath(name);
}
- kwsys_stl::string tryPath = name;
- tryPath += SystemTools::GetExecutableExtension();
- if(SystemTools::FileExists(tryPath.c_str()) &&
- !SystemTools::FileIsDirectory(tryPath.c_str()))
+ if(ext.size())
{
- return SystemTools::CollapseFullPath(tryPath.c_str());
+ kwsys_stl::string tryPath = name;
+ tryPath += ext;
+ if(SystemTools::FileExists(tryPath.c_str()) &&
+ !SystemTools::FileIsDirectory(tryPath.c_str()))
+ {
+ return SystemTools::CollapseFullPath(tryPath.c_str());
+ }
}
kwsys_stl::vector<kwsys_stl::string> path;
- SystemTools::GetPath(path, "CMAKE_PROGRAM_PATH");
// Add the system search path to our path.
if (!no_system_path)
{
@@ -1954,9 +1968,10 @@ kwsys_stl::string SystemTools::FindProgram(
p != path.end(); ++p)
{
#ifdef _WIN32
+ // Remove double quotes from the path on windows
SystemTools::ReplaceString(*p, "\"", "");
#endif
- tryPath = *p;
+ kwsys_stl::string tryPath = *p;
tryPath += "/";
tryPath += name;
if(SystemTools::FileExists(tryPath.c_str()) &&
@@ -1965,22 +1980,35 @@ kwsys_stl::string SystemTools::FindProgram(
return SystemTools::CollapseFullPath(tryPath.c_str());
}
#ifdef _WIN32
- tryPath += ".com";
- if(SystemTools::FileExists(tryPath.c_str()) &&
- !SystemTools::FileIsDirectory(tryPath.c_str()))
+ // on windows try .com before .exe
+ if(ext.size() == 0)
{
- return SystemTools::CollapseFullPath(tryPath.c_str());
+ SystemTools::ReplaceString(tryPath, ".exe", ".com");
+ SystemTools::ReplaceString(tryPath, ".EXE", ".com");
+ }
+ else
+ {
+ tryPath += ".com";
}
- tryPath = *p;
- tryPath += "/";
- tryPath += name;
-#endif
- tryPath += SystemTools::GetExecutableExtension();
if(SystemTools::FileExists(tryPath.c_str()) &&
!SystemTools::FileIsDirectory(tryPath.c_str()))
{
return SystemTools::CollapseFullPath(tryPath.c_str());
}
+#endif
+ // now try to add ext if it is different than name
+ if(ext.size())
+ {
+ tryPath = *p;
+ tryPath += "/";
+ tryPath += name;
+ tryPath += ext;
+ if(SystemTools::FileExists(tryPath.c_str()) &&
+ !SystemTools::FileIsDirectory(tryPath.c_str()))
+ {
+ return SystemTools::CollapseFullPath(tryPath.c_str());
+ }
+ }
}
// Couldn't find the program.