@@ -22,6 +22,18 @@ if is_mingw
22
22
add_project_arguments (' -D__USE_MINGW_ANSI_STDIO=1' , language : [' c' , ' cpp' ])
23
23
endif
24
24
25
+ # We install libnpymath and libnpyrandom; ensure they're using a `.lib` rather
26
+ # than a `.a` file extension in order not to break including them in a
27
+ # distutils-based build (see gh-23981 and
28
+ # https://mesonbuild.com/FAQ.html#why-does-building-my-project-with-msvc-output-static-libraries-called-libfooa)
29
+ if is_windows and cc.get_id() == ' msvc'
30
+ name_prefix_staticlib = ''
31
+ name_suffix_staticlib = ' lib'
32
+ else
33
+ name_prefix_staticlib = []
34
+ name_suffix_staticlib = []
35
+ endif
36
+
25
37
# Enable UNIX large file support on 32-bit systems (64 bit off_t,
26
38
# lseek -> lseek64, etc.)
27
39
cflags_large_file_support = []
55
67
blas = dependency (blas_name, required : false )
56
68
endif
57
69
have_blas = blas.found()
58
- if have_blas and blas_name == ' blas'
70
+ cblas = []
71
+ if have_blas
59
72
# Netlib BLAS has a separate `libcblas.so` which we use directly in the g77
60
- # ABI wrappers, so detect it and error out if we cannot find it.
73
+ # ABI wrappers, so detect it and error out if we cannot find it. OpenBLAS can
74
+ # be built without CBLAS too (see gh-23909, done by Arch Linux until
75
+ # recently)
61
76
# In the future, this should be done automatically for:
62
77
# `dependency('blas', modules: cblas)`
63
78
# see https://github.com/mesonbuild/meson/pull/10921.
64
- cblas = dependency (' cblas' )
65
- else
66
- cblas = []
79
+ have_cblas = false
80
+ if cc.links('''
81
+ #include <cblas.h>
82
+ int main(int argc, const char *argv[])
83
+ {
84
+ double a[4] = {1,2,3,4};
85
+ double b[4] = {5,6,7,8};
86
+ return cblas_ddot(4, a, 1, b, 1) > 10;
87
+ }
88
+ ''' ,
89
+ dependencies : blas,
90
+ name : ' CBLAS' ,
91
+ )
92
+ have_cblas = true
93
+ else
94
+ cblas = dependency (' cblas' , required : false )
95
+ if cblas.found()
96
+ have_cblas = true
97
+ endif
98
+ endif
67
99
endif
68
100
69
101
if lapack_name == ' openblas'
70
102
lapack_name = [' openblas' , ' OpenBLAS' ]
71
103
endif
72
- lapack = dependency (lapack_name, required : false )
73
- have_lapack = lapack .found()
104
+ lapack_dep = dependency (lapack_name, required : false )
105
+ have_lapack = lapack_dep .found()
74
106
75
107
dependency_map = {
76
108
' BLAS' : blas,
77
- ' LAPACK' : lapack ,
109
+ ' LAPACK' : lapack_dep ,
78
110
}
79
111
112
+ use_ilp64 = get_option (' use-ilp64' )
113
+ if not use_ilp64
114
+ # For now, keep supporting this environment variable too (same as in setup.py)
115
+ # `false is the default for the CLI flag, so check if env var was set
116
+ use_ilp64 = run_command (py,
117
+ [
118
+ ' -c' ,
119
+ ' import os; print(1) if os.environ.get("NPY_USE_BLAS_ILP64", "0") != "0" else print(0)'
120
+ ],
121
+ check : true
122
+ ).stdout().strip() == ' 1'
123
+ endif
124
+
80
125
# BLAS and LAPACK are optional dependencies for NumPy. We can only use a BLAS
81
126
# which provides a CBLAS interface.
82
127
# TODO: add ILP64 support
83
128
if have_blas
84
- # TODO: this is a shortcut - it needs to be checked rather than used
85
- # unconditionally, and then added to the extension modules that need the
86
- # macro, rather than as a project argument.
87
- add_project_arguments (' -DHAVE_CBLAS' , language : [' c' , ' cpp' ])
129
+ c_args_blas = [] # note: used for C and C++ via `blas_dep` below
130
+ if have_cblas
131
+ c_args_blas += [' -DHAVE_CBLAS' ]
132
+ endif
133
+ if use_ilp64
134
+ c_args_blas += [' -DHAVE_BLAS_ILP64' ]
135
+ endif
136
+ # This is currently injected directly into CFLAGS/CXXFLAGS for wheel builds
137
+ # (see cibuildwheel settings in pyproject.toml)
138
+ blas_symbol_suffix = get_option (' blas-symbol-suffix' )
139
+ if blas_symbol_suffix != ''
140
+ c_args_blas += [' -DBLAS_SYMBOL_SUFFIX=' + blas_symbol_suffix]
141
+ endif
142
+ blas_dep = declare_dependency (
143
+ dependencies : [blas, cblas],
144
+ compile_args : c_args_blas,
145
+ )
146
+ else
147
+ blas_dep = []
88
148
endif
89
149
90
150
# Copy the main __init__.py|pxd files to the build dir (needed for Cython)
@@ -138,7 +198,6 @@ pure_subdirs = [
138
198
' _utils' ,
139
199
' array_api' ,
140
200
' compat' ,
141
- ' distutils' ,
142
201
' doc' ,
143
202
' f2py' ,
144
203
' lib' ,
@@ -149,6 +208,9 @@ pure_subdirs = [
149
208
' tests' ,
150
209
' typing' ,
151
210
]
211
+ if py.version().version_compare(' <3.12' )
212
+ pure_subdirs += ' distutils'
213
+ endif
152
214
153
215
np_dir = py.get_install_dir() / ' numpy'
154
216
@@ -175,6 +237,14 @@ foreach name, compiler : compilers
175
237
conf_data.set(name + ' _COMP_LINKER_ID' , compiler.get_linker_id())
176
238
conf_data.set(name + ' _COMP_VERSION' , compiler.version())
177
239
conf_data.set(name + ' _COMP_CMD_ARRAY' , ' , ' .join(compiler.cmd_array()))
240
+ conf_data.set(name + ' _COMP_ARGS' , ' , ' .join(
241
+ get_option (name.to_lower() + ' _args' )
242
+ )
243
+ )
244
+ conf_data.set(name + ' _COMP_LINK_ARGS' , ' , ' .join(
245
+ get_option (name.to_lower() + ' _link_args' )
246
+ )
247
+ )
178
248
endforeach
179
249
180
250
# Machines CPU and system information
@@ -198,10 +268,13 @@ foreach name, dep : dependency_map
198
268
if dep.found()
199
269
conf_data.set(name + ' _VERSION' , dep.version())
200
270
conf_data.set(name + ' _TYPE_NAME' , dep.type_name())
201
- conf_data.set(name + ' _INCLUDEDIR' , dep.get_variable (' includedir' ))
202
- conf_data.set(name + ' _LIBDIR' , dep.get_variable (' libdir' ))
203
- conf_data.set(name + ' _OPENBLAS_CONFIG' , dep.get_variable (' openblas_config' ))
204
- conf_data.set(name + ' _PCFILEDIR' , dep.get_variable (' pcfiledir' ))
271
+ if dep.type_name() == ' pkgconfig'
272
+ # CMake detection yields less info, so we need to leave it blank there
273
+ conf_data.set(name + ' _INCLUDEDIR' , dep.get_variable (' includedir' ))
274
+ conf_data.set(name + ' _LIBDIR' , dep.get_variable (' libdir' ))
275
+ conf_data.set(name + ' _OPENBLAS_CONFIG' , dep.get_variable (' openblas_config' ))
276
+ conf_data.set(name + ' _PCFILEDIR' , dep.get_variable (' pcfiledir' ))
277
+ endif
205
278
endif
206
279
endforeach
207
280
0 commit comments