Skip to content

Commit 3adb0ac

Browse files
committed
[mlir][py] Fix python modules build with clang-cl due to requiring exceptions
The generator expression previously used to enable exceptions would not work since the compiler id of clang-cl is Clang, even if used via clang-cl. The patch fixes that by replacing the generator expression with simple logic, setting the right compiler flags for all MSVC like compilers (including clang-cl) and all GCC like compilers. Differential Revision: https://reviews.llvm.org/D141155
1 parent e22ff52 commit 3adb0ac

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

mlir/cmake/modules/AddMLIRPython.cmake

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -607,15 +607,13 @@ function(add_mlir_python_extension libname extname)
607607

608608
# The extension itself must be compiled with RTTI and exceptions enabled.
609609
# Also, some warning classes triggered by pybind11 are disabled.
610-
target_compile_options(${libname} PRIVATE
611-
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
612-
# Enable RTTI and exceptions.
613-
-frtti -fexceptions
614-
>
615-
$<$<CXX_COMPILER_ID:MSVC>:
616-
# Enable RTTI and exceptions.
617-
/EHsc /GR>
618-
)
610+
set(eh_rtti_enable)
611+
if (MSVC)
612+
set(eh_rtti_enable /EHsc /GR)
613+
elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE)
614+
set(eh_rtti_enable -frtti -fexceptions)
615+
endif ()
616+
target_compile_options(${libname} PRIVATE ${eh_rtti_enable})
619617

620618
# Configure the output to match python expectations.
621619
set_target_properties(

0 commit comments

Comments
 (0)