aboutsummaryrefslogtreecommitdiff
path: root/meson.build
blob: 33be57c629df7f56cd34283f3ec23123e4bad643 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
project('cmocka', 'c',
	version : '1.1.5',
	license : 'Apache-2.0')

cc = meson.get_compiler('c')

conf = configuration_data()

foreach hdr : ['assert.h', 'inttypes.h', 'io.h', 'malloc.h', 'memory.h',
	       'setjmp.h', 'signal.h', 'stdarg.h', 'stddef.h', 'stdint.h',
	       'stdio.h', 'stdlib.h', 'string.h', 'strings.h', 'sys/stat.h',
	       'sys/types.h', 'time.h', 'unistd.h']
  conf.set('HAVE_@0@'.format(hdr.underscorify().to_upper()), cc.has_header(hdr))
endforeach

code = '''#include <time.h>
int a = sizeof(struct timespec);
'''
conf.set('HAVE_STRUCT_TIMESPEC', cc.compiles(code, name : 'struct timepec'))

foreach func: ['calloc', 'exit', 'fprintf', 'free', 'longjmp', 'siglongjmp',
	       'malloc', 'memcpy', 'memset', 'printf', 'setjmp', 'signal',
	       'strsignal', 'strcmp', 'clock_gettime']
  conf.set('HAVE_@0@'.format(func.to_upper()), cc.has_function(func))
endforeach

install_lib = true
if meson.is_subproject()
  install_lib = false
endif

code = '__thread int tls;'
conf.set('HAVE_GCC_THREAD_LOCAL_STORAGE', cc.compiles(code, name : '__thread'))

code = '''#include <time.h>
clockid_t t = CLOCK_REALTIME;'''
conf.set('HAVE_CLOCK_REALTIME', cc.compiles(code, name : 'CLOCK_REALTIME'))

configure_file(output : 'config.h', configuration : conf)

cmocka_includes = [include_directories('.'), include_directories('include')]
libcmocka = library('cmocka', 'src/cmocka.c',
                    c_args : ['-DHAVE_CONFIG_H'],
                    include_directories : cmocka_includes,
                    install : install_lib,
                    override_options : ['c_std=gnu99'],
                    dependencies : [cc.find_library('rt', required : false)])

if meson.is_subproject()
  cmocka_dep = declare_dependency(include_directories : cmocka_includes,
                                  link_with : libcmocka)
else
  install_headers('include/cmocka.h')

  pkgconfig = import('pkgconfig')
  pkgconfig.generate(libraries : [libcmocka],
                     version : meson.project_version(),
                     name : 'cmocka',
                     filebase : 'cmocka',
                     description : 'The cmocka unit testing library')
endif

if get_option('unit_testing')
	subdir('tests')
endif