c77ad94c34adf523bac41f7483dc6038bb1f9ec1
[platform/upstream/efl.git] / header_checks / meson.build
1 if get_option('native-arch-optimization')
2   if host_machine.cpu_family() == 'x86' or host_machine.cpu_family() == 'x86_64'
3     native_header = 'immintrin.h'
4   elif host_machine.cpu_family() == 'arm'
5     native_header = 'arm_neon.h'
6   elif host_machine.cpu_family() == 'aarch64'
7     native_header = 'arm_neon.h'
8   elif host_machine.cpu_family() == 'ppc' or host_machine.cpu_family() == 'ppc64'
9     native_header = 'altivec.h'
10   endif
11
12   if cc.has_header(native_header) == false
13     error('Error, header '+native_header+' is required')
14   endif
15
16   config_h.set10('HAVE_'+native_header.underscorify().to_upper(), true)
17 endif
18
19 header_checks = [
20   'alloca.h',
21   'asm/hwcap.h',
22   'bsd/string.h',
23   'dirent.h',
24   'execinfo.h',
25   'mcheck.h',
26   'netinet/in.h',
27   'netinet/ssl.h',
28   'netinet/tcp.h',
29   'netinet/udp.h',
30   'net/if.h',
31   'stdlib.h',
32   'mman.h',
33   'sys/auxv.h',
34   'sys/inotify.h',
35   'sys/ioctl.h',
36   'sys/mman.h',
37   'sys/types.h',
38   'sys/socket.h',
39   'sys/filio.h',
40   'arpa/inet.h',
41   'sys/epoll.h',
42   'sys/un.h',
43   'sys/wait.h',
44   'sys/resource.h',
45   'sys/times.h',
46   'dirent.h',
47   'longinfo.h',
48   'exotic.h',
49   'ieeefp.h',
50   'node/uv.h',
51   'sys/timerfd.h',
52   'features.h',
53   'langinfo.h',
54   'locale.h',
55   'uv.h',
56   'ws2tcpip.h',
57   'crt_externs.h'
58 ]
59
60 #### The below is logically broken
61 #### the declaration of symbol + headers when you look the symbols up
62 #### in man pages you'll find that, for example, kevent needs you to
63 #### include ALL of the headers listed below. same for setxattr,
64 #### listxattr, pthread_getcpuclockid ... i stopped looking at this
65 #### point because it seems this is the pattern, but the foreach below
66 #### does not do this. it includes one header at a time from the list
67 #### then checks to see if the symbol exists. this leads to failures
68 #### in the checks (specifically i noticed kevent on bsd). so the whole
69 #### construct for this is wrong. it needs a rethink. i'm putting this
70 #### comment here as a note that this is the case for now as i'm just
71 #### trying to fix the meson build on freebsd for now
72
73 function_checks = [
74 # function name | headers that are needed | libraries to include | Defines that are needed
75   ['alloca', ['alloca.h']],
76   ['backtrace', ['execinfo.h']],
77   ['backtrace_symbols', ['execinfo.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   ['mallinfo', ['malloc.h']],
92   ['malloc_info', ['malloc.h']],
93   ['malloc_usable_size', ['malloc.h']],
94   ['mkdirat', ['sys/stat.h']],
95   ['mmap', ['sys/mman.h']],
96   ['mtrace', ['mcheck.h']],
97   ['prctl', ['sys/prctl.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   ['strerror_r', ['string.h']],
110   ['pthread_getcpuclockid', ['pthread.h', 'time.h']],
111   ['timerfd_create', ['sys/timerfd.h']],
112   ['kevent', ['sys/types.h', 'sys/event.h', 'sys/time.h']],
113 #from here on we specify the dependencies
114   ['dlopen', ['dlfcn.h'],                               ['dl']],
115   ['dlsym', ['dlfcn.h'],                                ['dl']],
116   ['lround', ['math.h'],                                ['m']],
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']
122 ]
123
124 strerror_r_char_p = cc.compiles('''#define _GNU_SOURCE
125                   #include <string.h>
126                   int func (void)
127                     {
128                        char error_string[256];
129                        char *ptr = strerror_r (-2, error_string, 256);
130                        char c = *strerror_r (-2, error_string, 256);
131                        return c != 0 && ptr != (void*) 0L;
132                     }
133                  ''',
134                  name : 'strerror_r() returns char *')
135
136 if strerror_r_char_p
137   config_h.set('STRERROR_R_CHAR_P', '1')
138 endif
139
140 #for later use, a bunch of librarie findings
141 m = cc.find_library('m')
142 #just keep this here as required false, if it is not inplace the library rt will just be linked as NOP
143 dl = cc.find_library('dl', required: false)
144 rt = cc.find_library('rt', required: false)
145
146 thread_dep = dependency('threads')
147
148 #check for the headers
149 foreach header : header_checks
150   if cc.has_header(header)
151     config_h.set10('HAVE_'+header.underscorify().to_upper(), true)
152   endif
153 endforeach
154
155 foreach function : function_checks
156   function_name = function[0]
157   headers_to_search = function[1]
158   dependencies = []
159   args = []
160
161   # if there is a library, make sure they exist
162   if function.length() > 2
163     foreach library : function[2]
164       lib = cc.find_library(library, required : false)
165       if lib.found() == true
166         dependencies += lib
167       endif
168     endforeach
169   endif
170
171   #check if there are args
172   if function.length() > 3
173     args = function[3]
174   endif
175
176   # Only check the header if the dependencies are ready
177   foreach header : headers_to_search
178     if cc.has_header_symbol(header, function_name,
179         dependencies : dependencies,
180         args : args)
181       config_h.set10('HAVE_'+function_name.to_upper(), true)
182     endif
183   endforeach
184 endforeach
185
186 # The next checks are manually for now due to the fact that some names are not within the default pattern
187 if (cc.has_header_symbol('sys/stat.h', 'fstatat'))
188   config_h.set10('HAVE_ATFILE_SOURCE', true)
189 endif
190
191 if (cc.has_header('sys/mman.h'))
192   config_h.set10('HAVE_MMAN_H', true)
193 endif
194
195 config_h.set('VMAJ', version_major)
196 config_h.set('VMIN', version_minor)
197 config_h.set('VMIC', version_micro)
198 config_h.set('VREV', '0')
199
200 #jpeg detection ... life is a bit more complex there 
201
202 jpeg = dependency('libjpeg', required: false)
203 if jpeg.found() == false
204   jpeg = cc.find_library('jpeg')
205 endif
206
207 if sys_bsd == true
208   config_h.set('HAVE_NOTIFY_KEVENT', '1')
209 endif
210
211 if sys_osx == true
212   config_h.set('HAVE_NOTIFY_COCOA', '1')
213 endif
214 config_h.set('SIZEOF_INT', cc.sizeof('int'))
215 config_h.set('SIZEOF_LONG', cc.sizeof('long'))
216
217 if sys_windows == true
218   config_h.set('HAVE_DLSYM', '1')
219   config_h.set('HAVE_NOTIFY_WIN32', '1')
220 endif