My cmake project has the following tree structure:
├── CMakeLists.txt
├── basis
├── build
├── deps
├── study
where /deps contains all 3rd-party dependencies, /basis and /study directories contain routines I wrote.
In my main CMakeLists.txt file, I have the following code to enable CxxTest
cmake_minimum_required(VERSION 3.14)
project(study_cmake)
set( CMAKE_BUILD_TYPE "Debug" )
add_subdirectory(deps/eigen)
set(CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/deps/cxxtest/)
find_package(CxxTest REQUIRED)
if(CXXTEST_FOUND)
include_directories(${CXXTEST_INCLUDE_DIR})
message( 'CXXTEST_INCLUDE_DIR:' ${CXXTEST_INCLUDE_DIR} )
enable_testing()
endif()
add_subdirectory(study)
add_subdirectory(basis)
In /basis/CMakeLists.txt, I have
project(basis)
add_library(
basis
include/bernstein.h
src/bernstein.cpp
)
CXXTEST_ADD_TEST(test_bernstein test_bernstein.cc ${CMAKE_CURRENT_SOURCE_DIR}/test/test_bernstein.h
In /study/CMakeLists.txt, I have similar things as in /basis/CMakeLists.txt. After running cmake .. and make in the build directory, I can run ctest in build/basis/, build/study/to run unit tests defined in these two subdirectories separately. But I would like to have a way to run all unit tests defined in these two subdirectories, so I tried run ctest in /build/. Unfortunately, this command seems also to run all unit tests defined in 3d-party dependencies in /deps/. How can we force ctest only run all unit tests defined in build/basis/ and build/study/ by myself?
The first thing I'd try is
ctest's regex selectors. Fromctest --helpIf you wanted to group a bunch of tests together you could set labels on them.
Note that
set_tests_properties()only defines properties on tests created withadd_test()(whichCXXTEST_ADD_TESTdoes behind the scenes.) Then you could runctest -L funto run only the "fun" tests.