cmakectest

CMake exclude tests in subdirectories


I have a c++ project which includes libevent library. Project structure:

.
|_ CMakeLists.txt
|_ Makefile
|_ src
| |_ my_lib.cpp
|_ test
| |_ my_lib_test.cpp
|_ lib
  |_ libevent
    |_ CMakeLists.txt
    |_ ...

When I build and run my tests, libevent tests are also executed. How can I exclude them and run only my own tests?


Solution

  • Looking at the available options in libevent's CMakeLists.txt file, it appears that you can disable these pretty easily by setting EVENT__DISABLE_TESTS to ON.

    You can either do this in your own CMakeLists.txt before libevent is included:

    set(EVENT__DISABLE_TESTS ON)
    ...
    add_subdirectory(lib/libevent)
    

    or when you invoke CMake on the command line:

    cmake . -DEVENT__DISABLE_TESTS=ON