diff options
author | Sam Freed <safreed@microsoft.com> | 2020-12-14 18:06:08 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-02-01 16:59:40 (GMT) |
commit | 676ecf0d37cf5cfda390f52ce60babcb5da78108 (patch) | |
tree | 79129100ed585db7a91b82778166c1e1d3d6f7e5 /Source/cmakemain.cxx | |
parent | 4f4f2028b8e2c45eb6940d1ec5069caad9b606a2 (diff) | |
download | CMake-676ecf0d37cf5cfda390f52ce60babcb5da78108.zip CMake-676ecf0d37cf5cfda390f52ce60babcb5da78108.tar.gz CMake-676ecf0d37cf5cfda390f52ce60babcb5da78108.tar.bz2 |
cmake-presets: Add build and test presets
Fixes: #21391
Diffstat (limited to 'Source/cmakemain.cxx')
-rw-r--r-- | Source/cmakemain.cxx | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index ba471b7..cd3c955 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -425,6 +425,8 @@ int do_build(int ac, char const* const* av) bool foundClean = false; bool foundNonClean = false; bool verbose = cmSystemTools::HasEnv("VERBOSE"); + std::string presetName; + bool listPresets = false; auto jLambda = [&](std::string const& value) -> bool { jobs = extract_job_number("-j", value); @@ -464,6 +466,16 @@ int do_build(int ac, char const* const* av) cmCommandLineArgument<bool(std::string const& value)>; std::vector<CommandArgument> arguments = { + CommandArgument{ "--preset", CommandArgument::Values::One, + [&](std::string const& value) -> bool { + presetName = value; + return true; + } }, + CommandArgument{ "--list-presets", CommandArgument::Values::Zero, + [&](std::string const&) -> bool { + listPresets = true; + return true; + } }, CommandArgument{ "-j", CommandArgument::Values::ZeroOrOne, jLambda }, CommandArgument{ "--parallel", CommandArgument::Values::ZeroOrOne, parallelLambda }, @@ -494,11 +506,26 @@ int do_build(int ac, char const* const* av) }; if (ac >= 3) { - dir = cmSystemTools::CollapseFullPath(av[2]); - std::vector<std::string> inputArgs; - inputArgs.reserve(ac - 3); - cm::append(inputArgs, av + 3, av + ac); + + bool hasPreset = false; + for (int i = 2; i < ac; ++i) { + if (strcmp(av[i], "--list-presets") == 0 || + strcmp(av[i], "--preset") == 0) { + hasPreset = true; + break; + } + } + + if (hasPreset) { + inputArgs.reserve(ac - 2); + cm::append(inputArgs, av + 2, av + ac); + } else { + dir = cmSystemTools::CollapseFullPath(av[2]); + + inputArgs.reserve(ac - 3); + cm::append(inputArgs, av + 3, av + ac); + } decltype(inputArgs.size()) i = 0; for (; i < inputArgs.size() && !nativeOptionsPassed; ++i) { @@ -551,12 +578,16 @@ int do_build(int ac, char const* const* av) } } - if (dir.empty()) { + if (dir.empty() && presetName.empty() && !listPresets) { /* clang-format off */ std::cerr << - "Usage: cmake --build <dir> [options] [-- [native-options]]\n" + "Usage: cmake --build [<dir> | --preset <preset>] [options] [-- [native-options]]\n" "Options:\n" " <dir> = Project binary directory to be built.\n" + " --preset <preset>\n" + " = Specify a build preset.\n" + " --list-presets\n" + " = List available build presets.\n" " --parallel [<jobs>], -j [<jobs>]\n" " = Build in parallel using the given number of jobs. \n" " If <jobs> is omitted the native build tool's \n" @@ -587,8 +618,10 @@ int do_build(int ac, char const* const* av) cm.SetProgressCallback([&cm](const std::string& msg, float prog) { cmakemainProgressCallback(msg, prog, &cm); }); - return cm.Build(jobs, dir, targets, config, nativeOptions, cleanFirst, - verbose); + + return cm.Build(jobs, std::move(dir), std::move(targets), std::move(config), + std::move(nativeOptions), cleanFirst, verbose, presetName, + listPresets); #endif } |