forked from scipy/scipy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeson.build
More file actions
281 lines (244 loc) · 10.2 KB
/
meson.build
File metadata and controls
281 lines (244 loc) · 10.2 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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
project(
'scipy',
'c', 'cpp', 'cython',
version: run_command(['tools/gitversion.py'], check: true).stdout().strip(),
license: 'BSD-3',
meson_version: '>= 1.5.0',
default_options: [
'buildtype=debugoptimized',
'b_ndebug=if-release',
'c_std=c17',
'cpp_std=c++17',
'blas=openblas',
'lapack=openblas'
],
)
fs = import('fs')
meson.add_dist_script('tools/trim_sdist_content.py')
py3 = import('python').find_installation(pure: false)
py3_dep = py3.dependency()
min_numpy_version = '2.0.0' # keep in sync with pyproject.toml
min_python_version = '3.12' # keep in sync with pyproject.toml
python_version = py3.language_version()
if python_version.version_compare(f'<@min_python_version@')
error(f'Minimum supported Python version is @min_python_version@, found @python_version@')
endif
# Emit a warning for 32-bit Python installs on Windows; users are getting
# unexpected from-source builds there because we no longer provide wheels.
is_windows = host_machine.system() == 'windows'
if is_windows and py3.has_variable('EXT_SUFFIX')
ext_suffix = py3.get_variable('EXT_SUFFIX')
if ext_suffix.contains('win32')
warning('You are building from source on a 32-bit Python install. SciPy does not provide 32-bit wheels; install 64-bit Python if you are having issues!')
endif
endif
cc = meson.get_compiler('c')
cpp = meson.get_compiler('cpp')
cy = meson.get_compiler('cython')
# generator() doesn't accept compilers, only found programs - cast it.
cython = find_program(cy.cmd_array()[0])
# Check compiler is recent enough (see "Toolchain Roadmap" for details)
if cc.get_id() == 'gcc'
if not cc.version().version_compare('>=9.1')
error('SciPy requires GCC >= 9.1')
endif
elif cc.get_id() == 'clang' or cc.get_id() == 'clang-cl'
if not cc.version().version_compare('>=15.0')
error('SciPy requires clang >= 15.0')
endif
elif cc.get_id() == 'msvc'
if not cc.version().version_compare('>=19.20')
error('SciPy requires at least vc142 (default with Visual Studio 2019) ' + \
'when building with MSVC')
endif
endif
if not cy.version().version_compare('>=3.0.8')
error('SciPy requires Cython >= 3.0.8')
endif
_global_c_args = cc.get_supported_arguments(
'-Wno-unused-but-set-variable',
'-Wno-unused-function',
'-Wno-conversion',
'-Wno-misleading-indentation',
)
add_project_arguments(_global_c_args, language : 'c')
# We need -lm for all C code (assuming it uses math functions, which is safe to
# assume for SciPy). For C++ it isn't needed, because libstdc++/libc++ is
# guaranteed to depend on it. For Fortran code, Meson already adds `-lm`.
m_dep = cc.find_library('m', required : false)
if m_dep.found()
add_project_link_arguments('-lm', language : 'c')
endif
if host_machine.system() == 'os400'
# IBM i system, needed to avoid build errors - see gh-17193
add_project_arguments('-D__STDC_FORMAT_MACROS', language : 'cpp')
add_project_link_arguments('-Wl,-bnotextro', language : ['c', 'cpp', 'fortran'])
endif
# Adding at project level causes many spurious -lgfortran flags.
add_languages('fortran', native: false)
ff = meson.get_compiler('fortran')
if ff.get_id() == 'gcc'
# -std=legacy is not supported by all Fortran compilers, but very useful with
# gfortran since it avoids a ton of warnings that we don't care about.
# Needs fixing in Meson, see https://github.com/mesonbuild/meson/issues/11633.
add_project_arguments('-std=legacy', language: 'fortran')
endif
if ff.has_argument('-Wno-conversion')
add_project_arguments('-Wno-conversion', language: 'fortran')
endif
if ff.get_id() == 'llvm-flang'
add_project_arguments('-D_CRT_SECURE_NO_WARNINGS', language: ['fortran'])
# -Wall warnings are visible because Meson's warning_level defaults to 1 (-Wall)
# LLVM tracking issue: https://github.com/llvm/llvm-project/issues/89888
endif
if cc.get_id() == 'clang-cl'
add_global_arguments('-D_CRT_SECURE_NO_WARNINGS', language: ['c', 'cpp'])
# Some arguments like -Wl,--version-script may otherwise generate a
# large number of warnings. clang-cl accepts but ignores them.
add_project_arguments('-Qunused-arguments', language: ['c', 'cpp'])
endif
if cpp.get_id() == 'msvc'
add_project_arguments('/bigobj', language: 'cpp')
endif
if host_machine.system() == 'darwin'
if cc.has_link_argument('-Wl,-dead_strip')
# Allow linker to strip unused symbols
add_project_link_arguments('-Wl,-dead_strip', language : ['c', 'cpp', 'fortran'])
endif
endif
if get_option('b_sanitize') != 'none'
if cc.get_id() == 'clang'
ignore_file = meson.current_source_dir() / 'tools' / 'asan-ignore.txt'
add_global_arguments('-fsanitize-ignorelist=' + ignore_file, language: ['c', 'cpp'])
endif
endif
# Intel compilers default to fast-math, so disable it if we detect Intel
# compilers. A word of warning: this may not work with the conda-forge
# compilers, because those have the annoying habit of including lots of flags
# that are gcc-specific in CFLAGS/CXXFLAGS/FFLAGS, which throws off the
# detection logic below. You have to remove the wrong flags (only `-isystem`
# is actually needed, everything else shouldn't be there).
_intel_cflags = []
_intel_fflags = []
if cc.get_id() in ['intel', 'intel-llvm']
_intel_cflags += cc.get_supported_arguments('-fp-model=strict')
elif cc.get_id() in ['intel-cl', 'intel-llvm-cl']
_intel_cflags += cc.get_supported_arguments('/fp:strict')
endif
if ff.get_id() in ['intel', 'intel-llvm']
_intel_fflags = ff.get_supported_arguments('-fp-model=strict')
minus0_arg = ['-assume', 'minus0']
if ff.has_multi_arguments(minus0_arg)
_intel_fflags += minus0_arg
endif
elif ff.get_id() in ['intel-cl', 'intel-llvm-cl']
# Intel Fortran on Windows does things differently, so deal with that
# (also specify dynamic linking and the right name mangling)
_intel_fflags = ff.get_supported_arguments(
'/fp:strict', '/MD', '/names:lowercase', '/assume:underscore',
'/assume:minus0'
)
endif
add_global_arguments(_intel_cflags, language: ['c', 'cpp'])
add_global_arguments(_intel_fflags, language: 'fortran')
# Hide symbols when building on Linux with GCC. For Python extension modules,
# we only need `PyInit_*` to be public, anything else may cause problems. So we
# use a linker script to avoid exporting those symbols (this is in addition to
# Meson using `-fvisibility=hidden` for C and `-fvisibility-inlines-hidden` for
# C++ code. See gh-15996 for details.
version_link_args = []
if cc.get_id() != 'clang-cl'
_linker_script = meson.project_source_root() / 'scipy/_build_utils/link-version-pyinit.map'
vscript_link_args = ['-Wl,--version-script=' + _linker_script]
# Note that FreeBSD only accepts version scripts when -shared is passed,
# hence we need to pass that to `cc.links` explicitly (flag is already
# present for `extension_module` invocations).
if cc.links('', name: '-Wl,--version-script', args: ['-shared', vscript_link_args])
version_link_args = vscript_link_args
endif
endif
generate_f2pymod = find_program('tools/generate_f2pymod.py')
tempita = find_program('scipy/_build_utils/tempita.py')
use_pythran = get_option('use-pythran')
if use_pythran
pythran = find_program('pythran', native: true, version: '>=0.18.1')
endif
# Subprojects
if not fs.exists('subprojects/array_api_compat/array_api_compat/README.md')
error('Missing the `array_api_compat` submodule! Run `git submodule update --init` to fix this.')
endif
if not fs.exists('subprojects/array_api_extra/README.md')
error('Missing the `array_api_extra` submodule! Run `git submodule update --init` to fix this.')
endif
if not fs.exists('subprojects/cobyqa/README.rst')
error('Missing the `cobyqa` submodule! Run `git submodule update --init` to fix this.')
endif
if not fs.exists('subprojects/pocketfft/README.md')
error('Missing the `pocketfft` submodule! Run `git submodule update --init` to fix this.')
endif
if not fs.exists('subprojects/unuran/README.md')
error('Missing the `unuran` submodule! Run `git submodule update --init` to fix this.')
endif
if not fs.exists('subprojects/xsf/README.md')
error('Missing the `xsf` submodule! Run `git submodule update --init` to fix this.')
endif
external_dir = 'scipy/_external'
array_api_compat = subproject('array_api_compat')
array_api_compat_sources = array_api_compat.get_variable('sources')
foreach prefix, files : array_api_compat_sources
py3.install_sources(files, subdir: external_dir / prefix)
endforeach
array_api_extra = subproject('array_api_extra')
array_api_extra_sources = array_api_extra.get_variable('sources')
foreach prefix, files : array_api_extra_sources
py3.install_sources(files, subdir: external_dir / prefix)
endforeach
cobyqa = subproject('cobyqa')
cobyqa_sources = cobyqa.get_variable('sources')
foreach prefix, files : cobyqa_sources
py3.install_sources(files, subdir: external_dir / prefix)
endforeach
pyprima = subproject('pyprima')
pyprima_sources = pyprima.get_variable('sources')
foreach prefix, files : pyprima_sources
py3.install_sources(files, subdir: external_dir / prefix)
endforeach
pocketfft = subproject('pocketfft')
pocketfft_dep = pocketfft.get_variable('pocketfft_dep')
unuran = subproject('unuran')
xsf = subproject('xsf')
xsf_dep = xsf.get_variable('xsf_dep')
# System libraries / subprojects
use_system_libraries = get_option('use-system-libraries')
all_system_libraries = false
auto_system_libraries = false
if use_system_libraries.contains('none')
use_system_libraries = ['none']
elif use_system_libraries.contains('all')
all_system_libraries = true
elif use_system_libraries.contains('auto')
auto_system_libraries = true
endif
if all_system_libraries or use_system_libraries.contains('boost.math')
boost_math_dep = dependency('boost', version : '1.89.0')
elif auto_system_libraries
boost_math_dep = dependency(
'boost', version : '1.89.0',
fallback : ['boost_math', 'boost_math_dep']
)
else
boost_math = subproject('boost_math', version : '1.89.0')
boost_math_dep = boost_math.get_variable('boost_math_dep')
endif
if all_system_libraries or use_system_libraries.contains('qhull')
qhull_r_dep = dependency('qhull_r', version : '8.0.2')
elif auto_system_libraries
qhull_r_dep = dependency(
'qhull_r', version : '8.0.2',
fallback : ['qhull_r', 'qhull_r_dep']
)
else
qhull_r = subproject('qhull_r', version : '8.0.2')
qhull_r_dep = qhull_r.get_variable('qhull_r_dep')
endif
subdir('scipy')