From b43a0cfaab27dd2a82a04d792f99f42278fd7f13 Mon Sep 17 00:00:00 2001 From: vfdev-5 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 9d4e06c7909c8..5cf3303203950 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