My project uses CMake as its build system, and I want it to execute my Boost.Test test cases.
How can I achieve that? In Boost.Build, I could do it as follows:
import testing ;
use-project /my_lib : ../src ;
unit-test my_test
: my_test.cpp
/my_lib
boost_unit_test_framework
;
lib boost_unit_test_framework ;
CMake itself is just a build system; CTest is a just test runner that is integrated with CMake. Neither is a unit test framework; that job can be done by Boost.Test or googletest.
To use a Boost.Test-based unit test program in a CMake project, you'd first have CMake build and link your unit test binary, using add_executable
and target_link_libraries
in your CMakeLists.txt
script. Then, you can add the unit test binary to the list of tests for CTest to run with enable_testing
and add_test
.
If you want to get really fancy, you can look through the CMake documentation for how to have CMake search through all your source files to find and build unit tests automatically, but first things first...