1 if get_option('native-arch-optimization')
2 check_native_header = true
3 if host_machine.cpu_family() == 'x86' or host_machine.cpu_family() == 'x86_64'
4 native_header = 'immintrin.h'
5 elif host_machine.cpu_family() == 'arm'
6 native_header = 'arm_neon.h'
7 elif host_machine.cpu_family() == 'aarch64'
8 native_header = 'arm_neon.h'
9 elif host_machine.cpu_family() == 'ppc' or host_machine.cpu_family() == 'ppc64'
10 native_header = 'altivec.h'
12 check_native_header = false
15 if check_native_header
16 if cc.has_header(native_header) == false
17 error('Error, header '+native_header+' is required')
20 config_h.set10('HAVE_'+native_header.underscorify().to_upper(), true)
59 #### The below is logically broken
60 #### the declaration of symbol + headers when you look the symbols up
61 #### in man pages you'll find that, for example, kevent needs you to
62 #### include ALL of the headers listed below. same for setxattr,
63 #### listxattr, pthread_getcpuclockid ... i stopped looking at this
64 #### point because it seems this is the pattern, but the foreach below
65 #### does not do this. it includes one header at a time from the list
66 #### then checks to see if the symbol exists. this leads to failures
67 #### in the checks (specifically i noticed kevent on bsd). so the whole
68 #### construct for this is wrong. it needs a rethink. i'm putting this
69 #### comment here as a note that this is the case for now as i'm just
70 #### trying to fix the meson build on freebsd for now
73 # function name | headers that are needed | libraries to include | Defines that are needed
74 ['alloca', ['alloca.h']],
75 ['backtrace', ['execinfo.h']],
76 ['backtrace_symbols', ['execinfo.h']],
77 ['chown', ['unistd.h']],
78 ['clock_gettime', ['time.h']],
79 ['dirfd', ['dirent.h sys/types.h']],
80 ['fchmod', ['sys/stat.h']],
81 ['fcntl', ['fcntl.h']],
82 ['fork', ['unistd.h']],
83 ['fpathconf', ['unistd.h']],
84 ['geteuid', ['unistd.h']],
85 ['getpagesize', ['unistd.h']],
86 ['getpwent', ['sys/types.h', 'pwd.h']],
87 #['getuid', ['unistd.h']],
88 ['getxattr', ['sys/types.h', 'sys/xattr.h']],
89 ['iconv', ['iconv.h']],
90 ['listxattr', ['sys/types.h', 'sys/xattr.h']],
91 ['malloc_info', ['malloc.h']],
92 ['malloc_usable_size', ['malloc.h']],
93 ['mkdirat', ['sys/stat.h']],
94 ['mmap', ['sys/mman.h']],
95 ['mtrace', ['mcheck.h']],
96 ['prctl', ['sys/prctl.h']],
97 ['procctl', ['sys/procctl.h']],
98 ['realpath', ['stdlib.h']],
99 ['setxattr', ['sys/types.h', 'sys/xattr.h']],
100 ['siglongjmp', ['setjmp.h']],
101 ['strerror_r', ['string.h']],
102 ['gettimeofday', ['sys/time.h']],
103 ['execvp', ['unistd.h']],
104 ['pause', ['unistd.h']],
105 ['isfinite', ['math.h']],
106 #FIXME strlcpy is detected by meson but drops at compilation time
107 # ['strlcpy', ['string.h']],
108 ['siginfo_t', ['signal.h']],
109 ['pthread_getcpuclockid', ['pthread.h', 'time.h']],
110 ['timerfd_create', ['sys/timerfd.h']],
111 ['kevent', ['sys/types.h', 'sys/event.h', 'sys/time.h']],
112 #from here on we specify the dependencies
113 ['dlopen', ['dlfcn.h'], ['dl']],
114 ['dlsym', ['dlfcn.h'], ['dl']],
115 ['lround', ['math.h'], ['m']],
116 ['mallinfo', ['malloc.h'], ['malloc']],
117 ['shm_open', ['sys/mman.h', 'sys/stat.h', 'fcntl.h'], ['rt']],
118 #from here on we specify arguments
119 ['splice', ['fcntl.h'], [], '-D_GNU_SOURCE=1'],
120 ['sched_getcpu', ['sched.h'], [], '-D_GNU_SOURCE=1'],
121 ['dladdr', ['dlfcn.h'], ['dl'], '-D_GNU_SOURCE=1']
124 open_cloexec = cc.compiles('''#include <sys/types.h>
125 #include <sys/stat.h>
127 int main(int argc, char **argv) {
128 int res = open(argv[0], O_RDONLY | O_CLOEXEC);
129 if (res < 0) return 1;
133 name : 'open works with O_CLOEXEC')
135 config_h.set10('HAVE_OPEN_CLOEXEC', true)
138 strerror_r_char_p = cc.compiles('''#define _GNU_SOURCE
142 char error_string[256];
143 char *ptr = strerror_r (-2, error_string, 256);
144 char c = *strerror_r (-2, error_string, 256);
145 return c != 0 && ptr != (void*) 0L;
148 name : 'strerror_r() returns char *')
151 config_h.set('STRERROR_R_CHAR_P', '1')
154 #for later use, a bunch of librarie findings
155 m = cc.find_library('m')
156 #just keep this here as required false, if it is not inplace the library rt will just be linked as NOP
157 dl = cc.find_library('dl', required: false)
158 rt = cc.find_library('rt', required: false)
161 malloc = cc.find_library('malloc', required: true)
162 socket = cc.find_library('socket', required: true)
165 #thread_dep = dependency('threads')
166 thread_dep = cc.find_library('pthread')
168 #check for the headers
169 foreach header : header_checks
170 if cc.has_header(header)
171 config_h.set10('HAVE_'+header.underscorify().to_upper(), true)
175 foreach function : function_checks
176 function_name = function[0]
177 headers_to_search = function[1]
181 # if there is a library, make sure they exist
182 if function.length() > 2
183 foreach library : function[2]
184 lib = cc.find_library(library, required : false)
185 if lib.found() == true
191 #check if there are args
192 if function.length() > 3
196 # Only check the header if the dependencies are ready
197 foreach header : headers_to_search
198 if cc.has_header_symbol(header, function_name,
199 dependencies : dependencies,
201 config_h.set10('HAVE_'+function_name.to_upper(), true)
206 # The next checks are manually for now due to the fact that some names are not within the default pattern
207 if (cc.has_header_symbol('sys/stat.h', 'fstatat'))
208 config_h.set10('HAVE_ATFILE_SOURCE', true)
211 if sys_linux and config_h.has('HAVE_LISTXATTR') and config_h.has('HAVE_SETXATTR') and config_h.has('HAVE_GETXATTR')
212 config_h.set10('HAVE_XATTR', true)
216 if sys_windows == true
217 regexp = cc.find_library('regex',
218 has_headers: ['regex.h', 'fnmatch.h'],
220 if regexp.found() == false
221 error('regex can not be found')
224 if cc.has_header_symbol('fnmatch.h', 'fnmatch') == false
225 error('fnmatch can not be found')
227 if cc.has_header_symbol('regex.h', 'regcomp') == false
228 error('regcomp can not be found')
232 config_h.set('VMAJ', version_major)
233 config_h.set('VMIN', version_minor)
234 config_h.set('VMIC', version_micro)
235 config_h.set('VREV', '0')
237 #jpeg detection ... life is a bit more complex there
239 jpeg = dependency('libjpeg', required: false)
240 if jpeg.found() == false
241 jpeg = cc.find_library('jpeg')
245 config_h.set('HAVE_NOTIFY_KEVENT', '1')
249 config_h.set('HAVE_NOTIFY_COCOA', '1')
251 config_h.set('SIZEOF_INT', cc.sizeof('int'))
252 config_h.set('SIZEOF_LONG', cc.sizeof('long'))
254 if sys_windows == true
255 config_h.set('HAVE_NOTIFY_WIN32', '1')
256 config_h.set10('HAVE_DDRAW_H', true)