Those of you familiar with the GNU Autotools probably know that the
all target in a Makefile generated by autoconf/automake does not cause
a (re)build of your test programs (assuming you've listed them as
check_PROGRAMS). This is IMHO a very nice feature, because the normal
build is not bogged down by the compilation of many test programs, or
worse, comes to a grinding halt due to a compilation error in one of the
test programs you didn't have time to fix yet. When the time has come to
run your test suite, you simply type make check and your test programs
will be (re)build and run.
This feature can be emulated in CMake.
Define a custom target
First you need to define a custom target check. You only need to do
this once, so doing this in your toplevel CMakeLists.txt file is
probably a good idea.
The option EXCLUDE_FROM_ALL is essential here; it causes to
be ignored when the all target is built.
If you organize all your test programs in one directory, you can use the
EXCLUDE_FROM_ALL option with the add_subdirectory command. That way,
you don't need to specify this option with every add_executable
This page was initially populated by conversion from its original location in another wiki.