[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
Mon Jan 6 14:13:09 PST 2025
vfdev-5 wrote:
> I don't know cmake at all and find it incomprehensible, but could we upstream a change to their cmake macros to silence the warnings?
We maybe can try to upstream an optional kwarg which defines nanobind compile optoins as following:
```cmake
cmake_minimum_required(VERSION 3.28)
project("test")
function(nanobind_add_module2 name)
cmake_parse_arguments(PARSE_ARGV 1 ARG
"STABLE_ABI;FREE_THREADED;NB_STATIC;NB_SHARED;PROTECT_STACK;LTO;NOMINSIZE;NOSTRIP;MUSL_DYNAMIC_LIBCPP"
"NB_DOMAIN" "NB_COMPILE_OPTIONS")
message("---- START of nanobind_add_module2")
message("ARG_NB_SHARED: ${ARG_NB_SHARED}")
message("ARG_STABLE_ABI: ${ARG_STABLE_ABI}")
message("ARG_FREE_THREADED: ${ARG_FREE_THREADED}")
message("ARG_NB_STATIC: ${ARG_NB_STATIC}")
message("ARG_UNPARSED_ARGUMENTS: ${ARG_UNPARSED_ARGUMENTS}")
message("ARG_NB_COMPILE_OPTIONS: ${ARG_NB_COMPILE_OPTIONS}")
message("---- END of nanobind_add_module2")
add_library(${name} MODULE ${ARG_UNPARSED_ARGUMENTS})
if (ARG_NB_COMPILE_OPTIONS)
target_compile_options(
${name} # in nanobind this should be libname and not name, here it is to simplify the example
PRIVATE
${ARG_NB_COMPILE_OPTIONS}
)
endif()
endfunction()
nanobind_add_module2(
my_ext # Target name
NB_STATIC STABLE_ABI LTO # Optional flags (see below)
my_ext.h # Source code files below
my_ext.cpp
)
nanobind_add_module2(
my_ext2 # Target name
NB_STATIC STABLE_ABI LTO # Optional flags (see below)
my_ext.h # Source code files below
my_ext.cpp
NB_COMPILE_OPTIONS
-Wno-cast-qual
-Wno-zero-length-array
-Wno-nested-anon-types
-Wno-c++98-compat-extra-semi
-Wno-covered-switch-default
)
```
in this case, for my_ext flags.make:
```
CXX_FLAGS = -fPIC
```
and for my_ext2 flags.make:
```
CXX_FLAGS = -fPIC -Wno-cast-qual -Wno-zero-length-array -Wno-nested-anon-types -Wno-c++98-compat-extra-semi -Wno-covered-switch-default
```
https://github.com/llvm/llvm-project/pull/121477
More information about the Mlir-commits
mailing list