diff options
author | Brad King <brad.king@kitware.com> | 2003-02-07 19:04:16 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2003-02-07 19:04:16 (GMT) |
commit | cde384411d1907d93369c144ec7b2f28da2628d5 (patch) | |
tree | 2b5aeb18901a5c20d408b3eff32e27e82c252be8 /Source/cmSystemTools.cxx | |
parent | f2b47501694f6951c97335676b2c577cbb4fd76f (diff) | |
download | CMake-cde384411d1907d93369c144ec7b2f28da2628d5.zip CMake-cde384411d1907d93369c144ec7b2f28da2628d5.tar.gz CMake-cde384411d1907d93369c144ec7b2f28da2628d5.tar.bz2 |
Several fixes/improvements:
- Fixed CollapseFullPath to work on relative paths with base paths
not in the current working directory.
- INCLUDE command now supports relative paths (using above fix).
- Added ABSOLUTE option to GET_FILENAME_COMPONENT command to
unwind symlinks and relative paths.
- Fixed libName_EXPORTS macro definition to be valid C identifier.
- Added DEFINE_SYMBOL target propterty for customizing the export symbol.
- Implemented LINK_FLAGS target propterty for libraries in VC6 and VC7.
Several of these fixes were contributed by Gareth Jones.
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r-- | Source/cmSystemTools.cxx | 84 |
1 files changed, 66 insertions, 18 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 99c04b0..b5f3d44 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1768,24 +1768,42 @@ void cmSystemTools::SplitProgramPath(const char* in_name, /** * Given a path to a file or directory, convert it to a full path. - * This collapses away relative paths. The full path is returned. + * This collapses away relative paths relative to the cwd argument + * (which defaults to the current working directory). The full path + * is returned. */ -std::string cmSystemTools::CollapseFullPath(const char* in_name) +std::string cmSystemTools::CollapseFullPath(const char* in_relative) +{ + return cmSystemTools::CollapseFullPath(in_relative, 0); +} + +std::string cmSystemTools::CollapseFullPath(const char* in_relative, + const char* in_base) { std::string dir, file; - cmSystemTools::SplitProgramPath(in_name, dir, file); + cmSystemTools::SplitProgramPath(in_relative, dir, file); + + // Save original working directory. + std::string orig = cmSystemTools::GetCurrentWorkingDirectory(); + + // Change to base of relative path. + if(in_base) + { + Chdir(in_base); + } + #ifdef _WIN32 - // Ultra-hack warning: - // This changes to the target directory, saves the working directory, - // and then changes back to the original working directory. - std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); - if(dir != "") { Chdir(dir.c_str()); } + // Follow relative path. + if(dir != "") + { + Chdir(dir.c_str()); + } + + // Get the resulting directory. std::string newDir = cmSystemTools::GetCurrentWorkingDirectory(); - Chdir(cwd.c_str()); - + + // Add the file back on to the directory. cmSystemTools::ConvertToUnixSlashes(newDir); - std::string newPath = newDir+"/"+file; - return newPath; #else # ifdef MAXPATHLEN char resolved_name[MAXPATHLEN]; @@ -1796,21 +1814,31 @@ std::string cmSystemTools::CollapseFullPath(const char* in_name) char resolved_name[5024]; # endif # endif + + // Resolve relative path. + std::string newDir; if(dir != "") { realpath(dir.c_str(), resolved_name); - dir = resolved_name; + newDir = resolved_name; } else { - dir = cmSystemTools::GetCurrentWorkingDirectory(); + newDir = cmSystemTools::GetCurrentWorkingDirectory(); } - if(file == "") +#endif + + // Restore original working directory. + Chdir(orig.c_str()); + + // Construct and return the full path. + std::string newPath = newDir; + if(file != "") { - return dir; + newPath += "/"; + newPath += file; } - return dir + "/" + file; -#endif + return newPath; } bool cmSystemTools::Split(const char* str, std::vector<cmStdString>& lines) @@ -2330,6 +2358,26 @@ void cmSystemTools::SplitProgramFromArgs(const char* path, args = ""; } +std::string cmSystemTools::MakeCindentifier(const char* s) +{ + std::string str(s); + if (str.find_first_of("0123456789") == 0) + { + str = "_" + str; + } + + std::string permited_chars("_" + "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789"); + std::string::size_type pos = 0; + while ((pos = str.find_first_not_of(permited_chars, pos)) != std::string::npos) + { + str[pos] = '_'; + } + return str; +} + #if defined(_MSC_VER) && defined(_DEBUG) # include <crtdbg.h> # include <stdio.h> |