|
| 1 | +project( |
| 2 | + 'nanobind', |
| 3 | + 'cpp', |
| 4 | + version: '2.1.0', |
| 5 | + meson_version: '>=0.53.0', |
| 6 | + license: 'BSD-3-Clause', |
| 7 | +) |
| 8 | + |
| 9 | +py_mod = import('python') |
| 10 | +py = py_mod.find_installation() |
| 11 | +py_dep = py.dependency() |
| 12 | + |
| 13 | +robin_map_dep = dependency('robin-map') |
| 14 | + |
| 15 | +incdir = include_directories('include') |
| 16 | + |
| 17 | +# Arguments are derived from nanobind_build_library function in CMake configuration |
| 18 | +dep_compile_args = [] |
| 19 | +dep_link_args = [] |
| 20 | + |
| 21 | +if get_option('buildtype') == 'shared' |
| 22 | + if host_machine.system() == 'darwin' |
| 23 | + is_pypy = py_dep.get_variable('implementation_lower') == 'pypy' |
| 24 | + if is_pypy |
| 25 | + resp_file = meson.project_source_root() / 'cmake/darwin-ld-pypy.sym' |
| 26 | + else |
| 27 | + resp_file = meson.project_source_root() / 'cmake/darwin-ld-cpython.sym' |
| 28 | + endif |
| 29 | + add_project_link_arguments('-Wl,-dead_strip', '-Wl,x', '-Wl,-S', '-Wl,@' + resp_file) |
| 30 | + dep_link_args += ['-Wl,-dead_strip', '-Wl,x', '-Wl,-S', '-Wl,@' + resp_file] |
| 31 | + elif host_machine.system() != 'windows' |
| 32 | + add_project_link_arguments('-Wl,-s', language: 'cpp') |
| 33 | + dep_link_args += ['-Wl,-s'] |
| 34 | + endif |
| 35 | + |
| 36 | + add_project_arguments('-DNB_BUILD', language: 'cpp') |
| 37 | + dep_compile_args += ['-DNB_SHARED'] |
| 38 | +elif host_machine.system() != 'windows' and host_machine.system() != 'darwin' |
| 39 | + dep_compile_args += ['-ffunction-sections', '-fdata-sections'] |
| 40 | + dep_link_args += ['-Wl,--gc-sections'] |
| 41 | +endif |
| 42 | + |
| 43 | +compiler = meson.get_compiler('cpp') |
| 44 | +if compiler.get_id() == 'msvc' |
| 45 | + dep_compile_args += ['-D_CRT_SECURE_NO_WARNINGS'] |
| 46 | +else |
| 47 | + # Discussion in WrapDB PR #1556 as to whether or not this is necessary |
| 48 | + # add_project_arguments('-fno-strict-aliasing', language: 'cpp') |
| 49 | +endif |
| 50 | + |
| 51 | +if get_option('buildtype') == 'release' |
| 52 | + add_project_arguments('-DNB_COMPACT_ASSERTIONS', language: 'cpp') |
| 53 | +endif |
| 54 | + |
| 55 | +nanobind_lib = static_library( |
| 56 | + 'nanobind', |
| 57 | + sources: [ |
| 58 | + 'src/nb_internals.cpp', |
| 59 | + 'src/nb_func.cpp', |
| 60 | + 'src/nb_type.cpp', |
| 61 | + 'src/nb_enum.cpp', |
| 62 | + 'src/nb_ndarray.cpp', |
| 63 | + 'src/nb_static_property.cpp', |
| 64 | + 'src/common.cpp', |
| 65 | + 'src/error.cpp', |
| 66 | + 'src/trampoline.cpp', |
| 67 | + 'src/implicit.cpp', |
| 68 | + ], |
| 69 | + include_directories: [incdir], |
| 70 | + dependencies: [py_dep, robin_map_dep], |
| 71 | + gnu_symbol_visibility: 'hidden', |
| 72 | +) |
| 73 | + |
| 74 | + |
| 75 | +nanobind_dep = declare_dependency( |
| 76 | + include_directories: [incdir], |
| 77 | + link_with: [nanobind_lib], |
| 78 | + dependencies: [py_dep, robin_map_dep], |
| 79 | + compile_args: dep_compile_args, |
| 80 | + link_args: dep_link_args, |
| 81 | +) |
0 commit comments