Skip to content

Commit cd91d0f

Browse files
authored
[mlir][py] Don't use a CMake iteration to find nanobind target to suppress warnings (NFC) (#143863)
Following approach suggested by @hpkfft.
1 parent cccb82e commit cd91d0f

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

mlir/cmake/modules/AddMLIRPython.cmake

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -676,33 +676,28 @@ function(add_mlir_python_extension libname extname)
676676
# Avoid some warnings from upstream nanobind.
677677
# If a superproject set MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES, let
678678
# the super project handle compile options as it wishes.
679-
set(nanobind_target "nanobind-static")
680-
if (NOT TARGET ${nanobind_target})
681-
# Get correct nanobind target name: nanobind-static-ft or something else
682-
# It is set by nanobind_add_module function according to the passed options
683-
get_property(all_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS)
684-
685-
# Iterate over the list of targets
686-
foreach(target ${all_targets})
687-
# Check if the target name matches the given string
688-
if("${target}" MATCHES "nanobind-")
689-
set(nanobind_target "${target}")
690-
endif()
691-
endforeach()
692-
693-
if (NOT TARGET ${nanobind_target})
694-
message(FATAL_ERROR "Could not find nanobind target to set compile options to")
695-
endif()
696-
endif()
697-
target_compile_options(${nanobind_target}
698-
PRIVATE
699-
-Wno-cast-qual
700-
-Wno-zero-length-array
701-
-Wno-nested-anon-types
702-
-Wno-c++98-compat-extra-semi
703-
-Wno-covered-switch-default
704-
${eh_rtti_enable}
705-
)
679+
get_property(NB_LIBRARY_TARGET_NAME TARGET ${libname} PROPERTY LINK_LIBRARIES)
680+
target_compile_options(${NB_LIBRARY_TARGET_NAME}
681+
PRIVATE
682+
-Wall -Wextra -Wpedantic
683+
-Wno-c++98-compat-extra-semi
684+
-Wno-cast-qual
685+
-Wno-covered-switch-default
686+
-Wno-nested-anon-types
687+
-Wno-unused-parameter
688+
-Wno-zero-length-array
689+
${eh_rtti_enable})
690+
691+
target_compile_options(${libname}
692+
PRIVATE
693+
-Wall -Wextra -Wpedantic
694+
-Wno-c++98-compat-extra-semi
695+
-Wno-cast-qual
696+
-Wno-covered-switch-default
697+
-Wno-nested-anon-types
698+
-Wno-unused-parameter
699+
-Wno-zero-length-array
700+
${eh_rtti_enable})
706701
endif()
707702

708703
if(APPLE)

0 commit comments

Comments
 (0)