@@ -148,20 +148,32 @@ endforeach
148148# Mandatory functions: if not found, fail the build
149149# Some of these can still be blocklisted if the C99 implementation
150150# is buggy, see numpy/core/src/common/npy_config.h
151- mandatory_funcs = [
151+ mandatory_math_funcs = [
152152 ' sin' , ' cos' , ' tan' , ' sinh' , ' cosh' , ' tanh' , ' fabs' ,
153153 ' floor' , ' ceil' , ' sqrt' , ' log10' , ' log' , ' exp' , ' asin' ,
154154 ' acos' , ' atan' , ' fmod' , ' modf' , ' frexp' , ' ldexp' ,
155155 ' expm1' , ' log1p' , ' acosh' , ' asinh' , ' atanh' ,
156- ' rint' , ' trunc' , ' exp2' ,
157- ' copysign' , ' nextafter' , ' strtoll' , ' strtoull' , ' cbrt' ,
156+ ' rint' , ' trunc' , ' exp2' , ' copysign' , ' nextafter' , ' cbrt' ,
158157 ' log2' , ' pow' , ' hypot' , ' atan2' ,
159- ' csin' , ' csinh' , ' ccos' , ' ccosh' , ' ctan' , ' ctanh' ,
160- ' creal' , ' cimag' , ' conj'
161158]
162- foreach func : mandatory_funcs
163- if not cc.has_function(func)
164- error (' Function `{func}` not found' )
159+ foreach func : mandatory_math_funcs
160+ if not cc.has_function(func, prefix : ' #include <math.h>' , dependencies : m_dep)
161+ error (f' Function `@func@` not found' )
162+ endif
163+ endforeach
164+
165+ mandatory_complex_math_funcs = [
166+ ' csin' , ' csinh' , ' ccos' , ' ccosh' , ' ctan' , ' ctanh' , ' creal' , ' cimag' , ' conj'
167+ ]
168+ foreach func : mandatory_complex_math_funcs
169+ if not cc.has_function(func, prefix : ' #include <complex.h>' , dependencies : m_dep)
170+ error (f' Function `@func@` not found' )
171+ endif
172+ endforeach
173+
174+ foreach func : [' strtoll' , ' strtoull' ]
175+ if not cc.has_function(func, prefix : ' #include <stdlib.h>' )
176+ error (f' Function `@func@` not found' )
165177 endif
166178endforeach
167179
@@ -175,13 +187,13 @@ c99_complex_funcs = [
175187foreach func : c99_complex_funcs
176188 func_single = func + ' f'
177189 func_longdouble = func + ' l'
178- if cc.has_function(func)
190+ if cc.has_function(func, prefix : ' #include <complex.h> ' , dependencies : m_dep )
179191 cdata.set10(' HAVE_' + func.to_upper(), true )
180192 endif
181- if cc.has_function(func_single)
193+ if cc.has_function(func_single, prefix : ' #include <complex.h> ' , dependencies : m_dep )
182194 cdata.set10(' HAVE_' + func_single.to_upper(), true )
183195 endif
184- if cc.has_function(func_longdouble)
196+ if cc.has_function(func_longdouble, prefix : ' #include <complex.h> ' , dependencies : m_dep )
185197 cdata.set10(' HAVE_' + func_longdouble.to_upper(), true )
186198 endif
187199endforeach
@@ -190,7 +202,7 @@ endforeach
190202# libnpymath as a C99 compat layer, these may still be relevant.
191203c99_macros = [' isfinite' , ' isinf' , ' isnan' , ' signbit' ]
192204foreach macro : c99_macros
193- if cc.has_function(macro)
205+ if cc.has_function(macro, prefix : ' #include <math.h> ' , dependencies : m_dep )
194206 cdata.set10(' NPY_HAVE_DECL_' + macro.to_upper(), true )
195207 if not cc.has_header_symbol(' Python.h' , macro, dependencies : py_dep)
196208 # Add in config.h as well, except if it will clash with Python's config.h content
0 commit comments