[mlir][py] Fix python modules build with clang-cl due to requiring exceptions
authorMarkus Böck <markus.boeck02@gmail.com>
Fri, 6 Jan 2023 21:48:02 +0000 (22:48 +0100)
committerMarkus Böck <markus.boeck02@gmail.com>
Fri, 6 Jan 2023 21:48:14 +0000 (22:48 +0100)
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

mlir/cmake/modules/AddMLIRPython.cmake

index 7064137..9227c51 100644 (file)
@@ -607,15 +607,13 @@ function(add_mlir_python_extension libname extname)
 
   # The extension itself must be compiled with RTTI and exceptions enabled.
   # Also, some warning classes triggered by pybind11 are disabled.
-  target_compile_options(${libname} PRIVATE
-    $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-      # Enable RTTI and exceptions.
-      -frtti -fexceptions
-    >
-    $<$<CXX_COMPILER_ID:MSVC>:
-      # Enable RTTI and exceptions.
-      /EHsc /GR>
-  )
+  set(eh_rtti_enable)
+  if (MSVC)
+    set(eh_rtti_enable /EHsc /GR)
+  elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE)
+    set(eh_rtti_enable -frtti -fexceptions)
+  endif ()
+  target_compile_options(${libname} PRIVATE ${eh_rtti_enable})
 
   # Configure the output to match python expectations.
   set_target_properties(