blob: 5f59b8a391db96361e8141eb71f39e9ae78f0caf [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 Johnston63338a22024-09-11 09:53:59 +080077feat_fileio = get_option('fileio').require(
Patrick Williams5cc20932025-02-01 08:37:58 -050078 compiler.links(
79 '''
Matt Johnston63338a22024-09-11 09:53:59 +080080 #include <poll.h>
81 #include <unistd.h>
82 void main()
83 {
84 poll(NULL, 0, -1);
85 }
Patrick Williams5cc20932025-02-01 08:37:58 -050086 ''',
87 ),
88)
Matt Johnston63338a22024-09-11 09:53:59 +080089if feat_fileio.allowed()
Patrick Williams5cc20932025-02-01 08:37:58 -050090 add_project_arguments('-DMCTP_HAVE_FILEIO', language: 'c')
Matt Johnston6586fc12024-09-10 16:01:27 +080091endif
92
93if get_option('syslog').require(
Patrick Williams5cc20932025-02-01 08:37:58 -050094 compiler.links(
95 '''
Matt Johnston6586fc12024-09-10 16:01:27 +080096 #include <stdarg.h>
97 #include <syslog.h>
98 void check_vsyslog(int level, const char *fmt, ...)
99 {
100 va_list ap;
101 va_start(ap, fmt);
102 vsyslog(0, fmt, ap);
103 va_end(ap);
104 }
105 void main()
106 {
107 check_vsyslog(0, "\n");
108 }
Patrick Williams5cc20932025-02-01 08:37:58 -0500109 ''',
110 ),
111).allowed()
112 add_project_arguments('-DMCTP_HAVE_SYSLOG', language: 'c')
Matt Johnston6586fc12024-09-10 16:01:27 +0800113endif
114
115if get_option('stdio').require(
Patrick Williams5cc20932025-02-01 08:37:58 -0500116 compiler.links(
117 '''
Matt Johnston6586fc12024-09-10 16:01:27 +0800118 #include <stdarg.h>
119 #include <stdio.h>
120 void check_vsyslog(const char *fmt, ...)
121 {
122 va_list ap;
123 va_start(ap, fmt);
124 vprintf(fmt, ap);
125 va_end(ap);
126 }
127 void main()
128 {
129 check_vsyslog("\n");
130 }
Patrick Williams5cc20932025-02-01 08:37:58 -0500131 ''',
132 ),
133).allowed()
134 add_project_arguments('-DMCTP_HAVE_STDIO', language: 'c')
Matt Johnston6586fc12024-09-10 16:01:27 +0800135endif
136
137# pcap is necessary for mctp-demux-daemon to be functional
138pcap_dep = dependency('libpcap', required: false)
139
140systemd_dep = dependency('systemd', required: false)
141libsystemd_dep = dependency('libsystemd', required: false)
142
143libmctp_include_dir = include_directories('.', is_system: true)
Patrick Williams5cc20932025-02-01 08:37:58 -0500144libmctp = library(
145 'mctp',
Matt Johnston6586fc12024-09-10 16:01:27 +0800146 libmctp_sources,
147 include_directories: libmctp_include_dir,
148 version: meson.project_version(),
149 install: true,
150)
151install_headers(libmctp_headers)
152
153if systemd_dep.found()
154 unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir')
155 install_data('systemd/system/mctp-demux.service', install_dir: unitdir)
156 install_data('systemd/system/mctp-demux.socket', install_dir: unitdir)
157endif
158
Patrick Williams5cc20932025-02-01 08:37:58 -0500159import('pkgconfig').generate(
160 libmctp,
Matt Johnston6586fc12024-09-10 16:01:27 +0800161 name: 'libmctp',
162 description: 'MCTP protocol implementation',
163 version: meson.project_version(),
164)
165
166libmctp_dep = declare_dependency(
167 include_directories: libmctp_include_dir,
168 link_with: libmctp,
169)
170
Matt Johnstone5b941d2024-09-17 16:44:38 +0800171# TODO: these should depend on the -internal.h headers so they rebuild
172# on changes, unclear how to do that.
Patrick Williams5cc20932025-02-01 08:37:58 -0500173sizeof_mctp = compiler.sizeof(
174 'struct mctp',
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800175 include_directories: libmctp_include_dir,
Patrick Williams5cc20932025-02-01 08:37:58 -0500176 prefix: '#include "core-internal.h"',
177)
178sizeof_binding_i2c = compiler.sizeof(
179 'struct mctp_binding_i2c',
Matt Johnstone5b941d2024-09-17 16:44:38 +0800180 include_directories: libmctp_include_dir,
Patrick Williams5cc20932025-02-01 08:37:58 -0500181 prefix: '#include "i2c-internal.h"',
182)
183sizes_h = configure_file(
184 configuration: {
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800185 'sizeof_struct_mctp': sizeof_mctp,
Matt Johnstone5b941d2024-09-17 16:44:38 +0800186 'sizeof_binding_i2c': sizeof_binding_i2c,
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800187 },
188 input: 'libmctp-sizes.h.in',
189 output: 'libmctp-sizes.h',
Patrick Williams5cc20932025-02-01 08:37:58 -0500190)
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800191install_headers(sizes_h)
192
Matt Johnston63338a22024-09-11 09:53:59 +0800193if feat_fileio.allowed()
194 subdir('utils')
195endif
Matt Johnston6586fc12024-09-10 16:01:27 +0800196
197if get_option('tests').allowed()
198 subdir('tests')
199endif