Skip to content

Support CMake presets, workflows and CTest in the CMake wrapper - #748

Open
Illustar0 wants to merge 7 commits into
Fallout-build:developfrom
Illustar0:feat/cmake-presets-ctest
Open

Illustar0 wants to merge 7 commits into
Fallout-build:developfrom
Illustar0:feat/cmake-presets-ctest

Conversation

@Illustar0

@Illustar0 Illustar0 commented Nov 16, 2026 •

Copy link
Copy Markdown

Closes #725

Add preset and workflow support to the CMake wrapper, and add a CTest wrapper. Builds that use CMakePresets.json no longer need to call cmake and ctest with raw argument strings.

Also, this PR doesn't introduce any breaking changes. I found that the tool generator actually ignores the default field in tool specs, so the CMake wrapper has never passed -G "Visual Studio 16 2019" -A x64 -S . -B ./out or any of the other defaults. Empty CMakeGenerateSettings produce no arguments at all. Removing these defaults therefore changes nothing.

What changed

  • CMakeGenerate and CMakeBuild get Preset (--preset) and PresetsFile (--presets-file, CMake 4.4 or later).
  • New CMakeWorkflow task for cmake --workflow --preset <name>.
  • New CTest tool wrapper (CTestTasks.CTest) for running tests: presets, test directory, configuration, parallel runs, output, filters, repeats, timeouts and JUnit reports. Dashboard, script and --build-and-test modes are not included.
  • CMakeBuild and CMakeInstall now always pass the binary directory right after --build or --install. Before, EnableVerbose().SetOutputDirectory("out") produced cmake --build --verbose out, which CMake rejects.
  • CMakeGenerator gets Ninja Multi-Config, Unix Makefiles, NMake Makefiles and MinGW Makefiles.
  • CMake.json no longer has default values, and wrong help texts are fixed. CMake and CTest are now listed in the CLI tools docs.

Example

using static Fallout.Common.Tools.CMake.CMakeTasks;
using static Fallout.Common.Tools.CTest.CTestTasks;

AbsolutePath SourceDirectory => RootDirectory / "native";
AbsolutePath LibraryPath => RootDirectory / "lib";

[Parameter] readonly string Preset = "ninja-release";

Target Compile => _ => _
    .Executes(() =>
    {
        CMakeGenerate(s => s
            .SetProcessWorkingDirectory(SourceDirectory)
            .SetPreset(Preset)
            .AddDefine($"MY_LIBRARY={LibraryPath}"));

        CMakeBuild(s => s
            .SetProcessWorkingDirectory(SourceDirectory)
            .SetPreset(Preset));
    });

Target Test => _ => _
    .DependsOn(Compile)
    .Executes(() => CTest(s => s
        .SetProcessWorkingDirectory(SourceDirectory)
        .SetPreset(Preset)
        .EnableOutputOnFailure()
        .SetOutputJunit(RootDirectory / "output" / "ctest.xml")));

// Runs every step of a workflow preset (configure, build, test) in one call
Target Workflow => _ => _
    .Executes(() => CMakeWorkflow(s => s
        .SetProcessWorkingDirectory(SourceDirectory)
        .SetPreset("ci")
        .EnableFresh()));

// Explicit values still apply on top of the preset
Target CompileMultiConfig => _ => _
    .Executes(() => CMakeGenerate(s => s
        .SetProcessWorkingDirectory(SourceDirectory)
        .SetPreset(Preset)
        .SetGenerator(CMakeGenerator.Ninja_Multi_Config)
        .SetOutputDirectory(RootDirectory / "out" / Preset)));

@Illustar0
Illustar0 requested a review from a team as a code owner November 16, 2026 02:39
- `CMakeBuild` and `CMakeInstall` now always put the binary directory directly after `--build` or `--install`
- Before, it followed the order of the setter calls, so `EnableVerbose().SetOutputDirectory("out")` produced `cmake --build --verbose out`, which CMake rejects
- Remove the `default` values from `CMake.json`. The generator ignores this field, so `CMakeGenerate()` never passed `-G`, `-A`, `-S` or `-B` by itself, and the values only made the spec misleading
- Fix help texts that described the wrong option, such as `CMakeGenerateSettings.OutputDirectory` and `CMakeInstallSettings.Configuration`
- Escape the angle brackets in the help of `Define`, which caused CS1570 warnings in the generated XML docs
- Add a spec that empty generate settings pass no arguments
- Add `Ninja Multi-Config`, `Unix Makefiles`, `NMake Makefiles` and `MinGW Makefiles` to `CMakeGenerator`
- Add `Preset` (`--preset`) and `PresetsFile` (`--presets-file`, CMake 4.4 or later) to `CMakeGenerateSettings` and `CMakeBuildSettings`
- Values set on the settings are still passed, so CMake applies them over the values from the preset
- The help of `CMakeBuildSettings.OutputDirectory` says not to combine it with `Preset`
- Add the `CMakeWorkflow` task for `cmake --workflow`, with `Preset`, `PresetsFile` (CMake 4.4 or later) and `Fresh`
- It uses `--preset <name>`, which CMake supports since 3.25, instead of the shorter form that needs CMake 3.31
- Add `CTestTasks.CTest` for the `ctest` executable, covering the options for running tests: presets, test directory, configuration, parallel runs, output, filters, repeats, timeouts and JUnit reports
- `Configuration` uses `CMakeConfiguration` from the CMake wrapper
- Dashboard, script and `--build-and-test` modes are not included
- Add CMake and CTest to the table of supported tools in the CLI tools docs. CMake was missing since its wrapper was added

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support CMake presets and CTest in the CMake tool wrapper

2 participants