mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 21:31:08 -06:00
Refactor: Simplify GetValue() function calls
This commit is contained in:
@@ -439,6 +439,21 @@ cm::optional<std::string> GetValue(cmExecutionStatus& status,
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
cm::optional<std::string> GetValueChained()
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename GetterFn, typename... Next>
|
||||||
|
cm::optional<std::string> GetValueChained(GetterFn current, Next... chain)
|
||||||
|
{
|
||||||
|
auto value = current();
|
||||||
|
if (value.has_value()) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return GetValueChained(chain...);
|
||||||
|
}
|
||||||
// END Private functions
|
// END Private functions
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
@@ -475,24 +490,21 @@ bool cmCMakeHostSystemInformationCommand(std::vector<std::string> const& args,
|
|||||||
result_list += DELIM[!result_list.empty()];
|
result_list += DELIM[!result_list.empty()];
|
||||||
|
|
||||||
auto const& key = args[i];
|
auto const& key = args[i];
|
||||||
auto value = GetValue(info, key);
|
// clang-format off
|
||||||
if (!value) {
|
auto value =
|
||||||
|
GetValueChained(
|
||||||
|
[&]() { return GetValue(info, key); }
|
||||||
|
#ifdef __linux__
|
||||||
|
, [&]() { return GetValue(status, key, variable); }
|
||||||
|
#endif
|
||||||
#ifdef HAVE_VS_SETUP_HELPER
|
#ifdef HAVE_VS_SETUP_HELPER
|
||||||
value = GetValue(status, key);
|
, [&]() { return GetValue(status, key); }
|
||||||
if (!value) {
|
#endif
|
||||||
status.SetError("does not recognize <key> " + key);
|
);
|
||||||
return false;
|
// clang-format on
|
||||||
}
|
if (!value) {
|
||||||
#elif defined(__linux__)
|
|
||||||
value = GetValue(status, key, variable);
|
|
||||||
if (!value) {
|
|
||||||
status.SetError("does not recognize <key> " + key);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
status.SetError("does not recognize <key> " + key);
|
status.SetError("does not recognize <key> " + key);
|
||||||
return false;
|
return false;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
result_list += value.value();
|
result_list += value.value();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user