Issue
With CMake I try to execute a simple test using CTest. I have this configuration all in one directory (${CMAKE_SOURCE_DIR}):
~$ cat hello.cpp
#include <iostream>
int main() {
std::cout << "hello world\n";
return(0);
}
~$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.18)
project(TEST_CTEST)
enable_testing()
add_executable(test_ctest hello.cpp)
add_test(my_test ./build/test_ctest)
Then I execute:
~$ rm -rf Testing/ build/
~$ cmake -S . -B build
~$ cmake --build build
~$ ./build/test_ctest
hello world
~$ ctest
*********************************
No test configuration file found!
*********************************
Usage
ctest [options]
The only hint I have found in other Q&A is to place enable_testing()
into the root CMakeLists.txt
. I feel like I just missed a little thing, but I can't find what.
How do I run a test with CTest?
Solution
The macro enable_testing()
creates ctest configuration file in the build directory. For find this file, ctest
needs to be run from that build directory.
Running ctest
from the source directory has no sense, as it doesn't see results of CMake (unless you do in-source builds).
Answered By - Tsyvarev Answer Checked By - Robin (WPSolving Admin)