diff --git a/CMakeLists.txt b/CMakeLists.txt index 64d703c89..433129df2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,21 +79,32 @@ rapids_cmake_build_type(Release) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") # Don't build tests if configuring stdexec as a submodule of another -# CMake project, unless they explicitly set STDEXEC_BUILD_TESTS=TRUE -if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) +# CMake project, unless they explicitly set STDEXEC_BUILD_TESTS=TRUE, +# or they enabled CTest's BUILD_TESTING option +if ((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) OR BUILD_TESTING) set(STDEXEC_BUILD_TESTS_DEFAULT ON) else() set(STDEXEC_BUILD_TESTS_DEFAULT OFF) endif() option(STDEXEC_BUILD_TESTS "Build stdexec tests" ${STDEXEC_BUILD_TESTS_DEFAULT}) +# STDEXEC_BUILD_TESTS is used solely to configure CTest's BUILD_TESTING option, +# which is CMake's preferred option for enabling testing when using CTest. +set(BUILD_TESTING ${STDEXEC_BUILD_TESTS}) + +if (BUILD_TESTING) + # CTest automatically calls enable_testing() if BUILD_TESTING is ON + # https://cmake.org/cmake/help/latest/module/CTest.html#module:CTest + include(CTest) +endif() + ############################################################################## # - Dependencies ------------------------------------------------------------- # Initialize CPM rapids_cpm_init(OVERRIDE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/versions.json) -if (STDEXEC_BUILD_TESTS) +if (BUILD_TESTING) # Add Catch2 set(Catch2_VERSION 2.13.6) # Always download it, don't attempt to do `find_package(Catch2)` first @@ -389,14 +400,6 @@ option(STDEXEC_ENABLE_IO_URING_TESTS "Enable io_uring tests" ${STDEXEC_FOUND_IO_ option(STDEXEC_BUILD_DOCS "Build stdexec documentation" OFF) option(STDEXEC_BUILD_EXAMPLES "Build stdexec examples" ON) -if (STDEXEC_BUILD_TESTS) - set(BUILD_TESTING ON) - - # CTest automatically calls enable_testing() if BUILD_TESTING is ON - # https://cmake.org/cmake/help/latest/module/CTest.html#module:CTest - include(CTest) -endif() - # Configure documentation if(STDEXEC_BUILD_DOCS) add_subdirectory(docs)