summaryrefslogtreecommitdiff
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-05-14 12:57:06 -0400
committerBrad King <brad.king@kitware.com>2021-05-17 10:02:16 -0400
commit5b3a71a83faf913aa4a9644779ae35c9d5eda733 (patch)
tree03c012dd1fa62ba1330e4c064bf6a8069aa5266f /Source/cmSystemTools.cxx
parentea9b1d36b8cdf384903021d41ca665848895480f (diff)
downloadcmake-5b3a71a83faf913aa4a9644779ae35c9d5eda733.tar.gz
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.cxx14
1 files changed, 14 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index ab42810feb..2fba13f436 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)
{