ENH: Add a findfile routine (as opposed to find executable or library) which doesn't

add any extensions - Borland make needs full paths to certain dependencies
otherwise linking doesn't work properly (dependencies aren't checked)
This commit is contained in:
John Biddiscombe 2001-09-11 19:58:22 -04:00
parent faafcdddbf
commit ea40b86683
2 changed files with 35 additions and 4 deletions

View File

@ -924,7 +924,34 @@ std::string cmSystemTools::TemporaryFileName()
return tempnam(0, "cmake"); return tempnam(0, "cmake");
} }
/**
* Find the file the given name. Searches the given path and then
* the system search path. Returns the full path to the file if it is
* found. Otherwise, the empty string is returned.
*/
std::string cmSystemTools::FindFile(const char* name,
const std::vector<std::string>& userPaths)
{
// Add the system search path to our path.
std::vector<std::string> path = userPaths;
cmSystemTools::GetPath(path);
std::string tryPath;
for(std::vector<std::string>::const_iterator p = path.begin();
p != path.end(); ++p)
{
tryPath = *p;
tryPath += "/";
tryPath += name;
if(cmSystemTools::FileExists(tryPath.c_str()) &&
!cmSystemTools::FileIsDirectory(tryPath.c_str()))
{
return cmSystemTools::CollapseFullPath(tryPath.c_str());
}
}
// Couldn't find the file.
return "";
}
/** /**
* Find the executable with the given name. Searches the given path and then * Find the executable with the given name. Searches the given path and then

View File

@ -205,6 +205,10 @@ public:
*/ */
static bool IsOff(const char* val); static bool IsOff(const char* val);
///! Find a file in the system PATH, with optional extra paths.
static std::string FindFile(const char* name,
const std::vector<std::string>& path= std::vector<std::string>());
///! Find an executable in the system PATH, with optional extra paths. ///! Find an executable in the system PATH, with optional extra paths.
static std::string FindProgram(const char* name, static std::string FindProgram(const char* name,
const std::vector<std::string>& path= std::vector<std::string>()); const std::vector<std::string>& path= std::vector<std::string>());