ctest presets and --build-and-test

I’m trying to use the --build-and-test option with ctest in conjunction with presets. I’m using Ninja Multi-Config as my generator. My test presets include both the configurePreset and configuration fields yet when I try to use ctest --build-and-test --preset=mypreset I still get:

--build-and-test requires that the generator be provided using the --build-generator command line option. 

It seems based on the information in the preset that ctest should be able to figure this out on its own, any reason it doesn’t?

I ran into this scenario again today and did a Google search… my own post was the first result! Does anyone have any advice on how to achieve this yet?

Basically I currently have to do:

cmake --build --preset foo-release && ctest --preset foo-release # etc

Is there a way to have ctest perform the build for the corresponding build preset without having to chain these two commands?

Test presets are not intended to run --build-and-test invocations. They are only meant for running test cases defined by the project through add_test() and so forth. If you want to execute a test case that runs ctest --build-and-test, you need to wrap that as a test case of the main project. For example:

add_test(NAME blah
    COMMAND ${CMAKE_CTEST_COMMAND} --build-and-test ....  # the rest of your arguments here

@craig.scott hm ok, maybe I’ve misunderstood the purpose of --build-and-test. I re-read the section in your book and I think I get how it should be used. It seems workflow presets would achieve what I am looking for.