ctest: --test-dir doesn't override binaryDir in test presets
Copying from the following Discourse discussion: https://discourse.cmake.org/t/ctest-preset-doesnt-appear-to-allow-for-out-of-tree-builds/6275
The key issue is this: --test-dir
does not work with ctest --preset
. Here's an example.
Suppose I have this CMakePresets.json
:
{
"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"
}
]
}
Alongside a very basic CMakeLists.txt
:
cmake_minimum_required(VERSION 3.23)
project(test)
enable_testing()
add_test(NAME check COMMAND true)
Now, if I run the following commands:
$ 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!!!
It seems that --test-dir
had no effect, but it should have! I was able to override binaryDir
for the configure step, but not for testing.
Edited by Brad King