blob: b8897a50a9c3cd663215892154c7ab1621426b6d [file] [log] [blame]
Matt Johnston6586fc12024-09-10 16:01:27 +08001project(
Patrick Williams5cc20932025-02-01 08:37:58 -05002 'libmctp',
3 'c',
Matt Johnston6586fc12024-09-10 16:01:27 +08004 meson_version: '>= 1.1',
5 version: '0.11',
6 default_options: [
7 'debug=true',
8 'optimization=g',
9 'warning_level=2',
10 'werror=true',
11 'tests=' + (meson.is_subproject() ? 'disabled' : 'enabled'),
12 ],
13)
14
Patrick Williams5cc20932025-02-01 08:37:58 -050015sources = ['core.c', 'alloc.c', 'control.c']
Matt Johnston6586fc12024-09-10 16:01:27 +080016
Patrick Williams5cc20932025-02-01 08:37:58 -050017headers = ['libmctp.h']
Matt Johnston6586fc12024-09-10 16:01:27 +080018
Patrick Williams5cc20932025-02-01 08:37:58 -050019serial_sources = ['serial.c', 'crc-16-ccitt.c']
Matt Johnston6586fc12024-09-10 16:01:27 +080020
Patrick Williams5cc20932025-02-01 08:37:58 -050021serial_headers = ['libmctp-serial.h']
Matt Johnston6586fc12024-09-10 16:01:27 +080022
Patrick Williams5cc20932025-02-01 08:37:58 -050023astlpc_sources = ['astlpc.c', 'crc32.c']
Matt Johnston6586fc12024-09-10 16:01:27 +080024
Patrick Williams5cc20932025-02-01 08:37:58 -050025astlpc_headers = ['libmctp-astlpc.h']
Matt Johnston6586fc12024-09-10 16:01:27 +080026
Patrick Williams5cc20932025-02-01 08:37:58 -050027i2c_sources = ['i2c.c']
Matt Johnstone5b941d2024-09-17 16:44:38 +080028
Patrick Williams5cc20932025-02-01 08:37:58 -050029i2c_headers = ['libmctp-i2c.h']
30control_sources = ['control.c']
Matt Johnstone5b941d2024-09-17 16:44:38 +080031
Matt Johnston6586fc12024-09-10 16:01:27 +080032libmctp_sources = sources
33libmctp_headers = headers
34
35if get_option('bindings').contains('serial')
36 libmctp_sources += serial_sources
37 libmctp_headers += serial_headers
38endif
39if get_option('bindings').contains('astlpc')
40 libmctp_sources += astlpc_sources
41 libmctp_headers += astlpc_headers
42endif
Matt Johnstone5b941d2024-09-17 16:44:38 +080043if get_option('bindings').contains('i2c')
44 libmctp_sources += i2c_sources
45 libmctp_headers += i2c_headers
46endif
Matt Johnston4058b2c2024-11-07 14:53:50 +080047if get_option('control')
48 libmctp_sources += control_sources
49endif
Matt Johnston6586fc12024-09-10 16:01:27 +080050
51compiler = meson.get_compiler('c')
52
Matt Johnstonbbfcc6e2024-09-17 16:48:15 +080053if not get_option('custom_alloc') and get_option('default_alloc').require(
Patrick Williams5cc20932025-02-01 08:37:58 -050054 compiler.links(
55 '''
Matt Johnston6586fc12024-09-10 16:01:27 +080056 #include <stdlib.h>
57 void main()
58 {
59 free(malloc(4096));
60 }
Patrick Williams5cc20932025-02-01 08:37:58 -050061 ''',
62 ),
63).allowed()
64 add_project_arguments('-DMCTP_DEFAULT_ALLOC', language: 'c')
Matt Johnston6586fc12024-09-10 16:01:27 +080065endif
66
Matt Johnstonbbfcc6e2024-09-17 16:48:15 +080067if get_option('custom_alloc')
Patrick Williams5cc20932025-02-01 08:37:58 -050068 add_project_arguments('-DMCTP_CUSTOM_ALLOC', language: 'c')
Matt Johnstonbbfcc6e2024-09-17 16:48:15 +080069endif
70
Matt Johnston12507272024-10-01 12:17:19 +080071if get_option('nolog')
Patrick Williams5cc20932025-02-01 08:37:58 -050072 add_project_arguments('-DMCTP_NOLOG', language: 'c')
Matt Johnston12507272024-10-01 12:17:19 +080073else
74 libmctp_sources += ['log.c']
75endif
76
Matt Johnstonb04447c2025-09-18 15:51:04 +080077option_args = [
78 '-DMCTP_MAX_MESSAGE_SIZE=@0@'.format(get_option('max_message_size')),
79 '-DMCTP_REASSEMBLY_CTXS=@0@'.format(get_option('reassembly_contexts')),
80 '-DMCTP_REQ_TAGS=@0@'.format(get_option('request_tags')),
81 '-DMCTP_DEFAULT_CLOCK_GETTIME=@0@'.format(
82 get_option('default_clock_gettime').to_int(),
83 ),
84 '-DMCTP_CONTROL_HANDLER=@0@'.format(get_option('control').to_int()),
85 '-DI2C_BTU=@0@'.format(get_option('i2c_mtu')),
86 '-DMCTP_I2C_NEIGH_COUNT=@0@'.format(get_option('i2c_neigh_count')),
87]
88
89add_project_arguments(option_args, language: 'c')
90
Matt Johnston63338a22024-09-11 09:53:59 +080091feat_fileio = get_option('fileio').require(
Patrick Williams5cc20932025-02-01 08:37:58 -050092 compiler.links(
93 '''
Matt Johnston63338a22024-09-11 09:53:59 +080094 #include <poll.h>
95 #include <unistd.h>
96 void main()
97 {
98 poll(NULL, 0, -1);
99 }
Patrick Williams5cc20932025-02-01 08:37:58 -0500100 ''',
101 ),
102)
Matt Johnston63338a22024-09-11 09:53:59 +0800103if feat_fileio.allowed()
Patrick Williams5cc20932025-02-01 08:37:58 -0500104 add_project_arguments('-DMCTP_HAVE_FILEIO', language: 'c')
Matt Johnston6586fc12024-09-10 16:01:27 +0800105endif
106
107if get_option('syslog').require(
Patrick Williams5cc20932025-02-01 08:37:58 -0500108 compiler.links(
109 '''
Matt Johnston6586fc12024-09-10 16:01:27 +0800110 #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 }
Patrick Williams5cc20932025-02-01 08:37:58 -0500123 ''',
124 ),
125).allowed()
126 add_project_arguments('-DMCTP_HAVE_SYSLOG', language: 'c')
Matt Johnston6586fc12024-09-10 16:01:27 +0800127endif
128
129if get_option('stdio').require(
Patrick Williams5cc20932025-02-01 08:37:58 -0500130 compiler.links(
131 '''
Matt Johnston6586fc12024-09-10 16:01:27 +0800132 #include <stdarg.h>
133 #include <stdio.h>
134 void check_vsyslog(const char *fmt, ...)
135 {
136 va_list ap;
137 va_start(ap, fmt);
138 vprintf(fmt, ap);
139 va_end(ap);
140 }
141 void main()
142 {
143 check_vsyslog("\n");
144 }
Patrick Williams5cc20932025-02-01 08:37:58 -0500145 ''',
146 ),
147).allowed()
148 add_project_arguments('-DMCTP_HAVE_STDIO', language: 'c')
Matt Johnston6586fc12024-09-10 16:01:27 +0800149endif
150
151# pcap is necessary for mctp-demux-daemon to be functional
152pcap_dep = dependency('libpcap', required: false)
153
154systemd_dep = dependency('systemd', required: false)
155libsystemd_dep = dependency('libsystemd', required: false)
156
157libmctp_include_dir = include_directories('.', is_system: true)
Patrick Williams5cc20932025-02-01 08:37:58 -0500158libmctp = library(
159 'mctp',
Matt Johnston6586fc12024-09-10 16:01:27 +0800160 libmctp_sources,
161 include_directories: libmctp_include_dir,
162 version: meson.project_version(),
163 install: true,
164)
165install_headers(libmctp_headers)
166
167if systemd_dep.found()
Patrick Williamsc2438232025-07-09 11:27:39 -0400168 unitdir = systemd_dep.get_variable(pkgconfig: 'systemd_system_unit_dir')
Matt Johnston6586fc12024-09-10 16:01:27 +0800169 install_data('systemd/system/mctp-demux.service', install_dir: unitdir)
170 install_data('systemd/system/mctp-demux.socket', install_dir: unitdir)
171endif
172
Patrick Williams5cc20932025-02-01 08:37:58 -0500173import('pkgconfig').generate(
174 libmctp,
Matt Johnston6586fc12024-09-10 16:01:27 +0800175 name: 'libmctp',
176 description: 'MCTP protocol implementation',
177 version: meson.project_version(),
178)
179
180libmctp_dep = declare_dependency(
181 include_directories: libmctp_include_dir,
182 link_with: libmctp,
183)
184
Matt Johnstone5b941d2024-09-17 16:44:38 +0800185# TODO: these should depend on the -internal.h headers so they rebuild
186# on changes, unclear how to do that.
Patrick Williams5cc20932025-02-01 08:37:58 -0500187sizeof_mctp = compiler.sizeof(
188 'struct mctp',
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800189 include_directories: libmctp_include_dir,
Matt Johnstonb04447c2025-09-18 15:51:04 +0800190 args: option_args,
Patrick Williams5cc20932025-02-01 08:37:58 -0500191 prefix: '#include "core-internal.h"',
192)
193sizeof_binding_i2c = compiler.sizeof(
194 'struct mctp_binding_i2c',
Matt Johnstone5b941d2024-09-17 16:44:38 +0800195 include_directories: libmctp_include_dir,
Matt Johnstonb04447c2025-09-18 15:51:04 +0800196 args: option_args,
Patrick Williams5cc20932025-02-01 08:37:58 -0500197 prefix: '#include "i2c-internal.h"',
198)
199sizes_h = configure_file(
200 configuration: {
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800201 'sizeof_struct_mctp': sizeof_mctp,
Matt Johnstone5b941d2024-09-17 16:44:38 +0800202 'sizeof_binding_i2c': sizeof_binding_i2c,
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800203 },
204 input: 'libmctp-sizes.h.in',
205 output: 'libmctp-sizes.h',
Patrick Williams5cc20932025-02-01 08:37:58 -0500206)
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800207install_headers(sizes_h)
208
Matt Johnston63338a22024-09-11 09:53:59 +0800209if feat_fileio.allowed()
210 subdir('utils')
211endif
Matt Johnston6586fc12024-09-10 16:01:27 +0800212
213if get_option('tests').allowed()
214 subdir('tests')
215endif