meson: introduce to meson build system
[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 thread_dep = cc.find_library('pthread')
148
149 #check for the headers
150 foreach header : header_checks
151   if cc.has_header(header)
152     config_h.set10('HAVE_'+header.underscorify().to_upper(), true)
153   endif
154 endforeach
155
156 foreach function : function_checks
157   function_name = function[0]
158   headers_to_search = function[1]
159   dependencies = []
160   args = []
161
162   # if there is a library, make sure they exist
163   if function.length() > 2
164     foreach library : function[2]
165       lib = cc.find_library(library, required : false)
166       if lib.found() == true
167         dependencies += lib
168       endif
169     endforeach
170   endif
171
172   #check if there are args
173   if function.length() > 3
174     args = function[3]
175   endif
176
177   # Only check the header if the dependencies are ready
178   foreach header : headers_to_search
179     if cc.has_header_symbol(header, function_name,
180         dependencies : dependencies,
181         args : args)
182       config_h.set10('HAVE_'+function_name.to_upper(), true)
183     endif
184   endforeach
185 endforeach
186
187 # The next checks are manually for now due to the fact that some names are not within the default pattern
188 if (cc.has_header_symbol('sys/stat.h', 'fstatat'))
189   config_h.set10('HAVE_ATFILE_SOURCE', true)
190 endif
191
192 if (cc.has_header('sys/mman.h'))
193   config_h.set10('HAVE_MMAN_H', true)
194 endif
195
196 config_h.set('VMAJ', version_major)
197 config_h.set('VMIN', version_minor)
198 config_h.set('VMIC', version_micro)
199 config_h.set('VREV', '0')
200
201 #jpeg detection ... life is a bit more complex there 
202
203 jpeg = dependency('libjpeg', required: false)
204 if jpeg.found() == false
205   jpeg = cc.find_library('jpeg')
206 endif
207
208 if sys_bsd == true
209   config_h.set('HAVE_NOTIFY_KEVENT', '1')
210 endif
211
212 if sys_osx == true
213   config_h.set('HAVE_NOTIFY_COCOA', '1')
214 endif
215 config_h.set('SIZEOF_INT', cc.sizeof('int'))
216 config_h.set('SIZEOF_LONG', cc.sizeof('long'))
217
218 if sys_windows == true
219   config_h.set('HAVE_DLSYM', '1')
220   config_h.set('HAVE_NOTIFY_WIN32', '1')
221 endif