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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
# We need -lm for all C code (assuming it uses math functions, which is safe to
# assume for numpy).
m_dep = cc.find_library('m', required : false)
mlib_linkflag = ''
if m_dep.found()
mlib_linkflag = '-lm'
add_project_link_arguments(mlib_linkflag, language : 'c')
endif
# Platform detection
is_windows = host_machine.system() == 'windows'
is_mingw = is_windows and cc.get_id() == 'gcc'
if is_windows
# For mingw-w64, link statically against the UCRT.
gcc_link_args = ['-lucrt', '-static']
if is_mingw
add_project_link_arguments(gcc_link_args, language: ['c', 'cpp'])
# Force gcc to float64 long doubles for compatibility with MSVC
# builds, for C only.
add_project_arguments('-mlong-double-64', language: 'c')
# Make fprintf("%zd") work (see https://github.com/rgommers/scipy/issues/118)
add_project_arguments('-D__USE_MINGW_ANSI_STDIO=1', language: ['c', 'cpp'])
# Manual add of MS_WIN64 macro when not using MSVC.
# https://bugs.python.org/issue28267
bitness = run_command('_build_utils/gcc_build_bitness.py').stdout().strip()
if bitness == '64'
add_project_arguments('-DMS_WIN64', language: ['c', 'cpp'])
endif
endif
endif
# Enable UNIX large file support on 32-bit systems (64 bit off_t,
# lseek -> lseek64, etc.)
cflags_large_file_support = []
if host_machine.system() == 'aix'
cflags_large_file_support += '-D_LARGE_FILES'
else
cflags_large_file_support += [
'-D_FILE_OFFSET_BITS=64',
'-D_LARGEFILE_SOURCE=1',
'-D_LARGEFILE64_SOURCE=1',
]
endif
# TODO: 64-bit BLAS and LAPACK
#
# Note that this works as long as BLAS and LAPACK are detected properly via
# pkg-config. By default we look for OpenBLAS, other libraries can be configured via
# `meson configure -Dblas=blas -Dlapack=lapack` (example to build with Netlib
# BLAS and LAPACK).
# For MKL and for auto-detecting one of multiple libs, we'll need a custom
# dependency in Meson (like is done for scalapack) - see
# https://github.com/mesonbuild/meson/issues/2835
blas_name = get_option('blas')
lapack_name = get_option('lapack')
# pkg-config uses a lower-case name while CMake uses a capitalized name, so try
# that too to make the fallback detection with CMake work
if blas_name == 'openblas'
blas_name = ['openblas', 'OpenBLAS']
endif
if lapack_name == 'openblas'
lapack_name = ['openblas', 'OpenBLAS']
endif
blas = dependency(blas_name, required: false)
lapack = dependency(lapack_name, required: false)
dependency_map = {
'BLAS': blas,
'LAPACK': lapack,
}
# BLAS and LAPACK are optional dependencies for NumPy. We can only use a BLAS
# which provides a CBLAS interface.
# TODO: add ILP64 support
have_blas = blas.found() # TODO: and blas.has_cblas()
have_lapack = lapack.found()
if have_blas
# TODO: this is a shortcut - it needs to be checked rather than used
# unconditionally, and then added to the extension modules that need the
# macro, rather than as a project argument.
add_project_arguments('-DHAVE_CBLAS', language: ['c', 'cpp'])
endif
# Copy the main __init__.py|pxd files to the build dir (needed for Cython)
__init__py = fs.copyfile('__init__.py')
__init__pxd = fs.copyfile('__init__.pxd')
__init__pxd30 = fs.copyfile('__init__.cython-30.pxd')
_cython_tree = [__init__py, __init__pxd, __init__pxd30]
python_sources = [
'__init__.cython-30.pxd',
'__init__.pxd',
'__init__.py',
'__init__.pyi',
'_distributor_init.py',
'_globals.py',
'_pytesttester.py',
'_pytesttester.pyi',
'_version.py',
'conftest.py',
'ctypeslib.py',
'ctypeslib.pyi',
'exceptions.py',
'exceptions.pyi',
'dtypes.py',
'dtypes.pyi',
'matlib.py',
'py.typed',
'version.py'
]
py.install_sources(
python_sources,
subdir: 'numpy'
)
src_file_cli = find_program('_build_utils/process_src_template.py')
src_file = generator(src_file_cli,
arguments : ['@INPUT@', '--outfile', '@OUTPUT@'],
output : '@BASENAME@'
)
tempita_cli = find_program('_build_utils/tempita.py')
tempita = generator(tempita_cli,
arguments : ['@INPUT@', '--outfile', '@OUTPUT@'],
output : '@BASENAME@'
)
pure_subdirs = [
'_pyinstaller',
'_typing',
'_utils',
'array_api',
'compat',
'distutils',
'doc',
'f2py',
'lib',
'ma',
'matrixlib',
'polynomial',
'testing',
'tests',
'typing',
]
np_dir = py.get_install_dir() / 'numpy'
foreach subdir: pure_subdirs
install_subdir(subdir, install_dir: np_dir)
endforeach
compilers = {
'C': cc,
'CPP': cpp,
'CYTHON': meson.get_compiler('cython')
}
machines = {
'HOST': host_machine,
'BUILD': build_machine,
}
conf_data = configuration_data()
# Set compiler information
foreach name, compiler : compilers
conf_data.set(name + '_COMP', compiler.get_id())
conf_data.set(name + '_COMP_LINKER_ID', compiler.get_linker_id())
conf_data.set(name + '_COMP_VERSION', compiler.version())
conf_data.set(name + '_COMP_CMD_ARRAY', ', '.join(compiler.cmd_array()))
endforeach
# Machines CPU and system information
foreach name, machine : machines
conf_data.set(name + '_CPU', machine.cpu())
conf_data.set(name + '_CPU_FAMILY', machine.cpu_family())
conf_data.set(name + '_CPU_ENDIAN', machine.endian())
conf_data.set(name + '_CPU_SYSTEM', machine.system())
endforeach
conf_data.set('CROSS_COMPILED', meson.is_cross_build())
# Python information
conf_data.set('PYTHON_PATH', py.full_path())
conf_data.set('PYTHON_VERSION', py.language_version())
# Dependencies information
foreach name, dep : dependency_map
conf_data.set(name + '_NAME', dep.name())
conf_data.set(name + '_FOUND', dep.found())
if dep.found()
conf_data.set(name + '_VERSION', dep.version())
conf_data.set(name + '_TYPE_NAME', dep.type_name())
conf_data.set(name + '_INCLUDEDIR', dep.get_variable('includedir'))
conf_data.set(name + '_LIBDIR', dep.get_variable('libdir'))
conf_data.set(name + '_OPENBLAS_CONFIG', dep.get_variable('openblas_config'))
conf_data.set(name + '_PCFILEDIR', dep.get_variable('pcfiledir'))
endif
endforeach
configure_file(
input: '__config__.py.in',
output: '__config__.py',
configuration : conf_data,
install_dir: np_dir,
)
subdir('core')
subdir('fft')
subdir('linalg')
subdir('random')
|