Skip to content

Commit 0e3bb6f

Browse files
committed
tentative fixup
1 parent f423c14 commit 0e3bb6f

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

meson.build

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,54 @@
1-
project('gpgi', 'c', 'cython', meson_version: '>=1.5.0')
1+
project('gpgi', 'cython', meson_version: '>=1.5.0')
22

33
py = import('python').find_installation(pure: false)
44

55
min_numpy_version = '1.25.0' # keep in sync with pyproject.toml
66
cy = meson.get_compiler('cython')
77
cython = find_program(cy.cmd_array()[0])
88

9+
numpy_nodepr_api = ['-DNPY_NO_DEPRECATED_API=NPY_1_25_API_VERSION']
910

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
2046

2147
py.extension_module(
22-
'gpgi._lib',
48+
'_lib',
2349
'src/gpgi/_lib.pyx',
50+
subdir: 'gpgi',
2451
install: true,
25-
include_directories : [inc_np],
52+
dependencies : [np_dep],
53+
c_args: numpy_nodepr_api,
2654
)

0 commit comments

Comments
 (0)