I would like to use the test framework Catch2 in a monorepo in which there will be many components, each with their own tests. I'd like to use CMake to define all build targets.
Catch2 provides a simple means to generate a common main()
function that will run all tests linked into the application. The source file (which I am calling test_main.cpp
) is just these two lines:
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
I'd like to have just one copy of test_main.cpp
in my source tree, and refer to it from each component directory that has tests (which will end up being on the order of hundreds of directories).
I can see how to set up CMake to work if I duplicated the test_main.cpp
so that a redundant copy existed in each directory with tests, but I haven't figured out how to have just one copy. Is there a simple trick I've overlooked?