-
Notifications
You must be signed in to change notification settings - Fork 25
/
meson.build
201 lines (175 loc) · 4.58 KB
/
meson.build
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
project(
'libmctp', 'c',
meson_version: '>= 1.1',
version: '0.11',
default_options: [
'debug=true',
'optimization=g',
'warning_level=2',
'werror=true',
'tests=' + (meson.is_subproject() ? 'disabled' : 'enabled'),
],
)
sources = [
'core.c',
'alloc.c',
'control.c',
]
headers = [
'libmctp.h',
]
serial_sources = [
'serial.c',
'crc-16-ccitt.c',
]
serial_headers = [
'libmctp-serial.h'
]
astlpc_sources = [
'astlpc.c',
'crc32.c',
]
astlpc_headers = [
'libmctp-astlpc.h',
]
i2c_sources = [
'i2c.c',
]
i2c_headers = [
'libmctp-i2c.h',
]
control_sources = [
'control.c',
]
libmctp_sources = sources
libmctp_headers = headers
if get_option('bindings').contains('serial')
libmctp_sources += serial_sources
libmctp_headers += serial_headers
endif
if get_option('bindings').contains('astlpc')
libmctp_sources += astlpc_sources
libmctp_headers += astlpc_headers
endif
if get_option('bindings').contains('i2c')
libmctp_sources += i2c_sources
libmctp_headers += i2c_headers
endif
if get_option('control')
libmctp_sources += control_sources
endif
compiler = meson.get_compiler('c')
if not get_option('custom_alloc') and get_option('default_alloc').require(
compiler.links('''
#include <stdlib.h>
void main()
{
free(malloc(4096));
}
''')).allowed()
add_project_arguments('-DMCTP_DEFAULT_ALLOC', language : 'c')
endif
if get_option('custom_alloc')
add_project_arguments('-DMCTP_CUSTOM_ALLOC', language : 'c')
endif
if get_option('nolog')
add_project_arguments('-DMCTP_NOLOG', language : 'c')
else
libmctp_sources += ['log.c']
endif
feat_fileio = get_option('fileio').require(
compiler.links('''
#include <poll.h>
#include <unistd.h>
void main()
{
poll(NULL, 0, -1);
}
'''))
if feat_fileio.allowed()
add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c')
endif
if get_option('syslog').require(
compiler.links('''
#include <stdarg.h>
#include <syslog.h>
void check_vsyslog(int level, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vsyslog(0, fmt, ap);
va_end(ap);
}
void main()
{
check_vsyslog(0, "\n");
}
''')).allowed()
add_project_arguments('-DMCTP_HAVE_SYSLOG', language : 'c')
endif
if get_option('stdio').require(
compiler.links('''
#include <stdarg.h>
#include <stdio.h>
void check_vsyslog(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
}
void main()
{
check_vsyslog("\n");
}
''')).allowed()
add_project_arguments('-DMCTP_HAVE_STDIO', language : 'c')
endif
# pcap is necessary for mctp-demux-daemon to be functional
pcap_dep = dependency('libpcap', required: false)
systemd_dep = dependency('systemd', required: false)
libsystemd_dep = dependency('libsystemd', required: false)
libmctp_include_dir = include_directories('.', is_system: true)
libmctp = library('mctp',
libmctp_sources,
include_directories: libmctp_include_dir,
version: meson.project_version(),
install: true,
)
install_headers(libmctp_headers)
if systemd_dep.found()
unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir')
install_data('systemd/system/mctp-demux.service', install_dir: unitdir)
install_data('systemd/system/mctp-demux.socket', install_dir: unitdir)
endif
import('pkgconfig').generate(libmctp,
name: 'libmctp',
description: 'MCTP protocol implementation',
version: meson.project_version(),
)
libmctp_dep = declare_dependency(
include_directories: libmctp_include_dir,
link_with: libmctp,
)
# TODO: these should depend on the -internal.h headers so they rebuild
# on changes, unclear how to do that.
sizeof_mctp = compiler.sizeof('struct mctp',
include_directories: libmctp_include_dir,
prefix: '#include "core-internal.h"')
sizeof_binding_i2c = compiler.sizeof('struct mctp_binding_i2c',
include_directories: libmctp_include_dir,
prefix: '#include "i2c-internal.h"')
sizes_h = configure_file(configuration: {
'sizeof_struct_mctp': sizeof_mctp,
'sizeof_binding_i2c': sizeof_binding_i2c,
},
input: 'libmctp-sizes.h.in',
output: 'libmctp-sizes.h',
)
install_headers(sizes_h)
if feat_fileio.allowed()
subdir('utils')
endif
if get_option('tests').allowed()
subdir('tests')
endif