CMake exclude tests in subdirectories

PovilasB picture PovilasB · May 17, 2014 · Viewed 7.2k times · Source

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?

Answer

Fraser picture Fraser · May 17, 2014

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