summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmCMakeHostSystemInformationCommand.cxx18
-rw-r--r--Source/cmWindowsRegistry.cxx34
-rw-r--r--Source/cmWindowsRegistry.h5
3 files changed, 44 insertions, 13 deletions
diff --git a/Source/cmCMakeHostSystemInformationCommand.cxx b/Source/cmCMakeHostSystemInformationCommand.cxx
index 0c41c68..2a019b1 100644
--- a/Source/cmCMakeHostSystemInformationCommand.cxx
+++ b/Source/cmCMakeHostSystemInformationCommand.cxx
@@ -9,7 +9,6 @@
#include <map>
#include <string>
#include <type_traits>
-#include <unordered_map>
#include <utility>
#include <cm/optional>
@@ -469,14 +468,6 @@ bool QueryWindowsRegistry(Range args, cmExecutionStatus& status,
std::string const& variable)
{
using View = cmWindowsRegistry::View;
- static std::unordered_map<cm::string_view, cmWindowsRegistry::View>
- ViewDefinitions{
- { "BOTH"_s, View::Both }, { "HOST"_s, View::Host },
- { "TARGET"_s, View::Target }, { "32"_s, View::Reg32 },
- { "64"_s, View::Reg64 }, { "32_64"_s, View::Reg32_64 },
- { "64_32"_s, View::Reg64_32 }
- };
-
if (args.empty()) {
status.SetError("missing <key> specification.");
return false;
@@ -522,8 +513,8 @@ bool QueryWindowsRegistry(Range args, cmExecutionStatus& status,
"\"VALUE_NAMES\" or \"SUBKEYS\".");
return false;
}
- if (!arguments.View.empty() &&
- ViewDefinitions.find(arguments.View) == ViewDefinitions.end()) {
+
+ if (!arguments.View.empty() && !cmWindowsRegistry::ToView(arguments.View)) {
status.SetError(
cmStrCat("given invalid value for \"VIEW\": ", arguments.View, '.'));
return false;
@@ -533,8 +524,9 @@ bool QueryWindowsRegistry(Range args, cmExecutionStatus& status,
makefile.AddDefinition(variable, ""_s);
- auto view =
- arguments.View.empty() ? View::Both : ViewDefinitions[arguments.View];
+ auto view = arguments.View.empty()
+ ? View::Both
+ : *cmWindowsRegistry::ToView(arguments.View);
cmWindowsRegistry registry(makefile);
if (arguments.ValueNames) {
auto result = registry.GetValueNames(key, view);
diff --git a/Source/cmWindowsRegistry.cxx b/Source/cmWindowsRegistry.cxx
index b452ec6..9048334 100644
--- a/Source/cmWindowsRegistry.cxx
+++ b/Source/cmWindowsRegistry.cxx
@@ -3,6 +3,8 @@
#include "cmWindowsRegistry.h"
+#include <unordered_map>
+
#if defined(_WIN32) && !defined(__CYGWIN__)
# include <algorithm>
# include <cstdint>
@@ -335,6 +337,38 @@ cmWindowsRegistry::cmWindowsRegistry(cmMakefile& makefile)
#endif
}
+cm::optional<cmWindowsRegistry::View> cmWindowsRegistry::ToView(
+ cm::string_view name)
+{
+ static std::unordered_map<cm::string_view, cmWindowsRegistry::View>
+ ViewDefinitions{
+ { "BOTH"_s, View::Both }, { "HOST"_s, View::Host },
+ { "TARGET"_s, View::Target }, { "32"_s, View::Reg32 },
+ { "64"_s, View::Reg64 }, { "32_64"_s, View::Reg32_64 },
+ { "64_32"_s, View::Reg64_32 }
+ };
+
+ auto it = ViewDefinitions.find(name);
+
+ return it == ViewDefinitions.end() ? cm::nullopt
+ : cm::optional{ it->second };
+}
+
+cm::string_view cmWindowsRegistry::FromView(View view)
+{
+ static std::unordered_map<cmWindowsRegistry::View, cm::string_view>
+ ViewDefinitions{
+ { View::Both, "BOTH"_s }, { View::Host, "HOST"_s },
+ { View::Target, "TARGET"_s }, { View::Reg32, "32"_s },
+ { View::Reg64, "64"_s }, { View::Reg32_64, "32_64"_s },
+ { View::Reg64_32, "64_32"_s }
+ };
+
+ auto it = ViewDefinitions.find(view);
+
+ return it == ViewDefinitions.end() ? ""_s : it->second;
+}
+
cm::string_view cmWindowsRegistry::GetLastError() const
{
return this->LastError;
diff --git a/Source/cmWindowsRegistry.h b/Source/cmWindowsRegistry.h
index 6f10b3a..e04ce87 100644
--- a/Source/cmWindowsRegistry.h
+++ b/Source/cmWindowsRegistry.h
@@ -27,6 +27,11 @@ public:
Reg64
};
+ // Helper routine to convert string to enum value
+ static cm::optional<View> ToView(cm::string_view name);
+ // Helper routine to convert enum to string
+ static cm::string_view FromView(View view);
+
cm::optional<std::string> ReadValue(cm::string_view key,
View view = View::Both,
cm::string_view separator = "\0"_s)