scipy
/
meson.build
154 строки · 5.9 Кб
1project(
2'scipy',
3'c', 'cpp', 'cython',
4version: run_command(['tools/gitversion.py'], check: true).stdout().strip(),
5license: 'BSD-3',
6meson_version: '>= 1.5.0',
7default_options: [
8'buildtype=debugoptimized',
9'b_ndebug=if-release',
10'c_std=c17',
11'cpp_std=c++17',
12'fortran_std=legacy',
13'blas=openblas',
14'lapack=openblas'
15],
16)
17
18py3 = import('python').find_installation(pure: false)
19py3_dep = py3.dependency()
20
21min_numpy_version = '1.23.5' # keep in sync with pyproject.toml
22
23# Emit a warning for 32-bit Python installs on Windows; users are getting
24# unexpected from-source builds there because we no longer provide wheels.
25is_windows = host_machine.system() == 'windows'
26if is_windows and py3.has_variable('EXT_SUFFIX')
27ext_suffix = py3.get_variable('EXT_SUFFIX')
28if ext_suffix.contains('win32')
29warning('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!')
30endif
31endif
32
33cc = meson.get_compiler('c')
34cpp = meson.get_compiler('cpp')
35cy = meson.get_compiler('cython')
36# generator() doesn't accept compilers, only found programs - cast it.
37cython = find_program(cy.cmd_array()[0])
38
39# Check compiler is recent enough (see "Toolchain Roadmap" for details)
40if cc.get_id() == 'gcc'
41if not cc.version().version_compare('>=9.1')
42error('SciPy requires GCC >= 9.1')
43endif
44elif cc.get_id() == 'clang' or cc.get_id() == 'clang-cl'
45if not cc.version().version_compare('>=12.0')
46error('SciPy requires clang >= 12.0')
47endif
48elif cc.get_id() == 'msvc'
49if not cc.version().version_compare('>=19.20')
50error('SciPy requires at least vc142 (default with Visual Studio 2019) ' + \
51'when building with MSVC')
52endif
53endif
54if not cy.version().version_compare('>=3.0.8')
55error('SciPy requires Cython >= 3.0.8')
56endif
57
58_global_c_args = cc.get_supported_arguments(
59'-Wno-unused-but-set-variable',
60'-Wno-unused-function',
61'-Wno-conversion',
62'-Wno-misleading-indentation',
63)
64add_project_arguments(_global_c_args, language : 'c')
65
66# We need -lm for all C code (assuming it uses math functions, which is safe to
67# assume for SciPy). For C++ it isn't needed, because libstdc++/libc++ is
68# guaranteed to depend on it. For Fortran code, Meson already adds `-lm`.
69m_dep = cc.find_library('m', required : false)
70if m_dep.found()
71add_project_link_arguments('-lm', language : 'c')
72endif
73
74if host_machine.system() == 'os400'
75# IBM i system, needed to avoid build errors - see gh-17193
76add_project_arguments('-D__STDC_FORMAT_MACROS', language : 'cpp')
77add_project_link_arguments('-Wl,-bnotextro', language : ['c', 'cpp', 'fortran'])
78endif
79
80# Adding at project level causes many spurious -lgfortran flags.
81add_languages('fortran', native: false)
82ff = meson.get_compiler('fortran')
83if ff.has_argument('-Wno-conversion')
84add_project_arguments('-Wno-conversion', language: 'fortran')
85endif
86
87if host_machine.system() == 'darwin'
88if cc.has_link_argument('-Wl,-ld_classic')
89# New linker introduced in macOS 14 not working yet, see gh-19357 and gh-19387
90add_project_link_arguments('-Wl,-ld_classic', language : ['c', 'cpp', 'fortran'])
91endif
92if cc.has_link_argument('-Wl,-dead_strip')
93# Allow linker to strip unused symbols
94add_project_link_arguments('-Wl,-dead_strip', language : ['c', 'cpp', 'fortran'])
95endif
96endif
97
98# Intel compilers default to fast-math, so disable it if we detect Intel
99# compilers. A word of warning: this may not work with the conda-forge
100# compilers, because those have the annoying habit of including lots of flags
101# that are gcc-specific in CFLAGS/CXXFLAGS/FFLAGS, which throws off the
102# detection logic below. You have to remove the wrong flags (only `-isystem`
103# is actually needed, everything else shouldn't be there).
104_intel_cflags = []
105_intel_fflags = []
106if cc.get_id() in ['intel', 'intel-llvm']
107_intel_cflags += cc.get_supported_arguments('-fp-model=strict')
108elif cc.get_id() in ['intel-cl', 'intel-llvm-cl']
109_intel_cflags += cc.get_supported_arguments('/fp:strict')
110endif
111if ff.get_id() in ['intel', 'intel-llvm']
112_intel_fflags = ff.get_supported_arguments('-fp-model=strict')
113minus0_arg = ['-assume', 'minus0']
114if ff.has_multi_arguments(minus0_arg)
115_intel_fflags += minus0_arg
116endif
117elif ff.get_id() in ['intel-cl', 'intel-llvm-cl']
118# Intel Fortran on Windows does things differently, so deal with that
119# (also specify dynamic linking and the right name mangling)
120_intel_fflags = ff.get_supported_arguments(
121'/fp:strict', '/MD', '/names:lowercase', '/assume:underscore',
122'/assume:minus0'
123)
124endif
125add_project_arguments(_intel_cflags, language: ['c', 'cpp'])
126add_project_arguments(_intel_fflags, language: 'fortran')
127
128# Hide symbols when building on Linux with GCC. For Python extension modules,
129# we only need `PyInit_*` to be public, anything else may cause problems. So we
130# use a linker script to avoid exporting those symbols (this is in addition to
131# Meson using `-fvisibility=hidden` for C and `-fvisibility-inlines-hidden` for
132# C++ code. See gh-15996 for details.
133_linker_script = meson.project_source_root() / 'scipy/_build_utils/link-version-pyinit.map'
134version_link_args = ['-Wl,--version-script=' + _linker_script]
135# Note that FreeBSD only accepts version scripts when -shared is passed,
136# hence we need to pass that to `cc.links` explicitly (flag is already
137# present for `extension_module` invocations).
138if not cc.links('', name: '-Wl,--version-script', args: ['-shared', version_link_args])
139version_link_args = []
140endif
141
142generate_f2pymod = find_program('tools/generate_f2pymod.py')
143tempita = find_program('scipy/_build_utils/tempita.py')
144
145use_pythran = get_option('use-pythran')
146if use_pythran
147pythran = find_program('pythran', native: true, version: '>=0.14.0')
148# xsimd is unvendored from pythran by conda-forge, and due to a compiler
149# activation bug the default <prefix>/include/ may not be visible (see
150# gh-15698). Hence look for xsimd explicitly.
151xsimd_dep = dependency('xsimd', required: false)
152endif
153
154subdir('scipy')
155