forked from scipy/scipy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
137 lines (124 loc) · 5.01 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
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
project(
'SciPy',
'c', 'cpp',
# Note that the git commit hash cannot be added dynamically here (it is added
# in the dynamically generated and installed `scipy/version.py` though - see
# tools/version_utils.py
version: '1.11.0.dev0',
license: 'BSD-3',
meson_version: '>= 0.64.0',
default_options: [
'buildtype=debugoptimized',
'c_std=c99',
'cpp_std=c++14',
'fortran_std=legacy',
'blas=openblas',
'lapack=openblas'
],
)
cc = meson.get_compiler('c')
cpp = meson.get_compiler('cpp')
# Check compiler is recent enough (see "Toolchain Roadmap" for details)
if cc.get_id() == 'gcc'
if not cc.version().version_compare('>=8.0')
error('SciPy requires GCC >= 8.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
# TODO: the below -Wno flags are all needed to silence warnings in
# f2py-generated code. This should be fixed in f2py itself.
_global_c_args = cc.get_supported_arguments(
'-Wno-unused-but-set-variable',
'-Wno-unused-function',
'-Wno-conversion',
'-Wno-misleading-indentation',
'-Wno-incompatible-pointer-types',
)
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')
add_project_link_arguments('-Wl,-bnotextro', language : 'cpp')
add_project_link_arguments('-Wl,-bnotextro', language : 'fortran')
endif
# Adding at project level causes many spurious -lgfortran flags.
add_languages('fortran', native: false)
ff = meson.get_compiler('fortran')
if ff.has_argument('-Wno-conversion')
add_project_arguments('-Wno-conversion', language: 'fortran')
endif
is_windows = host_machine.system() == 'windows'
# 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() == 'intel'
_intel_cflags += cc.get_supported_arguments('-fp-model=strict')
elif cc.get_id() == 'intel-cl'
_intel_cflags += cc.get_supported_arguments('/fp:strict')
endif
if ff.get_id() == 'intel'
_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() == 'intel-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_project_arguments(_intel_cflags, language: ['c', 'cpp'])
add_project_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.
_linker_script = meson.project_source_root() / 'scipy/_build_utils/link-version-pyinit.map'
version_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 not cc.links('', name: '-Wl,--version-script', args: ['-shared', version_link_args])
version_link_args = []
endif
cython = find_program('cython')
generate_f2pymod = files('tools/generate_f2pymod.py')
tempita = files('scipy/_build_utils/tempita.py')
# https://mesonbuild.com/Python-module.html
py_mod = import('python')
py3 = py_mod.find_installation(pure: false)
py3_dep = py3.dependency()
# For now, keep supporting this environment variable (same as in setup.py)
# Once setup.py-based builds are gone, we can convert this to a command-line flag, or make Pythran non-optional.
use_pythran = run_command(py3,
[
'-c',
'import os; print(os.environ.get("SCIPY_USE_PYTHRAN", 1))'
],
check: true
).stdout().strip() == '1'
if use_pythran
pythran = find_program('pythran')
endif
subdir('scipy')