[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:54 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: vfdev (vfdev-5)
<details>
<summary>Changes</summary>
Description:
`target_compile_options(nanobind-static ...)` is only works for default configuration of nanobind module `nanobind_add_module(...)` and the target name is different for other passed options like FREE_THREADED: `nanobind-static-ft`.
In this PR we first try the default name and if not found we search among all targets of the current cmake source directory (e.g. `llvm-project/mlir/python`).
Related to https://github.com/llvm/llvm-project/pull/107103
cc @<!-- -->jpienaar
---
Full diff: https://github.com/llvm/llvm-project/pull/121477.diff
1 Files Affected:
- (modified) mlir/cmake/modules/AddMLIRPython.cmake (+19-1)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/121477
More information about the Mlir-commits
mailing list