I have a very large project with modules that each have their own repository. The projects are using FetchContent like this:
FetchContent_Declare(
ModuleA
GIT_REPOSITORY git@URL:ModuleA.git
GIT_TAG HEAD
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(ModuleA)
The main CMake configuration as well as the configuration of the modules are using this way to switch on/off the creation of unit tests.
option(BUILD_TESTS "Build unit tests" ON)
if(BUILD_TESTS)
enable_testing()
...
endif(BUILD_TESTS)
When creating the project like this: cmake -G "Unix Makefiles" -DBUILD_TESTS=OFF ... PROJECT_PATH
, the tests for the main project are deactivated as expected, but the tests for all the modules are still created.
How can I configure my project in a way, that calling cmake with a command line option will switch of the creation of the unit tests for the modules as well?