[Mlir-commits] [mlir] Fixed nanobind target used in target_compile_options in AddMLIRPython.cmake (PR #121477)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Jan 2 05:12:21 PST 2025


https://github.com/vfdev-5 updated https://github.com/llvm/llvm-project/pull/121477

>From b43a0cfaab27dd2a82a04d792f99f42278fd7f13 Mon Sep 17 00:00:00 2001
From: vfdev-5 <vfdev.5 at gmail.com>
Date: Thu, 2 Jan 2025 13:53:58 +0100
Subject: [PATCH] Fixed nanobind target used in target_compile_options in
 mlir/cmake/modules/AddMLIRPython.cmake

---
 mlir/cmake/modules/AddMLIRPython.cmake | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index 9d4e06c7909c81..5cf3303203950f 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -673,7 +673,25 @@ function(add_mlir_python_extension libname extname)
 
     if (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL)
       # Avoids warnings from upstream nanobind.
-      target_compile_options(nanobind-static
+      set(nanobind_target "nanobind-static")
+      if (NOT TARGET ${nanobind_target})
+        # Get correct nanobind target name: nanobind-static-ft or something else
+        # It is set by nanobind_add_module function according to the passed options
+        get_property(all_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS)
+
+        # Iterate over the list of targets
+        foreach(target ${all_targets})
+          # Check if the target name matches the given string
+          if("${target}" MATCHES "nanobind-")
+            set(nanobind_target "${target}")
+          endif()
+        endforeach()
+
+        if (NOT TARGET ${nanobind_target})
+          message(FATAL_ERROR "Could not find nanobind target to set compile options to")
+        endif()
+      endif()
+      target_compile_options(${nanobind_target}
         PRIVATE
           -Wno-cast-qual
           -Wno-zero-length-array



More information about the Mlir-commits mailing list