1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

cmSystemTools: Adopt RelativeIfUnder helper

This returns a relative path if it does not start in `../`.
This commit is contained in:
Brad King
2021-05-14 12:57:06 -04:00
parent ea9b1d36b8
commit 5b3a71a83f
3 changed files with 21 additions and 9 deletions

View File

@@ -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

View File

@@ -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)
{

View File

@@ -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);