From acd9636d9d5ccc81d07b2cc65fa39dbc02fff436 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 14 Feb 2023 14:22:52 -0500 Subject: cmSystemTools: Add helpers for reading and parsing PATH env vars --- Source/cmSystemTools.cxx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'Source/cmSystemTools.cxx') 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 cmSystemTools::GetEnvVar(std::string const& var) +{ + cm::optional result; + { + std::string value; + if (cmSystemTools::GetEnv(var, value)) { + result = std::move(value); + } + } + return result; +} + +std::vector 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 paths = cmTokenize(value, sep); + for (std::string& p : paths) { + SystemTools::ConvertToUnixSlashes(p); + } + return paths; +} + #ifndef CMAKE_BOOTSTRAP bool cmSystemTools::UnsetEnv(const char* value) { -- cgit v1.2.1