Is there a best practice with respect to BUILD_TESTING for projects that want to support being used as git submodules or FetchContent? The root issue I’m having is that a project currently uses BUILD_TESTING directly. This works fine when building it as a top level project, but there are issues when it is used as a subproject (by way of a git submodule or FetchContent).
This is currently being discussed at cmake: Controlling Abseil's tests with BUILD_TESTING is inconvenient · Issue #1056 · abseil/abseil-cpp · GitHub.
In researching this I found Craig Scott’s post How to use FetchContent correctly for building external dependencies - #2 by craig.scott where he says:
Dealing with tests is harder. If you use the method above to handle the install problems, then you will avoid the need for
EXCLUDE_FROM_ALLand then you should be able to avoid the dependency problems you ran into. The dependency’s tests will still show up and be included in the main projects tests, but that is hard to avoid without the dependency providing some sort of switch to turn off adding tests. A well-structured project should ideally provide a project-specific CMake variable that can be passed down to turn tests on or off, and it should default to true if the dependency is being built on its own and false if it is not the top level project.
Emphasis mine. Is there a good example of an Open Source project I can look at that does this well?