Skip to content

Commit 9343e68

Browse files
daviskingwjakob
authored andcommitted
Fix cmake scripts so projects using CUDA .cu files build correctly. (#1441)
1 parent c8e9f3c commit 9343e68

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tools/pybind11Tools.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ function(pybind11_add_module target_name)
156156
# namespace; also turning it on for a pybind module compilation here avoids
157157
# potential warnings or issues from having mixed hidden/non-hidden types.
158158
set_target_properties(${target_name} PROPERTIES CXX_VISIBILITY_PRESET "hidden")
159+
set_target_properties(${target_name} PROPERTIES CUDA_VISIBILITY_PRESET "hidden")
159160

160161
if(WIN32 OR CYGWIN)
161162
# Link against the Python shared library on Windows
@@ -208,6 +209,15 @@ function(pybind11_add_module target_name)
208209
if(MSVC)
209210
# /MP enables multithreaded builds (relevant when there are many files), /bigobj is
210211
# needed for bigger binding projects due to the limit to 64k addressable sections
211-
target_compile_options(${target_name} PRIVATE /MP /bigobj)
212+
set(msvc_extra_options /MP /bigobj)
213+
if(CMAKE_VERSION VERSION_LESS 3.11)
214+
target_compile_options(${target_name} PRIVATE ${msvc_extra_options})
215+
else()
216+
# Only set these options for C++ files. This is important so that, for
217+
# instance, projects that include other types of source files like CUDA
218+
# .cu files don't get these options propagated to nvcc since that would
219+
# cause the build to fail.
220+
target_compile_options(${target_name} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${msvc_extra_options}>)
221+
endif()
212222
endif()
213223
endfunction()

0 commit comments

Comments
 (0)