MCPcopy Create free account
hub / github.com/Kitware/CMake / QueryWindowsRegistry

Function QueryWindowsRegistry

Source/cmCMakeHostSystemInformationCommand.cxx:629–713  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

627
628template <typename Range>
629bool QueryWindowsRegistry(Range args, cmExecutionStatus& status,
630 std::string const& variable)
631{
632 using View = cmWindowsRegistry::View;
633 if (args.empty()) {
634 status.SetError("missing <key> specification.");
635 return false;
636 }
637 std::string const& key = *args.begin();
638
639 struct Arguments : public ArgumentParser::ParseResult
640 {
641 std::string ValueName;
642 bool ValueNames = false;
643 bool SubKeys = false;
644 std::string View;
645 std::string Separator;
646 std::string ErrorVariable;
647 };
648 cmArgumentParser<Arguments> parser;
649 parser.Bind("VALUE"_s, &Arguments::ValueName)
650 .Bind("VALUE_NAMES"_s, &Arguments::ValueNames)
651 .Bind("SUBKEYS"_s, &Arguments::SubKeys)
652 .Bind("VIEW"_s, &Arguments::View)
653 .Bind("SEPARATOR"_s, &Arguments::Separator)
654 .Bind("ERROR_VARIABLE"_s, &Arguments::ErrorVariable);
655 std::vector<std::string> invalidArgs;
656
657 Arguments const arguments = parser.Parse(args.advance(1), &invalidArgs);
658 if (!invalidArgs.empty()) {
659 status.SetError(cmStrCat("given invalid argument(s) \"",
660 cmJoin(invalidArgs, ", "_s), "\"."));
661 return false;
662 }
663 if (arguments.MaybeReportError(status.GetMakefile())) {
664 return true;
665 }
666 if ((!arguments.ValueName.empty() &&
667 (arguments.ValueNames || arguments.SubKeys)) ||
668 (arguments.ValueName.empty() && arguments.ValueNames &&
669 arguments.SubKeys)) {
670 status.SetError("given mutually exclusive sub-options VALUE, "
671 "VALUE_NAMES or SUBKEYS.");
672 return false;
673 }
674
675 if (!arguments.View.empty() && !cmWindowsRegistry::ToView(arguments.View)) {
676 status.SetError(
677 cmStrCat("given invalid value for VIEW: ", arguments.View, '.'));
678 return false;
679 }
680
681 auto& makefile = status.GetMakefile();
682
683 makefile.AddDefinition(variable, ""_s);
684
685 auto view = arguments.View.empty()
686 ? View::Both

Callers 1

Calls 15

to_stringFunction · 0.85
MaybeReportErrorMethod · 0.80
GetValueNamesMethod · 0.80
GetSubKeysMethod · 0.80
GetLastErrorMethod · 0.80
cmStrCatFunction · 0.70
cmJoinFunction · 0.70
emptyMethod · 0.45
SetErrorMethod · 0.45
beginMethod · 0.45
BindMethod · 0.45
ParseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…