Skip to content

Commit c78dfb6

Browse files
authored
MSVC but not Clang: /MP (#2824)
On Windows, clang-cl does not understand /MP. ``` clang-cl: warning: argument unused during compilation: '/MP' [-Wunused-command-line-argument] ``` with Clang 10.0.0
1 parent e791ec4 commit c78dfb6

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

tools/pybind11Common.cmake

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,28 +115,32 @@ endif()
115115

116116
add_library(pybind11::windows_extras IMPORTED INTERFACE ${optional_global})
117117

118-
if(MSVC)
119-
# /MP enables multithreaded builds (relevant when there are many files), /bigobj is
120-
# needed for bigger binding projects due to the limit to 64k addressable sections
118+
if(MSVC) # That's also clang-cl
119+
# /bigobj is needed for bigger binding projects due to the limit to 64k
120+
# addressable sections
121121
set_property(
122122
TARGET pybind11::windows_extras
123123
APPEND
124124
PROPERTY INTERFACE_COMPILE_OPTIONS /bigobj)
125125

126-
if(CMAKE_VERSION VERSION_LESS 3.11)
127-
set_property(
128-
TARGET pybind11::windows_extras
129-
APPEND
130-
PROPERTY INTERFACE_COMPILE_OPTIONS $<$<NOT:$<CONFIG:Debug>>:/MP>)
131-
else()
132-
# Only set these options for C++ files. This is important so that, for
133-
# instance, projects that include other types of source files like CUDA
134-
# .cu files don't get these options propagated to nvcc since that would
135-
# cause the build to fail.
136-
set_property(
137-
TARGET pybind11::windows_extras
138-
APPEND
139-
PROPERTY INTERFACE_COMPILE_OPTIONS $<$<NOT:$<CONFIG:Debug>>:$<$<COMPILE_LANGUAGE:CXX>:/MP>>)
126+
# /MP enables multithreaded builds (relevant when there are many files) for MSVC
127+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # no Clang no Intel
128+
if(CMAKE_VERSION VERSION_LESS 3.11)
129+
set_property(
130+
TARGET pybind11::windows_extras
131+
APPEND
132+
PROPERTY INTERFACE_COMPILE_OPTIONS $<$<NOT:$<CONFIG:Debug>>:/MP>)
133+
else()
134+
# Only set these options for C++ files. This is important so that, for
135+
# instance, projects that include other types of source files like CUDA
136+
# .cu files don't get these options propagated to nvcc since that would
137+
# cause the build to fail.
138+
set_property(
139+
TARGET pybind11::windows_extras
140+
APPEND
141+
PROPERTY INTERFACE_COMPILE_OPTIONS
142+
$<$<NOT:$<CONFIG:Debug>>:$<$<COMPILE_LANGUAGE:CXX>:/MP>>)
143+
endif()
140144
endif()
141145
endif()
142146

0 commit comments

Comments
 (0)