Browse Source

cmExperimental: add support for getting a feature value from its name

Ben Boeckel 1 year ago
parent
commit
e8582abc6d
2 changed files with 17 additions and 0 deletions
  1. 14 0
      Source/cmExperimental.cxx
  2. 3 0
      Source/cmExperimental.h

+ 14 - 0
Source/cmExperimental.cxx

@@ -54,6 +54,20 @@ const cmExperimental::FeatureData& cmExperimental::DataForFeature(Feature f)
   return ::DataForFeature(f);
 }
 
+cm::optional<cmExperimental::Feature> cmExperimental::FeatureByName(
+  std::string const& name)
+{
+  size_t idx = 0;
+  for (auto const& feature : LookupTable) {
+    if (feature.Name == name) {
+      return static_cast<Feature>(idx);
+    }
+    ++idx;
+  }
+
+  return {};
+}
+
 bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f)
 {
   bool enabled = false;

+ 3 - 0
Source/cmExperimental.h

@@ -8,6 +8,8 @@
 #include <string>
 #include <vector>
 
+#include <cm/optional>
+
 class cmMakefile;
 
 class cmExperimental
@@ -40,5 +42,6 @@ public:
   };
 
   static const FeatureData& DataForFeature(Feature f);
+  static cm::optional<Feature> FeatureByName(std::string const& name);
   static bool HasSupportEnabled(cmMakefile const& mf, Feature f);
 };