numpy
/
meson.build
92 строки · 3.4 Кб
1project(
2'NumPy',
3'c', 'cpp', 'cython',
4version: run_command(
5# This should become `numpy/_version.py` in NumPy 2.0
6['numpy/_build_utils/gitversion.py'],
7check: true).stdout().strip(),
8license: 'BSD-3',
9meson_version: '>=1.2.99', # version in vendored-meson is 1.2.99
10default_options: [
11'buildtype=debugoptimized',
12'b_ndebug=if-release',
13'c_std=c11',
14'cpp_std=c++17',
15'pkgconfig.relocatable=true',
16],
17)
18
19fs = import('fs')
20
21cc = meson.get_compiler('c')
22cpp = meson.get_compiler('cpp')
23cy = meson.get_compiler('cython')
24
25# Check compiler is recent enough (see the SciPy Toolchain Roadmap for details)
26if cc.get_id() == 'gcc'
27if not cc.version().version_compare('>=8.4')
28error('NumPy requires GCC >= 8.4')
29endif
30elif cc.get_id() == 'msvc'
31if not cc.version().version_compare('>=19.20')
32error('NumPy requires at least vc142 (default with Visual Studio 2019) ' + \
33'when building with MSVC')
34endif
35endif
36if not cy.version().version_compare('>=3.0.6')
37error('NumPy requires Cython >= 3.0.6')
38endif
39
40py = import('python').find_installation(pure: false)
41py_dep = py.dependency()
42
43if not cc.has_header('Python.h', dependencies: py_dep)
44error('Cannot compile `Python.h`. Perhaps you need to install python-dev|python-devel')
45endif
46
47# Add default compile flags for any compiler that supports them.
48# Note that MSVC does not support strict aliasing at all, and neither do the
49# Intel compilers on Windows, so the `-fno` flavor of the flag should be fine.
50add_project_arguments(
51cc.get_supported_arguments( '-fno-strict-aliasing'), language : 'c'
52)
53#
54# Clang defaults to a non-strict floating error point model, but we need strict
55# behavior. `-ftrapping-math` is equivalent to `-ffp-exception-behavior=strict`.
56# This flag is also required to prevent the activation of SIMD partial load workarounds.
57# For further clarification, refer to gh-24461.
58cc_id = cc.get_id()
59if cc_id.startswith('clang')
60# Determine the compiler flags for trapping math exceptions.
61trapping_math = {
62'clang-cl': '/clang:-ftrapping-math',
63}.get(cc_id, '-ftrapping-math')
64# Check if the compiler supports the trapping math flag.
65if cc.has_argument(trapping_math)
66# TODO: Consider upgrading the vendored Meson to 1.3.0 to support the parameter `werror`
67# Detect whether the compiler actually supports strict handling of floating-point exceptions
68# by treating warnings as errors.
69if cc.compiles('int main() { return 0; }', args: [trapping_math, '-Werror'])
70trapping_math = [trapping_math, '-DNPY_HAVE_CLANG_FPSTRICT']
71else
72# Suppress warnings about unsupported floating-point optimization.
73trapping_math = [trapping_math, '-Wno-unsupported-floating-point-opt']
74# Inform the user about the workaround.
75message(
76'NumPy is being built against a version of Clang that does not strictly enforce ' +
77'floating-point exception handling. Workarounds will be used, which may impact performance.\n' +
78'Consider upgrading Clang to the latest version.'
79)
80endif
81add_project_arguments(trapping_math, language: ['c', 'cpp'])
82endif
83endif
84
85if host_machine.system() == 'darwin' and cc.has_link_argument('-Wl,-ld_classic')
86# New linker introduced in macOS 14 not working yet with at least OpenBLAS in Spack,
87# see gh-24964 (and linked scipy issue from there).
88add_project_link_arguments('-Wl,-ld_classic', language : ['c', 'cpp'])
89endif
90
91subdir('meson_cpu')
92subdir('numpy')
93