Browse Source

cmSystemTools: Add GetEnvPathNormalized to get paths from environment

Brad King 1 year ago
parent
commit
9fe09ebc53
2 changed files with 14 additions and 0 deletions
  1. 13 0
      Source/cmSystemTools.cxx
  2. 1 0
      Source/cmSystemTools.h

+ 13 - 0
Source/cmSystemTools.cxx

@@ -20,6 +20,8 @@
 
 #include "cmSystemTools.h"
 
+#include <iterator>
+
 #include <cm/optional>
 #include <cmext/algorithm>
 #include <cmext/string_view>
@@ -1614,6 +1616,17 @@ cm::optional<std::string> cmSystemTools::GetEnvVar(std::string const& var)
   return result;
 }
 
+std::vector<std::string> cmSystemTools::GetEnvPathNormalized(
+  std::string const& var)
+{
+  std::vector<std::string> result;
+  if (cm::optional<std::string> env = cmSystemTools::GetEnvVar(var)) {
+    std::vector<std::string> p = cmSystemTools::SplitEnvPathNormalized(*env);
+    std::move(p.begin(), p.end(), std::back_inserter(result));
+  }
+  return result;
+}
+
 std::vector<std::string> cmSystemTools::SplitEnvPath(cm::string_view in)
 {
 #if defined(_WIN32) && !defined(__CYGWIN__)

+ 1 - 0
Source/cmSystemTools.h

@@ -399,6 +399,7 @@ public:
                                      std::string const& in);
 
   static cm::optional<std::string> GetEnvVar(std::string const& var);
+  static std::vector<std::string> GetEnvPathNormalized(std::string const& var);
 
   static std::vector<std::string> SplitEnvPath(cm::string_view in);
   static std::vector<std::string> SplitEnvPathNormalized(cm::string_view in);