4848 ]
4949endif
5050
51+ macOS13_3_or_later = false
52+ if host_machine .system() == ' darwin'
53+ r = run_command (' xcrun' , ' -sdk' , ' macosx' , ' --show-sdk-version' , check : true )
54+ sdkVersion = r.stdout().strip()
55+
56+ macOS13_3_or_later = sdkVersion.version_compare(' >=13.3' )
57+ endif
5158
5259# This is currently injected directly into CFLAGS/CXXFLAGS for wheel builds
5360# (see cibuildwheel settings in pyproject.toml), but used by CI jobs already
8188# https://github.com/mesonbuild/meson/issues/2835
8289blas_name = get_option (' blas' )
8390lapack_name = get_option (' lapack' )
91+
8492# pkg-config uses a lower-case name while CMake uses a capitalized name, so try
8593# that too to make the fallback detection with CMake work
8694if blas_name == ' openblas'
@@ -90,6 +98,23 @@ if blas_name == 'openblas'
9098 _openblas_names = [' openblas' , ' OpenBLAS' ]
9199 endif
92100 blas = dependency (_openblas_names, required : false )
101+ elif blas_name.to_lower() == ' accelerate'
102+ # macOS 13.3+ has updated interfaces aligned with BLAS/LAPACK 3.9.1. Use them if available.
103+ if macOS13_3_or_later
104+ accelerate_compile_args = [' -DACCELERATE_NEW_LAPACK' ]
105+ if (use_ilp64)
106+ accelerate_compile_args += ' -DACCELERATE_LAPACK_ILP64'
107+ endif
108+ blas = declare_dependency (
109+ compile_args : accelerate_compile_args,
110+ dependencies : dependency (' Accelerate' )
111+ )
112+ else
113+ if (use_ilp64)
114+ error (' macOS SDK 13.3+ is required for ILP64 support.' )
115+ endif
116+ blas = dependency (' Accelerate' )
117+ endif
93118else
94119 blas = dependency (blas_name, required : false )
95120endif
@@ -112,14 +137,22 @@ if have_blas
112137 # `dependency('blas', modules: cblas)`
113138 # see https://github.com/mesonbuild/meson/pull/10921.
114139 have_cblas = false
115- if cc.links('''
140+ if blas_name.to_lower() == ' accelerate'
141+ _cblas_header = ' <Accelerate/Accelerate.h>'
142+ elif blas_name.to_lower().startswith(' mkl' )
143+ _cblas_header = ' <mkl_cblas.h>'
144+ else
145+ _cblas_header = ' <cblas.h>'
146+ endif
147+ if cc.links(f'''
116148 #ifndef BLAS_SYMBOL_SUFFIX
117149 # define BLAS_SYMBOL_SUFFIX
118150 #endif
119151 #define EXPAND(suffix) cblas_ddot ## suffix
120152 #define DDOT(suffix) EXPAND(suffix)
121153
122- #include <cblas.h>
154+ #include @_cblas_header@
155+
123156 int main(int argc, const char *argv[])
124157 {
125158 double a[4] = {1,2,3,4};
@@ -178,9 +211,27 @@ else
178211endif
179212
180213if lapack_name == ' openblas'
181- lapack_name = [' openblas' , ' OpenBLAS' ]
214+ lapack_dep = dependency ([' openblas' , ' OpenBLAS' ], required : false )
215+ elif lapack_name.to_lower() == ' accelerate'
216+ # macOS 13.3+ has updated interfaces aligned with BLAS/LAPACK 3.9.1. Use them if available.
217+ if macOS13_3_or_later
218+ accelerate_compile_args = [' -DACCELERATE_NEW_LAPACK' ]
219+ if (use_ilp64)
220+ accelerate_compile_args += ' -DACCELERATE_LAPACK_ILP64'
221+ endif
222+ lapack_dep = declare_dependency (
223+ compile_args : accelerate_compile_args,
224+ dependencies : dependency (' Accelerate' )
225+ )
226+ else
227+ if (use_ilp64)
228+ error (' macOS SDK 13.3+ is required for ILP64 support.' )
229+ endif
230+ lapack_dep = dependency (' Accelerate' )
231+ endif
232+ else
233+ lapack_dep = dependency (lapack_name, required : false )
182234endif
183- lapack_dep = dependency (lapack_name, required : false )
184235have_lapack = lapack_dep.found()
185236if not have_lapack and not allow_noblas
186237 error (' No LAPACK library detected! Install one, or use the ' + \
0 commit comments