If I have a look at Eigen’s library CMakeLists.txt, I see their tests are not guarded by something like EIGEN_BUILD_TESTS, but just by BUILD_TESTING:
option(BUILD_TESTING "Enable creation of Eigen tests." ON)
if(BUILD_TESTING)
include(EigenConfigureTesting)
if(EIGEN_LEAVE_TEST_IN_ALL_TARGET)
add_subdirectory(test) # can't do EXCLUDE_FROM_ALL here, breaks CTest
else()
add_subdirectory(test EXCLUDE_FROM_ALL)
endif()
add_subdirectory(failtest)
endif()
So, when I run ctest I see all the Eigen tests are added.
Is there a way to avoid tests from suprojects, in this case Eigen, being added to my project’s list of tests?
You could set (BUILD_TESTING OFF) before FetchContent_MakeAvailable (Eigen3), but IMHO the best solution is to name all of your project’s test with a consistent prefix so that you can run only your tests with CTest’s name regex feature.
Just as a side note, and for this particular case of Eigen, I’ve talked with the maintainers of the lib and they have it working fine in master via two different things:
They only enable BUILD_TESTING if PROJECT_IS_TOP_LEVEL.