summaryrefslogtreecommitdiff
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-02-14 14:22:52 -0500
committerBrad King <brad.king@kitware.com>2023-02-23 09:05:59 -0500
commitacd9636d9d5ccc81d07b2cc65fa39dbc02fff436 (patch)
tree523ff651465d095ba2b9d1b4b85e3ec2cb6df890 /Source/cmSystemTools.cxx
parentd3ea15e80152511946c719404466dfa199532005 (diff)
downloadcmake-acd9636d9d5ccc81d07b2cc65fa39dbc02fff436.tar.gz
cmSystemTools: Add helpers for reading and parsing PATH env vars
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx26
1 files changed, 26 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 3d61270b76..1fb0079103 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)
{