Use the NAME and COMMAND keyword form of add_test(), which allows you to use generator expressions. Then use $<CONFIG> instead of ${CMAKE_BUILD_TYPE}. I think that should get you most of the way there. I don’t know if the --build-config-sample might also be useful to you, but maybe you don’t need that.
And what is about --clean-first, it seams to me, I should use it to get same behaviour with all generators?
But with this build-options, it always fails with Ninja generator?
Start testing: Oct 31 10:41 CET
----------------------------------------------------------
80/80 Testing: find-package-test
80/80 Test: find-package-test
Command: "/usr/local/bin/ctest" "--output-on-failure" "-C" "RelWithDebInfo" "--build-and-test" "/Users/clausklein/Workspace/cpp/beman-project/execution26/src/beman/execution26/tests" "/Users/clausklein/Workspace/cpp/beman-project/execution26/build/release/src/beman/execution26/tests/find-package-test" "--build-generator" "Ninja" "--build-makeprogram" "/usr/local/bin/ninja" "--build-options" "--clean-first" "-DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++" "-DCMAKE_BUILD_TYPE=RelWithDebInfo" "-DCMAKE_PREFIX_PATH=/Users/clausklein/Workspace/cpp/beman-project/execution26/stagedir"
Directory: /Users/clausklein/Workspace/cpp/beman-project/execution26/build/release/src/beman/execution26/tests
"find-package-test" start time: Oct 31 10:41 CET
Output:
----------------------------------------------------------
<end of output>
Test time = 0.02 sec
----------------------------------------------------------
Test Failed.
"find-package-test" end time: Oct 31 10:41 CET
"find-package-test" time elapsed: 00:00:00
----------------------------------------------------------
End testing: Oct 31 10:41 CET