diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2000-09-12 09:30:35 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2000-09-12 09:30:35 (GMT) |
commit | aa3ca2b432ab346c28ea7c758cbbf57ca346e139 (patch) | |
tree | dec236eb51e746ae123edb3e9c01a5595381e12f /Source/cmSystemTools.cxx | |
parent | e2ad65d3c27177b8f3ee3c9b81382ea883a3bfbd (diff) | |
download | CMake-aa3ca2b432ab346c28ea7c758cbbf57ca346e139.zip CMake-aa3ca2b432ab346c28ea7c758cbbf57ca346e139.tar.gz CMake-aa3ca2b432ab346c28ea7c758cbbf57ca346e139.tar.bz2 |
ENH: CMake and configure now use SUBDIRS in CMakeLists.txt to find all the directories of the system.
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r-- | Source/cmSystemTools.cxx | 108 |
1 files changed, 105 insertions, 3 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 49dc32b..b8a44c9 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1,7 +1,52 @@ #include "cmSystemTools.h" -#include <direct.h> #include "errno.h" +#include <sys/stat.h> + +#ifdef _MSC_VER #include <windows.h> +#include <direct.h> +inline int Mkdir(const char* dir) +{ + return _mkdir(dir); +} +#else +#include <sys/types.h> +#include <fcntl.h> +#include <unistd.h> +inline int Mkdir(const char* dir) +{ + return mkdir(dir, 00700); +} +#endif + +// remove extra spaces and the "\" character from the name +// of the class as it is in the CMakeLists.txt +std::string cmSystemTools::CleanUpName(const char* name) +{ + std::string className = name; + size_t i =0; + while(className[i] == ' ') + { + i++; + } + if(i) + { + className = className.substr(i, className.size()); + } + size_t pos = className.find('\\'); + if(pos != std::string::npos) + { + className = className.substr(0, pos); + } + + pos = className.find(' '); + if(pos != std::string::npos) + { + className = className.substr(0, pos); + } + return className; +} + bool cmSystemTools::MakeDirectory(const char* path) { @@ -21,10 +66,10 @@ bool cmSystemTools::MakeDirectory(const char* path) while((pos = dir.find('/', pos)) != std::string::npos) { std::string topdir = dir.substr(0, pos); - _mkdir(topdir.c_str()); + Mkdir(topdir.c_str()); pos++; } - if(_mkdir(path) != 0) + if(Mkdir(path) != 0) { // if it is some other error besides directory exists // then return false @@ -36,6 +81,9 @@ bool cmSystemTools::MakeDirectory(const char* path) return true; } + +// replace replace with with as many times as it shows up in source. +// write the result into source. void cmSystemTools::ReplaceString(std::string& source, const char* replace, const char* with) @@ -52,3 +100,57 @@ void cmSystemTools::ReplaceString(std::string& source, start = source.find(replace, start + lengthReplace ); } } + +// return true if the file exists +bool cmSystemTools::FileExists(const char* filename) +{ + struct stat fs; + if (stat(filename, &fs) != 0) + { + return false; + } + else + { + return true; + } +} + +// Read a list from a CMakeLists.txt file open stream. +// assume the stream has just read "VAR = \" +// read until there is not a "\" at the end of the line. +void cmSystemTools::ReadList(std::vector<std::string>& stringList, + std::ifstream& fin) +{ + char inbuffer[2048]; + bool done = false; + while ( !done ) + { + fin.getline(inbuffer, 2047 ); + std::string inname = inbuffer; + if(inname.find('\\') == std::string::npos) + { + done = true; + } + if(inname.size()) + { + stringList.push_back(cmSystemTools::CleanUpName(inname.c_str())); + } + } +} + + +// convert windows slashes to unix slashes \ with / +void cmSystemTools::ConvertToUnixSlashes(std::string& path) +{ + std::string::size_type pos = path.find('\\'); + while(pos != std::string::npos) + { + path[pos] = '/'; + pos = path.find('\\'); + } + // remove any trailing slash + if(path[path.size()-1] == '/') + { + path = path.substr(0, path.size()-1); + } +} |