cmSystemTools: Add helpers for reading and parsing PATH env vars
This commit is contained in:
parent
d3ea15e801
commit
acd9636d9d
@ -1648,6 +1648,32 @@ std::string cmSystemTools::RelativeIfUnder(std::string const& top,
|
||||
return out;
|
||||
}
|
||||
|
||||
cm::optional<std::string> cmSystemTools::GetEnvVar(std::string const& var)
|
||||
{
|
||||
cm::optional<std::string> result;
|
||||
{
|
||||
std::string value;
|
||||
if (cmSystemTools::GetEnv(var, value)) {
|
||||
result = std::move(value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> cmSystemTools::SplitEnvPath(std::string const& value)
|
||||
{
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
static cm::string_view sep = ";"_s;
|
||||
#else
|
||||
static cm::string_view sep = ":"_s;
|
||||
#endif
|
||||
std::vector<std::string> paths = cmTokenize(value, sep);
|
||||
for (std::string& p : paths) {
|
||||
SystemTools::ConvertToUnixSlashes(p);
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
#ifndef CMAKE_BOOTSTRAP
|
||||
bool cmSystemTools::UnsetEnv(const char* value)
|
||||
{
|
||||
|
@ -399,6 +399,9 @@ public:
|
||||
static std::string RelativeIfUnder(std::string const& top,
|
||||
std::string const& in);
|
||||
|
||||
static cm::optional<std::string> GetEnvVar(std::string const& var);
|
||||
static std::vector<std::string> SplitEnvPath(std::string const& value);
|
||||
|
||||
#ifndef CMAKE_BOOTSTRAP
|
||||
/** Remove an environment variable */
|
||||
static bool UnsetEnv(const char* value);
|
||||
|
Loading…
Reference in New Issue
Block a user