|
1 | | -project('gpgi', 'c', 'cython', meson_version: '>=1.5.0') |
| 1 | +project('gpgi', 'cython', meson_version: '>=1.5.0') |
2 | 2 |
|
3 | 3 | py = import('python').find_installation(pure: false) |
4 | 4 |
|
5 | 5 | min_numpy_version = '1.25.0' # keep in sync with pyproject.toml |
6 | 6 | cy = meson.get_compiler('cython') |
7 | 7 | cython = find_program(cy.cmd_array()[0]) |
8 | 8 |
|
| 9 | +numpy_nodepr_api = ['-DNPY_NO_DEPRECATED_API=NPY_1_25_API_VERSION'] |
9 | 10 |
|
10 | | -# https://github.com/mesonbuild/meson/issues/9598 |
11 | | -incdir_numpy = run_command(py, |
12 | | - [ |
13 | | - '-c', |
14 | | - 'import os; os.chdir(".."); import numpy; print(numpy.get_include())' |
15 | | - ], |
16 | | - check: true |
17 | | -).stdout().strip() |
18 | | - |
19 | | -inc_np = include_directories(incdir_numpy) |
| 11 | +# copied from PyWavelets |
| 12 | +# https://github.com/PyWavelets/pywt/blob/becef5486174c77727ea2a60e6392744b2cc1d4a/pywt/_extensions/meson.build#L13 |
| 13 | +# Uses the `numpy-config` executable (or a user's numpy.pc pkg-config file), |
| 14 | +# will work for numpy>=2.0.0b1 and meson>=1.4.0 |
| 15 | +_numpy_dep = dependency('numpy', required: false) |
| 16 | +if _numpy_dep.found() |
| 17 | + np_dep = declare_dependency(dependencies: _numpy_dep, compile_args: numpy_nodepr_api) |
| 18 | +else |
| 19 | + # For cross-compilation it is often not possible to run the Python interpreter |
| 20 | + # in order to retrieve numpy's include directory. It can be specified in the |
| 21 | + # cross file instead: |
| 22 | + # [properties] |
| 23 | + # numpy-include-dir = /abspath/to/host-pythons/site-packages/numpy/core/include |
| 24 | + # |
| 25 | + # This uses the path as is, and avoids running the interpreter. |
| 26 | + incdir_numpy = meson.get_external_property('numpy-include-dir', 'not-given') |
| 27 | + if incdir_numpy == 'not-given' |
| 28 | + incdir_numpy = run_command(py, |
| 29 | + [ |
| 30 | + '-c', |
| 31 | + '''import os |
| 32 | +import numpy as np |
| 33 | +try: |
| 34 | + incdir = os.path.relpath(np.get_include()) |
| 35 | +except Exception: |
| 36 | + incdir = np.get_include() |
| 37 | +print(incdir) |
| 38 | + ''' |
| 39 | + ], |
| 40 | + check: true |
| 41 | + ).stdout().strip() |
| 42 | + endif |
| 43 | + inc_np = include_directories(incdir_numpy) |
| 44 | + np_dep = declare_dependency(include_directories: inc_np, compile_args: numpy_nodepr_api) |
| 45 | +endif |
20 | 46 |
|
21 | 47 | py.extension_module( |
22 | | - 'gpgi._lib', |
| 48 | + '_lib', |
23 | 49 | 'src/gpgi/_lib.pyx', |
| 50 | + subdir: 'gpgi', |
24 | 51 | install: true, |
25 | | - include_directories : [inc_np], |
| 52 | + dependencies : [np_dep], |
| 53 | + c_args: numpy_nodepr_api, |
26 | 54 | ) |
0 commit comments