Skip to content

Commit

Permalink
Merge pull request #1380 from ednolan/enolan_submoduletestcmake1
Browse files Browse the repository at this point in the history
Prevent CMake from attempting to configure test executables without Catch2
  • Loading branch information
ericniebler authored Jul 22, 2024
2 parents bfc2610 + 7aec9ab commit ee0a962
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ee0a962

Please sign in to comment.