Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent CMake from attempting to configure test executables without Catch2 #1380

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

ednolan
Copy link
Contributor

@ednolan ednolan commented Jul 22, 2024

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.

Copy link

copy-pr-bot bot commented Jul 22, 2024

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

…atch2

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.
@ednolan ednolan force-pushed the enolan_submoduletestcmake1 branch from f626596 to 7aec9ab Compare July 22, 2024 02:52
@ednolan
Copy link
Contributor Author

ednolan commented Jul 22, 2024

This addresses issue 1371: #1371 (comment)

@ericniebler
Copy link
Collaborator

/ok to test

@ericniebler ericniebler merged commit ee0a962 into NVIDIA:main Jul 22, 2024
18 checks passed
@ericniebler
Copy link
Collaborator

Thanks!

ednolan added a commit to bemanproject/utf_view that referenced this pull request Nov 13, 2024
This commit adds a UTF_VIEW_BUILD_TESTS CMake option. The logic around
its use is:

- If the user has explicitly set UTF_VIEW_BUILD_TESTS, BUILD_TESTING
    is set to that value
- Otherwise, if BUILD_TESTING was already set to ON, then it continues
    to be set to ON
- Otherwise, if this is the top-level CMake project and not a
    dependency of another project, BUILD_TESTING is set to ON
- Otherwise, BUILD_TESTING is set to OFF

Using BUILD_TESTING to control whether tests are enabled is
recommended by CMake in its documentation here:
https://cmake.org/cmake/help/latest/module/CTest.html

This logic is based on a similar option implemented in NVIDIA/stdexec.
My commit implementing this logic can be found here:

NVIDIA/stdexec@ee0a962

Additional reasoning can be found here:

NVIDIA/stdexec#1380 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants