summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2013-07-02 13:03:52 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2013-07-02 13:03:52 (GMT)
commit357db89d27f488ca9482d1a9ac1b3073bad40a01 (patch)
tree99bb95112eca9d7297139edbd1fd0d35f08337e1 /Source/cmSystemTools.cxx
parent000793aae70f9a627838427bfee5ed7334c04adb (diff)
parent551d3343cd16c566be4b33e96c892c3e769951af (diff)
downloadCMake-357db89d27f488ca9482d1a9ac1b3073bad40a01.zip
CMake-357db89d27f488ca9482d1a9ac1b3073bad40a01.tar.gz
CMake-357db89d27f488ca9482d1a9ac1b3073bad40a01.tar.bz2
Merge topic 'make-depends-collapse-paths'
551d334 cmDependsC: Collapse relative include paths
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx34
1 files changed, 34 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 4ae16cc..aa5fc94 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -1594,6 +1594,40 @@ std::string cmSystemTools::RelativePath(const char* local, const char* remote)
return cmsys::SystemTools::RelativePath(local, remote);
}
+std::string cmSystemTools::CollapseCombinedPath(std::string const& dir,
+ std::string const& file)
+{
+ if(dir.empty() || dir == ".")
+ {
+ return file;
+ }
+
+ std::vector<std::string> dirComponents;
+ std::vector<std::string> fileComponents;
+ cmSystemTools::SplitPath(dir.c_str(), dirComponents);
+ cmSystemTools::SplitPath(file.c_str(), fileComponents);
+
+ if(fileComponents.empty())
+ {
+ return dir;
+ }
+ if(fileComponents[0] != "")
+ {
+ // File is not a relative path.
+ return file;
+ }
+
+ std::vector<std::string>::iterator i = fileComponents.begin()+1;
+ while(i != fileComponents.end() && *i == ".." && dirComponents.size() > 1)
+ {
+ ++i; // Remove ".." file component.
+ dirComponents.pop_back(); // Remove last dir component.
+ }
+
+ dirComponents.insert(dirComponents.end(), i, fileComponents.end());
+ return cmSystemTools::JoinPath(dirComponents);
+}
+
#ifdef CMAKE_BUILD_WITH_CMAKE
//----------------------------------------------------------------------
bool cmSystemTools::UnsetEnv(const char* value)