diff options
author | Brad King <brad.king@kitware.com> | 2021-05-14 16:57:06 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-05-17 14:02:16 (GMT) |
commit | 5b3a71a83faf913aa4a9644779ae35c9d5eda733 (patch) | |
tree | 03c012dd1fa62ba1330e4c064bf6a8069aa5266f /Source/cmSystemTools.cxx | |
parent | ea9b1d36b8cdf384903021d41ca665848895480f (diff) | |
download | CMake-5b3a71a83faf913aa4a9644779ae35c9d5eda733.zip CMake-5b3a71a83faf913aa4a9644779ae35c9d5eda733.tar.gz CMake-5b3a71a83faf913aa4a9644779ae35c9d5eda733.tar.bz2 |
cmSystemTools: Adopt RelativeIfUnder helper
This returns a relative path if it does not start in `../`.
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r-- | Source/cmSystemTools.cxx | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index ab42810..2fba13f 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1491,6 +1491,20 @@ std::string cmSystemTools::ForceToRelativePath(std::string const& local_path, return relative; } +std::string cmSystemTools::RelativeIfUnder(std::string const& top, + std::string const& in) +{ + std::string out; + if (in == top) { + out = "."; + } else if (cmSystemTools::IsSubDirectory(in, top)) { + out = in.substr(top.size() + 1); + } else { + out = in; + } + return out; +} + #ifndef CMAKE_BOOTSTRAP bool cmSystemTools::UnsetEnv(const char* value) { |