diff options
author | Brad King <brad.king@kitware.com> | 2023-02-14 19:22:52 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-02-23 14:05:59 (GMT) |
commit | acd9636d9d5ccc81d07b2cc65fa39dbc02fff436 (patch) | |
tree | 523ff651465d095ba2b9d1b4b85e3ec2cb6df890 | |
parent | d3ea15e80152511946c719404466dfa199532005 (diff) | |
download | CMake-acd9636d9d5ccc81d07b2cc65fa39dbc02fff436.zip CMake-acd9636d9d5ccc81d07b2cc65fa39dbc02fff436.tar.gz CMake-acd9636d9d5ccc81d07b2cc65fa39dbc02fff436.tar.bz2 |
cmSystemTools: Add helpers for reading and parsing PATH env vars
-rw-r--r-- | Source/cmSystemTools.cxx | 26 | ||||
-rw-r--r-- | Source/cmSystemTools.h | 3 |
2 files changed, 29 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 3d61270..1fb0079 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -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) { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 09f2bf0..7d55d4b 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -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); |