blob: fa6ff811bf45c995524ef727ff4ca2611c99f33b [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 Johnston6586fc12024-09-10 16:01:27 +080017]
18
19headers = [
20 'libmctp.h',
21]
22
23serial_sources = [
24 'serial.c',
25 'crc-16-ccitt.c',
26]
27
28serial_headers = [
29 'libmctp-serial.h'
30]
31
32astlpc_sources = [
33 'astlpc.c',
34 'crc32.c',
35]
36
37astlpc_headers = [
38 'libmctp-astlpc.h',
39]
40
Matt Johnstone5b941d2024-09-17 16:44:38 +080041i2c_sources = [
42 'i2c.c',
43]
44
45i2c_headers = [
46 'libmctp-i2c.h',
47]
48
Matt Johnston6586fc12024-09-10 16:01:27 +080049libmctp_sources = sources
50libmctp_headers = headers
51
52if get_option('bindings').contains('serial')
53 libmctp_sources += serial_sources
54 libmctp_headers += serial_headers
55endif
56if get_option('bindings').contains('astlpc')
57 libmctp_sources += astlpc_sources
58 libmctp_headers += astlpc_headers
59endif
Matt Johnstone5b941d2024-09-17 16:44:38 +080060if get_option('bindings').contains('i2c')
61 libmctp_sources += i2c_sources
62 libmctp_headers += i2c_headers
63endif
Matt Johnston6586fc12024-09-10 16:01:27 +080064
65compiler = meson.get_compiler('c')
66
Matt Johnstonbbfcc6e2024-09-17 16:48:15 +080067if not get_option('custom_alloc') and get_option('default_alloc').require(
Matt Johnston6586fc12024-09-10 16:01:27 +080068 compiler.links('''
69 #include <stdlib.h>
70 void main()
71 {
72 free(malloc(4096));
73 }
74 ''')).allowed()
75 add_project_arguments('-DMCTP_DEFAULT_ALLOC', language : 'c')
76endif
77
Matt Johnstonbbfcc6e2024-09-17 16:48:15 +080078if get_option('custom_alloc')
79 add_project_arguments('-DMCTP_CUSTOM_ALLOC', language : 'c')
80endif
81
Matt Johnston12507272024-10-01 12:17:19 +080082if get_option('nolog')
83 add_project_arguments('-DMCTP_NOLOG', language : 'c')
84else
85 libmctp_sources += ['log.c']
86endif
87
Matt Johnston63338a22024-09-11 09:53:59 +080088feat_fileio = get_option('fileio').require(
89 compiler.links('''
90 #include <poll.h>
91 #include <unistd.h>
92 void main()
93 {
94 poll(NULL, 0, -1);
95 }
96 '''))
97if feat_fileio.allowed()
Matt Johnston6586fc12024-09-10 16:01:27 +080098 add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c')
99endif
100
101if get_option('syslog').require(
102 compiler.links('''
103 #include <stdarg.h>
104 #include <syslog.h>
105 void check_vsyslog(int level, const char *fmt, ...)
106 {
107 va_list ap;
108 va_start(ap, fmt);
109 vsyslog(0, fmt, ap);
110 va_end(ap);
111 }
112 void main()
113 {
114 check_vsyslog(0, "\n");
115 }
116 ''')).allowed()
117 add_project_arguments('-DMCTP_HAVE_SYSLOG', language : 'c')
118endif
119
120if get_option('stdio').require(
121 compiler.links('''
122 #include <stdarg.h>
123 #include <stdio.h>
124 void check_vsyslog(const char *fmt, ...)
125 {
126 va_list ap;
127 va_start(ap, fmt);
128 vprintf(fmt, ap);
129 va_end(ap);
130 }
131 void main()
132 {
133 check_vsyslog("\n");
134 }
135 ''')).allowed()
136 add_project_arguments('-DMCTP_HAVE_STDIO', language : 'c')
137endif
138
139# pcap is necessary for mctp-demux-daemon to be functional
140pcap_dep = dependency('libpcap', required: false)
141
142systemd_dep = dependency('systemd', required: false)
143libsystemd_dep = dependency('libsystemd', required: false)
144
145libmctp_include_dir = include_directories('.', is_system: true)
146libmctp = library('mctp',
147 libmctp_sources,
148 include_directories: libmctp_include_dir,
149 version: meson.project_version(),
150 install: true,
151)
152install_headers(libmctp_headers)
153
154if systemd_dep.found()
155 unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir')
156 install_data('systemd/system/mctp-demux.service', install_dir: unitdir)
157 install_data('systemd/system/mctp-demux.socket', install_dir: unitdir)
158endif
159
160import('pkgconfig').generate(libmctp,
161 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.
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800173sizeof_mctp = compiler.sizeof('struct mctp',
174 include_directories: libmctp_include_dir,
175 prefix: '#include "core-internal.h"')
Matt Johnstone5b941d2024-09-17 16:44:38 +0800176sizeof_binding_i2c = compiler.sizeof('struct mctp_binding_i2c',
177 include_directories: libmctp_include_dir,
178 prefix: '#include "i2c-internal.h"')
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800179sizes_h = configure_file(configuration: {
180 'sizeof_struct_mctp': sizeof_mctp,
Matt Johnstone5b941d2024-09-17 16:44:38 +0800181 'sizeof_binding_i2c': sizeof_binding_i2c,
Matt Johnstonf9b99f12024-09-17 16:48:34 +0800182 },
183 input: 'libmctp-sizes.h.in',
184 output: 'libmctp-sizes.h',
185 )
186install_headers(sizes_h)
187
Matt Johnston63338a22024-09-11 09:53:59 +0800188if feat_fileio.allowed()
189 subdir('utils')
190endif
Matt Johnston6586fc12024-09-10 16:01:27 +0800191
192if get_option('tests').allowed()
193 subdir('tests')
194endif