Struggling to use VSCode with CMakePresets.json to invoke a test

Oliver Schneider
Tue, 04 Mar 2025 15:56:07 +0000
Usage

Hi,

I would like to use the built-in facilities of VSCode to invoke ctest. However, I am unable to tell it to step into a given --test-dir via CMakePresets.json.

And so I get one of two symptoms:

1. if I call enable_testing() in the top-level CMakeLists.txt it attempts to run tests, including some which I don’t want it to run (defined by dependencies included with add_subdirectory()); but more importantly which cannot run

2. if I call enable_testing() where the test is defined (a subsubdirectory called unit-test) that works when invoked manually as in this case I can pass --test-dir, but not via CMakePresets.json which seems to go by the assumption that the tests are to be invoked in the directory of the top-level CMakeLists.txt … additionally because the respective file gets generated at the wrong directory level, I get a complaint about DartConfiguration.tcl missing, which doesn’t seem to be fatal, though

How can I teach VSCode through CMakePresets.json where to point ctest upon invocation, without hardcoding the --test-dir option plus its argument in the global VSCode settings?

Thanks in advance for any insights.

PS: the Linux distro is Mint, based upon Ubuntu 24.04 LTS, in case it matters. CMake is the latest from the APT repo of Kitware (3.31).

4 posts - 3 participants