Prevent CMake from attempting to configure test executables without Catch2 #1380
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, the CMake would check whether STDEXEC_BUILD_TESTS was set when determining whether CPM should add Catch2, but it would then check BUILD_TESTING when determining whether to add the CMake for the test subdirectory. If STDEXEC_BUILD_TESTS was enabled, this would work, because the CMake would enable BUILD_TESTING whenever STDEXEC_BUILD_TESTS was enabled. However, if BUILD_TESTING was enabled but STDEXEC_BUILD_TESTS was disabled, then the CMake would attempt to configure the tests without having added Catch2, causing the build configuration to fail.
This was a particular problem when adding stdexec as a submodule of another project, since if that project had an include(CTest) command invocation before it added stdexec, and it did not explicitly enable STDEXEC_BUILD_TESTS, the build configuration would fail, since STDEXEC_BUILD_TESTS is disabled by default when stdexec is a submodule, and include(CTest) automatically sets BUILD_TESTING.
This commit addresses the issue by setting BUILD_TESTING to whatever STDEXEC_BUILD_TESTS was set to, and then relying on BUILD_TESTING to decide both whether to add Catch2 and whether to configure the test executables. It also adds a check for BUILD_TESTING when determining how to set the default for STDEXEC_BUILD_TESTS when the user doesn't configure it. The outcome is that, if the user explicitly enables or disables STDEXEC_BUILD_TESTS, then the CMake will use it to override the preexisting BUILD_TESTING setting; but otherwise, the CMake will enable tests only if BUILD_TESTING is set or if stdexec is not a submodule.