1 project('p11-kit', 'c',
3 meson_version: '>= 0.49')
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()
10 cc = meson.get_compiler('c')
16 soversion = current - age
17 library_version = '@0@.@1@.@2@'.format(soversion, age, revision)
19 configinc = include_directories('.')
20 commoninc = include_directories('common')
21 p11kitinc = include_directories('p11-kit')
22 trustinc = include_directories('trust')
24 add_project_arguments(['-D_GNU_SOURCE', '-DP11_KIT_FUTURE_UNSTABLE_API'],
27 conf = configuration_data()
29 conf.set('PACKAGE_MAJOR', major_version)
30 conf.set('PACKAGE_MINOR', minor_version)
32 host_system = host_machine.system()
33 conf.set(host_system == 'windows' ? 'OS_WIN32' : 'OS_UNIX', 1)
35 if host_system == 'windows'
43 conf.set_quoted('SHLEXT', shlext)
44 conf.set_quoted('EXEEXT', exeext)
46 if get_option('debug')
47 conf.set('WITH_DEBUG', 1)
51 conf.set10('WITH_STRICT', get_option('strict'))
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()
64 '-DBINDIR="@0@"'.format(prefix / bindir),
65 '-DPRIVATEDIR="@0@"'.format(prefix / privatedir),
66 '-DSYSCONFDIR="@0@"'.format(prefix / sysconfdir)
69 top_source_dir = meson.current_source_dir()
70 top_build_dir = meson.current_build_dir()
73 '-DSRCDIR="@0@"'.format(top_source_dir),
74 '-DBUILDDIR="@0@"'.format(top_build_dir)
77 conf.set('SIZEOF_UNSIGNED_LONG', cc.sizeof('unsigned long'))
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')
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
95 error('could not find nanosleep')
99 if not cc.has_function('dlopen')
100 libdl = cc.find_library('dl', required: false)
101 if cc.has_function('dlopen', dependencies: libdl)
104 error('could not find dlopen')
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)
112 if cc.has_function('gethostbyname', dependencies: libnsl)
113 socket_deps += libnsl
116 libsocket = cc.find_library('socket', required: false)
118 if cc.has_function('connect', dependencies: [libsocket, libnsl])
119 socket_deps += libsocket
121 error('could not find socket')
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)
133 if cc.has_function('strerror_l', prefix: '#include <string.h>')
134 conf.set('HAVE_STRERROR_L', 1)
139 # These are things we can work around
147 conf.set('HAVE_' + h.underscorify().to_upper(), 1)
166 foreach f : functions
167 if cc.has_function(f)
168 conf.set('HAVE_' + f.underscorify().to_upper(), 1)
172 if cc.has_member('struct dirent', 'd_type', prefix: '#include <dirent.h>')
173 conf.set('HAVE_STRUCT_DIRENT_D_TYPE', 1)
176 tls_test_code_template = '''
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)
191 if cc.has_function('gmtime_r')
192 conf.set('HAVE_GMTIME_R', 1)
194 error('could not find required gmtime_r() function')
197 # Check if these are declared and/or available to link against
198 program_invocation_short_name_test_code = '''
201 int main (void) { program_invocation_short_name = "test"; }
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)
207 __progname_test_code = '''
208 extern char *__progname;
209 int main (void) { __progname = (char*)0; return 0; }
211 if cc.links(__progname_test_code, name: '__progname')
212 conf.set('HAVE___PROGNAME', 1)
216 __libc_enable_secure_test_code = '''
217 extern int __libc_enable_secure;
218 int main (void) { __libc_enable_secure = 0; return 0; }
220 if cc.links(__libc_enable_secure_test_code, name: '__libc_enable_secure')
221 conf.set('HAVE___LIBC_ENABLE_SECURE', 1)
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()
246 foreach f : functions
247 if cc.has_function(f)
248 conf.set('HAVE_' + f.underscorify().to_upper(), 1)
252 conf.set10('HAVE_DECL_ASPRINTF',
253 cc.has_header_symbol('stdio.h', 'asprintf',
254 prefix: '#define _GNU_SOURCE'))
256 conf.set10('HAVE_DECL_VASPRINTF',
257 cc.has_header_symbol('stdio.h', 'vasprintf',
258 prefix: '#define _GNU_SOURCE'))
260 conf.set10('HAVE_DECL_REALLOCARRAY',
261 cc.has_header_symbol('stdlib.h', 'reallocarray'))
263 # --------------------------------------------------------------------
267 libffi = dependency('libffi', version: '>= 3.0.0', required: get_option('libffi'))
269 conf.set('WITH_FFI', 1)
270 libffi_deps += libffi
273 closures = get_option('closures')
275 error('at least one closure must be compiled in')
278 conf.set('P11_VIRTUAL_MAX_FIXED', closures)
280 # ------------------------------------------------------------------------------
281 # PKCS#11 Directories
283 p11_package_config_modules = get_option('module_config')
284 if p11_package_config_modules == ''
285 p11_package_config_modules = pkgdatadir / 'modules'
288 p11_system_config = get_option('system_config')
289 if p11_system_config == ''
290 p11_system_config = sysconfdir / 'pkcs11'
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'
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'
304 # --------------------------------------------------------------------
305 # Hash implementation
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)
314 error('could not find the freebl3 library')
318 # --------------------------------------------------------------------
321 with_trust_module = false
323 libtasn1 = dependency('libtasn1', version: '>= 2.3',
324 required: get_option('trust_module'))
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
334 trust_paths = get_option('trust_paths')
335 conf.set_quoted('TRUST_PATHS', trust_paths)
337 # --------------------------------------------------------------------
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
351 configure_file(output: 'config.h', configuration: conf)
353 gnome = import('gnome')
354 i18n = import('i18n')
355 pkg = import('pkgconfig')
364 subdir('bash-completion')