@@ -30,6 +30,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../tools")
3030
3131option (PYBIND11_WERROR "Report all warnings as errors" OFF )
3232option (DOWNLOAD_EIGEN "Download EIGEN (requires CMake 3.11+)" OFF )
33+ option (PYBIND11_CUDA_TESTS "Enable building CUDA tests (requires CMake 3.12+)" OFF )
3334set (PYBIND11_TEST_OVERRIDE
3435 ""
3536 CACHE STRING "Tests from ;-separated list of *.cpp files will be built instead of all tests" )
@@ -49,6 +50,14 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
4950 "RelWithDebInfo" )
5051endif ()
5152
53+ if (PYBIND11_CUDA_TESTS)
54+ enable_language (CUDA)
55+ if (DEFINED CMAKE_CXX_STANDARD)
56+ set (CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD} )
57+ endif ()
58+ set (CMAKE_CUDA_STANDARD_REQUIRED ON )
59+ endif ()
60+
5261# Full set of test files (you can override these; see below)
5362set (PYBIND11_TEST_FILES
5463 test_async.cpp
@@ -104,6 +113,16 @@ if((PYBIND11_TEST_FILES_ASYNC_I GREATER -1) AND (PYTHON_VERSION VERSION_LESS 3.5
104113 list (REMOVE_AT PYBIND11_TEST_FILES ${PYBIND11_TEST_FILES_ASYNC_I} )
105114endif ()
106115
116+ # Skip tests for CUDA check:
117+ # /pybind11/tests/test_constants_and_functions.cpp(125):
118+ # error: incompatible exception specifications
119+ list (FIND PYBIND11_TEST_FILES test_constants_and_functions.cpp PYBIND11_TEST_FILES_CAF_I)
120+ if ((PYBIND11_TEST_FILES_CAF_I GREATER -1) AND PYBIND11_CUDA_TESTS)
121+ message (
122+ STATUS "Skipping test_constants_and_functions due to incompatible exception specifications" )
123+ list (REMOVE_AT PYBIND11_TEST_FILES ${PYBIND11_TEST_FILES_CAF_I} )
124+ endif ()
125+
107126string (REPLACE ".cpp" ".py" PYBIND11_PYTEST_FILES "${PYBIND11_TEST_FILES} " )
108127
109128# Contains the set of test files that require pybind11_cross_module_tests to be
@@ -195,14 +214,16 @@ endif()
195214function (pybind11_enable_warnings target_name)
196215 if (MSVC )
197216 target_compile_options (${target_name} PRIVATE /W4)
198- elseif (CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Intel|Clang)" )
217+ elseif (CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Intel|Clang)" AND NOT PYBIND11_CUDA_TESTS )
199218 target_compile_options (${target_name} PRIVATE -Wall -Wextra -Wconversion -Wcast-qual
200219 -Wdeprecated)
201220 endif ()
202221
203222 if (PYBIND11_WERROR)
204223 if (MSVC )
205224 target_compile_options (${target_name} PRIVATE /WX)
225+ elseif (PYBIND11_CUDA_TESTS)
226+ target_compile_options (${target_name} PRIVATE "SHELL:-Werror all-warnings" )
206227 elseif (CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Intel|Clang)" )
207228 target_compile_options (${target_name} PRIVATE -Werror)
208229 endif ()
@@ -239,12 +260,22 @@ foreach(t ${PYBIND11_CROSS_MODULE_GIL_TESTS})
239260 endif ()
240261endforeach ()
241262
263+ # Support CUDA testing by forcing the target file to compile with NVCC
264+ if (PYBIND11_CUDA_TESTS)
265+ set_property (SOURCE ${PYBIND11_TEST_FILES} PROPERTY LANGUAGE CUDA)
266+ endif ()
267+
242268foreach (target ${test_targets} )
243269 set (test_files ${PYBIND11_TEST_FILES} )
244270 if (NOT "${target} " STREQUAL "pybind11_tests" )
245271 set (test_files "" )
246272 endif ()
247273
274+ # Support CUDA testing by forcing the target file to compile with NVCC
275+ if (PYBIND11_CUDA_TESTS)
276+ set_property (SOURCE ${target} .cpp PROPERTY LANGUAGE CUDA)
277+ endif ()
278+
248279 # Create the binding library
249280 pybind11_add_module(${target} THIN_LTO ${target} .cpp ${test_files} ${PYBIND11_HEADERS} )
250281 pybind11_enable_warnings(${target} )
@@ -354,8 +385,10 @@ add_custom_command(
354385 $<TARGET_FILE:pybind11_tests>
355386 ${CMAKE_CURRENT_BINARY_DIR} /sosize-$<TARGET_FILE_NAME:pybind11_tests>.txt)
356387
357- # Test embedding the interpreter. Provides the `cpptest` target.
358- add_subdirectory (test_embed)
388+ if (NOT PYBIND11_CUDA_TESTS)
389+ # Test embedding the interpreter. Provides the `cpptest` target.
390+ add_subdirectory (test_embed)
359391
360- # Test CMake build using functions and targets from subdirectory or installed location
361- add_subdirectory (test_cmake_build)
392+ # Test CMake build using functions and targets from subdirectory or installed location
393+ add_subdirectory (test_cmake_build)
394+ endif ()
0 commit comments