-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeson.build
More file actions
118 lines (103 loc) · 2.97 KB
/
meson.build
File metadata and controls
118 lines (103 loc) · 2.97 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
project(
'mapflpy',
'c', 'cpp', 'fortran',
version: run_command(['tools/pyproject_version.py'], check: true).stdout().strip(),
license : 'Apache-2.0',
meson_version : '>=1.1.0',
default_options : [
'warning_level=1',
'buildtype=release'
],
)
# ---- Compilers / platform niceties
cc = meson.get_compiler('c')
fc = meson.get_compiler('fortran')
if host_machine.system() == 'darwin'
if cc.has_link_argument('-Wl,-dead_strip')
add_project_link_arguments('-Wl,-dead_strip', language : ['c', 'fortran'])
endif
endif
# Optional quadmath (GCC Fortran)
quadmath_dep = fc.find_library('quadmath', required : false)
# ---- Python & NumPy / F2PY
py = import('python').find_installation(pure : false)
py_dep = py.dependency()
np_inc_dir = run_command(
py, ['-c', 'import numpy; print(numpy.get_include())'],
check : true
).stdout().strip()
f2py_inc_dir = run_command(
py, ['-c', 'import numpy; print(numpy.f2py.get_include())'],
check : true
).stdout().strip()
# supply absolute include paths via compile args so they work for C and Fortran
numpy_dep = declare_dependency(compile_args : ['-I' + np_inc_dir])
f2py_dep = declare_dependency(compile_args : ['-I' + f2py_inc_dir])
# fortranobject.c from f2py
fortranobject_c = f2py_inc_dir / 'fortranobject.c'
# ---- HDF5 dependencies
hdf5_c = dependency('hdf5', required : true)
hdf5f = declare_dependency(link_args : ['-lhdf5_fortran'], dependencies : [hdf5_c])
hdf5f_hl = declare_dependency(link_args : ['-lhdf5hl_fortran'], dependencies : [hdf5_c])
# Optional: OpenMP
# omp_dep = dependency('openmp', required : false)
# if omp_dep.found()
# deps += omp_dep
# endif
# ---- F2PY codegen as a tracked build step
f2py_wrapped = custom_target(
'mapflpy_fortran_wrappers',
input : ['src/mapflpy_fortran.f90'],
output : ['mapflpy_fortranmodule.c', 'mapflpy_fortran-f2pywrappers2.f90'],
command: [
py, '-m', 'numpy.f2py',
'@INPUT0@',
'-m', 'mapflpy_fortran',
'--backend', 'meson',
'--f2cmap', meson.project_source_root() / '.f2py_f2cmap',
],
capture : false
)
# ---- Build CPython extension, install under mapflpy/fortran
py.extension_module(
'mapflpy_fortran',
[
'src/mapflpy_fortran.f90',
'src/mapfl/psi_io.f90',
'src/mapfl/mapfl.f',
f2py_wrapped[0],
f2py_wrapped[1],
fortranobject_c,
],
dependencies : [
py_dep,
quadmath_dep,
numpy_dep,
f2py_dep,
hdf5_c,
hdf5f,
hdf5f_hl,
],
subdir : 'mapflpy/fortran',
install : true,
)
# ---- Generate mapflpy/_version.py
conf = configuration_data()
conf.set('VERSION', meson.project_version())
configure_file(
input : 'mapflpy/_version.py.in', # contains: __version__ = "@VERSION@"
output : '_version.py',
configuration : conf,
install : true,
install_dir : py.get_install_dir() / 'mapflpy',
)
# ---- Install the pure-Python package tree
install_subdir(
'mapflpy',
install_dir : py.get_install_dir(),
exclude_files: [
'_version.py.in',
'__pycache__',
'*.pyc',
]
)