-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathmeson.build
106 lines (91 loc) · 4.63 KB
/
meson.build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
project('HoloPy', 'c',
version: '3.6.0pre',
meson_version: '>= 1.2.3',
)
'''
Build instructions for fortran extensions and holopy package
Notes:
The t-matrix and mie scattering codes require working Fortran 90 and C
compilers, as well as cython. On Ubuntu, you will need the "gfortran"
and "python-dev" packages installed.
meson 1.2.3 is first version to not rely on distutils and is minimum
version to support python>3.12
'''
# It seems to be common to add fortran in this way rather than in the
# project statement -- avoids some warnings.
add_languages('fortran', native: false)
# (below is from scipy meson.build)
# Don't use the deprecated NumPy C API. Define this to a fixed version
# instead of NPY_API_VERSION in order not to break compilation when
# NumPy introduces a new deprecation. Use in a meson.build file:
#
# py3.extension_module('_name',
# 'source_fname',
# numpy_nodepr_api)
#
# numpy_nodepr_api = '-DNPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION'
#
# GCC 14 enables strict type checking for pointers, which will lead to
# "incompatible pointer type" errors when compiling .c sources generated by f2py
# from numpy 1.20.3. To disable strict type checking we use
# '-Wno-error=incompatible-pointer-types' as an option to compiler. This problem
# should not occur in later versions of numpy, so we can remove the option when
# we update numpy.
numpy_nodepr_api = ['-DNPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION', '-Wno-error=incompatible-pointer-types']
py = import('python').find_installation(pure: false)
py_dep = py.dependency()
# quadmath library is required to compile fortran scattering extensions
quadmath_dep = meson.get_compiler('fortran').find_library('quadmath')
# Unlike numpy.distutils, meson doesn't run f2py automatically to
# compile the fortran extensions. So we need to tell meson how to find
# fortranobject.c, which is included with f2py and should be compiled
# and linked with any extension.
# See https://numpy.org/doc/stable/f2py/buildtools/meson.html
incdir_numpy = run_command(py,
['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'],
check : true
).stdout().strip()
incdir_f2py = incdir_numpy / '..' / '..' / 'f2py' / 'src'
# in numpy 1.22 and later, can replace above with
# incdir_f2py = run_command(py,
# ['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'],
# check : true
# ).stdout().strip()
inc_np = include_directories(incdir_numpy, incdir_f2py)
# All meson builds are done "out of tree". That means compiled
# extensions are not installed into the same directory as their sources.
# Note that holopy has several extensions that must be installed in a
# way that makes it possible to do (for example):
#
# import holopy.scattering.theory.mie_f.scsmfo_min
#
# To enable this functionality, we need to tell meson to copy the
# extensions to the appropriate point in the installation tree, *and* to
# copy the python files too. In the subdirectories, you'll see
# meson.build files that call "install_sources()", which installs the
# .py files of holopy, and that call "extension_module(subdir=...)"
# which tells meson where to install the fortran extensions. All files
# have to be specified, so if we add a python file somewhere, we need to
# update the relevant meson.build file to include it in the
# installation. This is how scipy uses meson. Having to specify all the
# files is a big switch from how numpy.distutils does things, but it
# makes the build process more efficient.
subdir('holopy')
# the original setup.py (used in the old installation method that relied on
# numpy.distutils) copied the data files into the package. The lines below are
# from setup.py. They won't work with meson, but are placed here so that we have
# a record of what files used to be copied, in case we want to add them to the
# meson build in the future.
# config.add_data_files(['.', [join(hp_root, 'AUTHORS')]])
# config.add_data_files(join(hp_root, 'holopy', 'scattering', 'tests',
# 'gold', 'full_data', '*.h5'))
# config.add_data_files(join(hp_root, 'holopy', 'scattering', 'tests',
# 'gold', '*.yaml'))
# config.add_data_files(join(hp_root, 'holopy', 'core', 'tests',
# 'exampledata', '*.h5'))
# config.add_data_files(join(hp_root, 'holopy', 'core', 'tests',
# 'exampledata', '*.jpg'))
# config.add_data_files(join(hp_root, 'holopy', 'propagation', 'tests',
# 'gold', 'full_data', '*.h5'))
# config.add_data_files(join(hp_root, 'holopy', 'propagation', 'tests',
# 'gold', '*.yaml'))