When I configure a build in CMake using a build-preset, I can have a handy default for the build dir (e.g. --preset=release
can default to build/Release
)… but I can always use -B build_dir
to override this if I want (e.g., if I need a completely-out-of-tree build directory, for buildbots or other unusual environments). This is great!
Unfortunately, it doesn’t seem possible to use test-presets in CTest with this kind of setup: there doesn’t seem to be a flag to override the default for binaryDir in the test preset (using --test-dir
appears to do nothing in this situation).
This seems like a disappointing oversight for presets; ideally, there would be a (common?) flag that could be used to override the binaryDir for a given preset. The only workaround I’ve found is to maintain a separate set of presets, which is something that really should be necessary.
Is there any way to make this work as of recent versions of CMake? If not, could we find a way to make it work in the future?
Example reproducer (courtesy of Alex Reinking):
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 22,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "default",
"description": "default",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build"
}
],
"testPresets": [
{
"name": "default",
"configurePreset": "default"
}
]
}
cmake_minimum_required(VERSION 3.23)
project(test)
enable_testing()
add_test(NAME check COMMAND true)
$ cmake --preset=default -B override
$ ctest --preset=default --test-dir override
Internal ctest changing into directory: /usr/local/google/home/reinking/test/override
Test project /usr/local/google/home/reinking/test/build
No tests were found!!!