diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2022-09-16 19:17:27 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2022-09-27 15:09:06 (GMT) |
commit | 374d82bbcd461a5ee8d1d9d3a94abd8a26759c37 (patch) | |
tree | d390a842e701ad29e157ee5d097902a6305ddd02 /Source/cmakemain.cxx | |
parent | e3168128841485a0a579ad3b9125fdae5e12eec8 (diff) | |
download | CMake-374d82bbcd461a5ee8d1d9d3a94abd8a26759c37.zip CMake-374d82bbcd461a5ee8d1d9d3a94abd8a26759c37.tar.gz CMake-374d82bbcd461a5ee8d1d9d3a94abd8a26759c37.tar.bz2 |
cmake: Add --workflow mode
Fixes: #23118
Diffstat (limited to 'Source/cmakemain.cxx')
-rw-r--r-- | Source/cmakemain.cxx | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 6f3d0eb..b754b72 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -911,6 +911,68 @@ int do_install(int ac, char const* const* av) #endif } +int do_workflow(int ac, char const* const* av) +{ +#ifdef CMAKE_BOOTSTRAP + std::cerr << "This cmake does not support --workflow\n"; + return -1; +#else + std::string presetName; + bool listPresets = false; + + using CommandArgument = + cmCommandLineArgument<bool(std::string const& value)>; + + std::vector<CommandArgument> arguments = { + CommandArgument{ "--preset", CommandArgument::Values::One, + CommandArgument::setToValue(presetName) }, + CommandArgument{ "--list-presets", CommandArgument::Values::Zero, + CommandArgument::setToTrue(listPresets) } + }; + + std::vector<std::string> inputArgs; + + inputArgs.reserve(ac - 2); + cm::append(inputArgs, av + 2, av + ac); + + decltype(inputArgs.size()) i = 0; + for (; i < inputArgs.size(); ++i) { + std::string const& arg = inputArgs[i]; + bool matched = false; + bool parsed = false; + for (auto const& m : arguments) { + matched = m.matches(arg); + if (matched) { + parsed = m.parse(arg, i, inputArgs); + break; + } + } + if (!(matched && parsed)) { + if (!matched) { + std::cerr << "Unknown argument " << arg << std::endl; + } + break; + } + } + + if (presetName.empty() && !listPresets) { + std::cerr << "TODO: Usage\n"; + return 1; + } + + cmake cm(cmake::RoleInternal, cmState::Project); + cmSystemTools::SetMessageCallback( + [&cm](const std::string& msg, const cmMessageMetadata& md) { + cmakemainMessageCallback(msg, md, &cm); + }); + cm.SetProgressCallback([&cm](const std::string& msg, float prog) { + cmakemainProgressCallback(msg, prog, &cm); + }); + + return cm.Workflow(presetName, listPresets); +#endif +} + int do_open(int ac, char const* const* av) { #ifdef CMAKE_BOOTSTRAP @@ -980,6 +1042,9 @@ int main(int ac, char const* const* av) if (strcmp(av[1], "--open") == 0) { return do_open(ac, av); } + if (strcmp(av[1], "--workflow") == 0) { + return do_workflow(ac, av); + } if (strcmp(av[1], "-E") == 0) { return do_command(ac, av, std::move(consoleBuf)); } |