From c78dfb69f23639148870bf7d97587b5a7e7053ab Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Mon, 8 Feb 2021 12:40:04 -0800 Subject: [PATCH] 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 --- tools/pybind11Common.cmake | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/tools/pybind11Common.cmake b/tools/pybind11Common.cmake index 3c05c682d..57e42536e 100644 --- a/tools/pybind11Common.cmake +++ b/tools/pybind11Common.cmake @@ -115,28 +115,32 @@ endif() add_library(pybind11::windows_extras IMPORTED INTERFACE ${optional_global}) -if(MSVC) - # /MP enables multithreaded builds (relevant when there are many files), /bigobj is - # needed for bigger binding projects due to the limit to 64k addressable sections +if(MSVC) # That's also clang-cl + # /bigobj is needed for bigger binding projects due to the limit to 64k + # addressable sections set_property( TARGET pybind11::windows_extras APPEND PROPERTY INTERFACE_COMPILE_OPTIONS /bigobj) - if(CMAKE_VERSION VERSION_LESS 3.11) - set_property( - TARGET pybind11::windows_extras - APPEND - PROPERTY INTERFACE_COMPILE_OPTIONS $<$>:/MP>) - else() - # Only set these options for C++ files. This is important so that, for - # instance, projects that include other types of source files like CUDA - # .cu files don't get these options propagated to nvcc since that would - # cause the build to fail. - set_property( - TARGET pybind11::windows_extras - APPEND - PROPERTY INTERFACE_COMPILE_OPTIONS $<$>:$<$:/MP>>) + # /MP enables multithreaded builds (relevant when there are many files) for MSVC + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # no Clang no Intel + if(CMAKE_VERSION VERSION_LESS 3.11) + set_property( + TARGET pybind11::windows_extras + APPEND + PROPERTY INTERFACE_COMPILE_OPTIONS $<$>:/MP>) + else() + # Only set these options for C++ files. This is important so that, for + # instance, projects that include other types of source files like CUDA + # .cu files don't get these options propagated to nvcc since that would + # cause the build to fail. + set_property( + TARGET pybind11::windows_extras + APPEND + PROPERTY INTERFACE_COMPILE_OPTIONS + $<$>:$<$:/MP>>) + endif() endif() endif()