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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Feb 2 21:51:18 PST 2025


================
@@ -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()
----------------
hpkfft wrote:

Does the following work instead of iterating over the list of all targets:
```
get_property(nanobind_target TARGET ${libname} PROPERTY LINK_LIBRARIES)
```

https://github.com/llvm/llvm-project/pull/121477


More information about the Mlir-commits mailing list