Skip to content

use NAME and COMMAND tags in add_test function

If CMAKE_RUNTIME_OUTPUT_DIRECTORY variable is specified, the ctest can't find executables for tests.

When add_test is used without NAME and COMMAND options, ctest tries to run tests with exact commands specified in add_test function. If CMAKE_RUNTIME_OUTPUT_DIRECTORY is specified, cmake moves binaries to that folder, 'exact command' from add_test is relevant any more and ctest is unable to find the binaries and fails (see documentation of the add_test function at the bottom of the page). To fix this issue just use NAME and COMMAND options.

Steps to reproduce:

mkdir build
cd build
cmake -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=bin ..
make
ctest --verbose

This variable is usually used in big projects which set many options manually, and they usually set CMAKE_RUNTIME_OUTPUT_DIRECTORY variable to make it easier to find all output binaries. Some package managers that use cmake as underlying build tool also specifies this variable (for example, conan).

Edited by Andrey Potapov

Merge request reports