From 3adb0ac183242cd18931dc0dc011385403727f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20B=C3=B6ck?= Date: Fri, 6 Jan 2023 22:48:02 +0100 Subject: [PATCH] [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 --- mlir/cmake/modules/AddMLIRPython.cmake | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake index 706413776b9e..9227c5186d73 100644 --- a/mlir/cmake/modules/AddMLIRPython.cmake +++ b/mlir/cmake/modules/AddMLIRPython.cmake @@ -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 - $<$,$,$>: - # Enable RTTI and exceptions. - -frtti -fexceptions - > - $<$: - # 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(