]> granicus.if.org Git - p11-kit/blob - meson.build
Fix RPC calls: ATTRIBUTE buf not null but length 0
[p11-kit] / meson.build
1 project('p11-kit', 'c',
2         version: '0.23.18',
3         meson_version: '>= 0.49')
4
5 version_arr = meson.project_version().split('.')
6 major_version = version_arr[0].to_int()
7 minor_version = version_arr[1].to_int()
8 micro_version = version_arr[2].to_int()
9
10 cc = meson.get_compiler('c')
11
12 current = 3
13 revision = 0
14 age = 3
15
16 soversion = current - age
17 library_version = '@0@.@1@.@2@'.format(soversion, age, revision)
18
19 configinc = include_directories('.')
20 commoninc = include_directories('common')
21 p11kitinc = include_directories('p11-kit')
22 trustinc = include_directories('trust')
23
24 add_project_arguments(['-D_GNU_SOURCE', '-DP11_KIT_FUTURE_UNSTABLE_API'],
25                       language: 'c')
26
27 conf = configuration_data()
28
29 conf.set('PACKAGE_MAJOR', major_version)
30 conf.set('PACKAGE_MINOR', minor_version)
31
32 host_system = host_machine.system()
33 conf.set(host_system == 'windows' ? 'OS_WIN32' : 'OS_UNIX', 1)
34
35 if host_system == 'windows'
36   shlext = '.dll'
37   exeext = '.exe'
38 else
39   shlext = '.so'
40   exeext = ''
41 endif
42
43 conf.set_quoted('SHLEXT', shlext)
44 conf.set_quoted('EXEEXT', exeext)
45
46 if get_option('debug')
47   conf.set('WITH_DEBUG', 1)
48   conf.set('_DEBUG', 1)
49 endif
50
51 conf.set10('WITH_STRICT', get_option('strict'))
52
53 prefix = get_option('prefix')
54 datadir = get_option('datadir')
55 bindir = get_option('bindir')
56 libdir = get_option('libdir')
57 libexecdir = get_option('libexecdir')
58 sysconfdir = get_option('sysconfdir')
59 mandir = get_option('mandir')
60 pkgdatadir = datadir / meson.project_name()
61 privatedir = libexecdir / meson.project_name()
62
63 common_c_args = [
64   '-DBINDIR="@0@"'.format(prefix / bindir),
65   '-DPRIVATEDIR="@0@"'.format(prefix / privatedir),
66   '-DSYSCONFDIR="@0@"'.format(prefix / sysconfdir)
67 ]
68
69 top_source_dir = meson.current_source_dir()
70 top_build_dir = meson.current_build_dir()
71
72 tests_c_args = [
73   '-DSRCDIR="@0@"'.format(top_source_dir),
74   '-DBUILDDIR="@0@"'.format(top_build_dir)
75 ]
76
77 conf.set('SIZEOF_UNSIGNED_LONG', cc.sizeof('unsigned long'))
78
79 nanosleep_deps = []
80 dlopen_deps = []
81 socket_deps = []
82 thread_deps = []
83
84 if host_system != 'windows'
85   thread_deps += dependency('threads')
86   if not cc.has_function('pthread_create', dependencies: thread_deps)
87     error('could not find pthread_create')
88   endif
89
90   if not cc.has_function('nanosleep')
91     librt = cc.find_library('rt', required: false)
92     if cc.has_function('nanosleep', dependencies: librt)
93       nanosleep_deps += librt
94     else
95       error('could not find nanosleep')
96     endif
97   endif
98
99   if not cc.has_function('dlopen')
100     libdl = cc.find_library('dl', required: false)
101     if cc.has_function('dlopen', dependencies: libdl)
102       dlopen_deps += libdl
103     else
104       error('could not find dlopen')
105     endif
106   endif
107
108   # for Solaris we need -lsocket -lnsl for socket stuff, gethostbyname
109   # is just a dummy to find -lnsl
110   libnsl = cc.find_library('nsl', required: false)
111   if libnsl.found()
112     if cc.has_function('gethostbyname', dependencies: libnsl)
113       socket_deps += libnsl
114     endif
115
116     libsocket = cc.find_library('socket', required: false)
117     if libsocket.found()
118       if cc.has_function('connect', dependencies: [libsocket, libnsl])
119         socket_deps += libsocket
120       else
121         error('could not find socket')
122       endif
123     endif
124   endif
125
126   if cc.has_header('locale.h')
127     conf.set('HAVE_LOCALE_H', 1)
128     if cc.has_header_symbol('locale.h', 'locale_t')
129       conf.set('HAVE_LOCALE_T', 1)
130       if cc.has_function('newlocale', prefix: '#include <locale.h>')
131         conf.set('HAVE_NEWLOCALE', 1)
132       endif
133       if cc.has_function('strerror_l', prefix: '#include <string.h>')
134         conf.set('HAVE_STRERROR_L', 1)
135       endif
136     endif
137   endif
138
139   # These are things we can work around
140   headers = [
141     'sys/resource.h',
142     'ucred.h'
143   ]
144
145   foreach h : headers
146     if cc.has_header(h)
147       conf.set('HAVE_' + h.underscorify().to_upper(), 1)
148     endif
149   endforeach
150
151   functions = [
152     'fdwalk',
153     'getauxval',
154     'getexecname',
155     'getpeereid',
156     'getpeerucred',
157     'getprogname',
158     'getresuid',
159     'issetugid',
160     'mkdtemp',
161     'mkstemp',
162     'secure_getenv',
163     'strndup'
164   ]
165
166   foreach f : functions
167     if cc.has_function(f)
168       conf.set('HAVE_' + f.underscorify().to_upper(), 1)
169     endif
170   endforeach
171
172   if cc.has_member('struct dirent', 'd_type', prefix: '#include <dirent.h>')
173     conf.set('HAVE_STRUCT_DIRENT_D_TYPE', 1)
174   endif
175
176   tls_test_code_template = '''
177 #include <stdlib.h>
178 int main (void) {
179 static @0@ foo;
180 return 0;
181 }
182 '''
183   foreach keyword : ['_Thread_local', '__thread']
184     if cc.compiles(tls_test_code_template.format(keyword),
185                    name: 'thread-local storage class')
186       conf.set('P11_TLS_KEYWORD', keyword)
187       break
188     endif
189   endforeach
190
191   if cc.has_function('gmtime_r')
192     conf.set('HAVE_GMTIME_R', 1)
193   else
194     error('could not find required gmtime_r() function')
195   endif
196
197   # Check if these are declared and/or available to link against
198   program_invocation_short_name_test_code = '''
199 #define _GNU_SOURCE
200 #include <errno.h>
201 int main (void) { program_invocation_short_name = "test"; }
202 '''
203   if cc.links(program_invocation_short_name_test_code,
204               name: 'program_invocation_short_name_test_code')
205     conf.set('HAVE_PROGRAM_INVOCATION_SHORT_NAME', 1)
206   else
207     __progname_test_code = '''
208 extern char *__progname;
209 int main (void) { __progname = (char*)0; return 0; }
210 '''
211     if cc.links(__progname_test_code, name: '__progname')
212       conf.set('HAVE___PROGNAME', 1)
213     endif
214   endif
215
216   __libc_enable_secure_test_code = '''
217 extern int __libc_enable_secure;
218 int main (void) { __libc_enable_secure = 0; return 0; }
219 '''
220   if cc.links(__libc_enable_secure_test_code, name: '__libc_enable_secure')
221     conf.set('HAVE___LIBC_ENABLE_SECURE', 1)
222   endif
223
224   foreach h : ['sys/types.h', 'signal.h']
225     foreach t : ['sighandler_t', 'sig_t', '__sighandler_t']
226       if cc.has_header_symbol(h, t)
227         define = 'HAVE_' + t.underscorify().to_upper()
228         conf.set(define, 1)
229       endif
230     endforeach
231   endforeach
232 endif
233
234 functions = [
235   'asprintf',
236   'basename',
237   'memdup',
238   'reallocarray',
239   'secure_getenv',
240   'setenv',
241   'strerror_r',
242   'strnstr',
243   'vasprintf'
244 ]
245
246 foreach f : functions
247   if cc.has_function(f)
248     conf.set('HAVE_' + f.underscorify().to_upper(), 1)
249   endif
250 endforeach
251
252 conf.set10('HAVE_DECL_ASPRINTF',
253            cc.has_header_symbol('stdio.h', 'asprintf',
254                                 prefix: '#define _GNU_SOURCE'))
255
256 conf.set10('HAVE_DECL_VASPRINTF',
257            cc.has_header_symbol('stdio.h', 'vasprintf',
258                                 prefix: '#define _GNU_SOURCE'))
259
260 conf.set10('HAVE_DECL_REALLOCARRAY',
261            cc.has_header_symbol('stdlib.h', 'reallocarray'))
262
263 # --------------------------------------------------------------------
264 # libffi
265
266 libffi_deps = []
267 libffi = dependency('libffi', version: '>= 3.0.0', required: get_option('libffi'))
268 if libffi.found()
269   conf.set('WITH_FFI', 1)
270   libffi_deps += libffi
271 endif
272
273 closures = get_option('closures')
274 if closures < 1
275   error('at least one closure must be compiled in')
276 endif
277
278 conf.set('P11_VIRTUAL_MAX_FIXED', closures)
279
280 # ------------------------------------------------------------------------------
281 # PKCS#11 Directories
282
283 p11_package_config_modules = get_option('module_config')
284 if p11_package_config_modules == ''
285   p11_package_config_modules = pkgdatadir / 'modules'
286 endif
287
288 p11_system_config = get_option('system_config')
289 if p11_system_config == ''
290   p11_system_config = sysconfdir / 'pkcs11'
291 endif
292
293 p11_user_config = get_option('user_config')
294 p11_module_path = get_option('module_path')
295 if p11_module_path == ''
296   p11_module_path = libdir / 'pkcs11'
297 endif
298
299 p11_system_config_file = p11_system_config / 'pkcs11.conf'
300 p11_system_config_modules = p11_system_config / 'modules'
301 p11_user_config_file = p11_user_config / 'pkcs11.conf'
302 p11_user_config_modules = p11_user_config / 'modules'
303
304 # --------------------------------------------------------------------
305 # Hash implementation
306
307 hash_impl = get_option('hash_impl')
308 if hash_impl == 'freebl'
309   libfreebl3 = cc.find_library('freebl3', required: false)
310   if libfreebl3.found() and cc.has_function('NSSLOW_Init',
311                                             dependencies: libfreebl3)
312     conf.set('WITH_FREEBL', 1)
313   else
314     error('could not find the freebl3 library')
315   endif
316 endif
317
318 # --------------------------------------------------------------------
319 # Trust Module
320
321 with_trust_module = false
322 libtasn1_deps = []
323 libtasn1 = dependency('libtasn1', version: '>= 2.3',
324                       required: get_option('trust_module'))
325 if libtasn1.found()
326   asn1Parser = find_program('asn1Parser', required: get_option('trust_module'))
327   if asn1Parser.found()
328     conf.set('WITH_ASN1', 1)
329     libtasn1_deps += libtasn1
330     with_trust_module = true
331   endif
332 endif
333
334 trust_paths = get_option('trust_paths')
335 conf.set_quoted('TRUST_PATHS', trust_paths)
336
337 # --------------------------------------------------------------------
338 # systemd
339
340 with_systemd = false
341 libsystemd_deps = []
342 libsystemd = dependency('libsystemd', required: get_option('systemd'))
343 systemd = dependency('systemd', required: get_option('systemd'))
344 if libsystemd.found() and systemd.found()
345   systemduserunitdir = systemd.get_pkgconfig_variable('systemduserunitdir')
346   conf.set('WITH_SYSTEMD', 1)
347   libsystemd_deps += libsystemd
348   with_systemd = true
349 endif
350
351 configure_file(output: 'config.h', configuration: conf)
352
353 gnome = import('gnome')
354 i18n = import('i18n')
355 pkg = import('pkgconfig')
356
357 subdir('common')
358 subdir('p11-kit')
359 if with_trust_module
360   subdir('trust')
361 endif
362 subdir('doc/manual')
363 subdir('po')
364 subdir('bash-completion')