blob: 28c01268922db5554ac7b669755d31a6788a5a1f [file] [log] [blame]
Matt Johnston6586fc12024-09-10 16:01:27 +08001project(
2 'libmctp', 'c',
3 meson_version: '>= 1.1',
4 version: '0.11',
5 default_options: [
6 'debug=true',
7 'optimization=g',
8 'warning_level=2',
9 'werror=true',
10 'tests=' + (meson.is_subproject() ? 'disabled' : 'enabled'),
11 ],
12)
13
14sources = [
15 'core.c',
16 'alloc.c',
Matt Johnston4058b2c2024-11-07 14:53:50 +080017 'control.c',
Matt Johnston6586fc12024-09-10 16:01:27 +080018]
19
20headers = [
21 'libmctp.h',
22]
23
24serial_sources = [
25 'serial.c',
26 'crc-16-ccitt.c',
27]
28
29serial_headers = [
30 'libmctp-serial.h'
31]
32
33astlpc_sources = [
34 'astlpc.c',
35 'crc32.c',
36]
37
38astlpc_headers = [
39 'libmctp-astlpc.h',
40]
41
Matt Johnstone5b941d2024-09-17 16:44:38 +080042i2c_sources = [
43 'i2c.c',
44]
45
46i2c_headers = [
47 'libmctp-i2c.h',
48]
Matt Johnston4058b2c2024-11-07 14:53:50 +080049control_sources = [
50 'control.c',
51]
Matt Johnstone5b941d2024-09-17 16:44:38 +080052
Matt Johnston6586fc12024-09-10 16:01:27 +080053libmctp_sources = sources
54libmctp_headers = headers
55
56if get_option('bindings').contains('serial')
57 libmctp_sources += serial_sources
58 libmctp_headers += serial_headers
59endif
60if get_option('bindings').contains('astlpc')
61 libmctp_sources += astlpc_sources
62 libmctp_headers += astlpc_headers
63endif
Matt Johnstone5b941d2024-09-17 16:44:38 +080064if get_option('bindings').contains('i2c')
65 libmctp_sources += i2c_sources
66 libmctp_headers += i2c_headers
67endif
Matt Johnston4058b2c2024-11-07 14:53:50 +080068if get_option('control')
69 libmctp_sources += control_sources
70endif
Matt Johnston6586fc12024-09-10 16:01:27 +080071
72compiler = meson.get_compiler('c')
73
Matt Johnstonbbfcc6e2024-09-17 16:48:15 +080074if not get_option('custom_alloc') and get_option('default_alloc').require(
Matt Johnston6586fc12024-09-10 16:01:27 +080075 compiler.links('''
76 #include <stdlib.h>
77 void main()
78 {
79 free(malloc(4096));
80 }
81 ''')).allowed()
82 add_project_arguments('-DMCTP_DEFAULT_ALLOC', language : 'c')
83endif
84
Matt Johnstonbbfcc6e2024-09-17 16:48:15 +080085if get_option('custom_alloc')
86 add_project_arguments('-DMCTP_CUSTOM_ALLOC', language : 'c')
87endif
88
Matt Johnston12507272024-10-01 12:17:19 +080089if get_option('nolog')
90 add_project_arguments('-DMCTP_NOLOG', language : 'c')
91else
92 libmctp_sources += ['log.c']
93endif
94
Matt Johnston63338a22024-09-11 09:53:59 +080095feat_fileio = get_option('fileio').require(
96 compiler.links('''
97 #include <poll.h>
98 #include <unistd.h>
99 void main()
100 {
101 poll(NULL, 0, -1);
102 }
103 '''))
104if feat_fileio.allowed()
Matt Johnston6586fc12024-09-10 16:01:27 +0800105 add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c')
106endif
107
108if get_option('syslog').require(
109 compiler.links('''
110 #include <stdarg.h>
111 #include <syslog.h>
112 void check_vsyslog(int level, const char *fmt, ...)
113 {
114 va_list ap;
115 va_start(ap, fmt);
116 vsyslog(0, fmt, ap);
117 va_end(ap);
118 }
119 void main()
120 {
121 check_vsyslog(0, "\n");
122 }
123 ''')).allowed()
124 add_project_arguments('-DMCTP_HAVE_SYSLOG', language : 'c')
125endif
126
127if get_option('stdio').require(
128 compiler.links('''
129 #include <stdarg.h>
130 #include <stdio.h>
131 void check_vsyslog(const char *fmt, ...)
132 {
133 va_list ap;
134 va_start(ap, fmt);
135 vprintf(fmt, ap);
136 va_end(ap);
137 }
138 void main()
139 {
140 check_vsyslog("\n");
141 }
142 ''')).allowed()
143 add_project_arguments('-DMCTP_HAVE_STDIO', language : 'c')
144endif
145
146# pcap is necessary for mctp-demux-daemon to be functional
147pcap_dep = dependency('libpcap', required: false)
148
149systemd_dep = dependency('systemd', required: false)
150libsystemd_dep = dependency('libsystemd', required: false)
151
152libmctp_include_dir = include_directories('.', is_system: true)
153libmctp = library('mctp',
154 libmctp_sources,
155 include_directories: libmctp_include_dir,
156 version: meson.project_version(),
157 install: true,
158)
159install_headers(libmctp_headers)
160
161if systemd_dep.found()
162 unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir')
163 install_data('systemd/system/mctp-demux.service', install_dir: unitdir)
164 install_data('systemd/system/mctp-demux.socket', install_dir: unitdir)
165endif
166
167import('pkgconfig').generate(libmctp,
168 name: 'libmctp',
169 description: 'MCTP protocol implementation',
170 version: meson.project_version(),
171)
172
173libmctp_dep = declare_dependency(
174 include_directories: libmctp_include_dir,
175 link_with: libmctp,
176)
177
Matt Johnstone5b941d2024-09-17 16:44:38 +0800178# TODO: these should depend on the -internal.h headers so they rebuild
179# on changes, unclear how to do that.
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800180sizeof_mctp = compiler.sizeof('struct mctp',
181 include_directories: libmctp_include_dir,
182 prefix: '#include "core-internal.h"')
Matt Johnstone5b941d2024-09-17 16:44:38 +0800183sizeof_binding_i2c = compiler.sizeof('struct mctp_binding_i2c',
184 include_directories: libmctp_include_dir,
185 prefix: '#include "i2c-internal.h"')
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800186sizes_h = configure_file(configuration: {
187 'sizeof_struct_mctp': sizeof_mctp,
Matt Johnstone5b941d2024-09-17 16:44:38 +0800188 'sizeof_binding_i2c': sizeof_binding_i2c,
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800189 },
190 input: 'libmctp-sizes.h.in',
191 output: 'libmctp-sizes.h',
192 )
193install_headers(sizes_h)
194
Matt Johnston63338a22024-09-11 09:53:59 +0800195if feat_fileio.allowed()
196 subdir('utils')
197endif
Matt Johnston6586fc12024-09-10 16:01:27 +0800198
199if get_option('tests').allowed()
200 subdir('tests')
201endif