summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-05-14 16:57:06 (GMT)
committerBrad King <brad.king@kitware.com>2021-05-17 14:02:16 (GMT)
commit5b3a71a83faf913aa4a9644779ae35c9d5eda733 (patch)
tree03c012dd1fa62ba1330e4c064bf6a8069aa5266f /Source
parentea9b1d36b8cdf384903021d41ca665848895480f (diff)
downloadCMake-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')
-rw-r--r--Source/cmFileAPICodemodel.cxx10
-rw-r--r--Source/cmSystemTools.cxx14
-rw-r--r--Source/cmSystemTools.h6
3 files changed, 21 insertions, 9 deletions
diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx
index 6b8757c..6b35842 100644
--- a/Source/cmFileAPICodemodel.cxx
+++ b/Source/cmFileAPICodemodel.cxx
@@ -57,15 +57,7 @@ using TargetIndexMapType =
std::string 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;
+ return cmSystemTools::RelativeIfUnder(top, in);
}
class JBTIndex
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)
{
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 9f9c493..474f591 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -346,6 +346,12 @@ public:
static std::string ForceToRelativePath(std::string const& local_path,
std::string const& remote_path);
+ /**
+ * Express the 'in' path relative to 'top' if it does not start in '../'.
+ */
+ static std::string RelativeIfUnder(std::string const& top,
+ std::string const& in);
+
#ifndef CMAKE_BOOTSTRAP
/** Remove an environment variable */
static bool UnsetEnv(const char* value);