blob: 7f44a46ef58a6ec25455f602fbdddcc390424030 [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',
17 'log.c',
18]
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
42libmctp_sources = sources
43libmctp_headers = headers
44
45if get_option('bindings').contains('serial')
46 libmctp_sources += serial_sources
47 libmctp_headers += serial_headers
48endif
49if get_option('bindings').contains('astlpc')
50 libmctp_sources += astlpc_sources
51 libmctp_headers += astlpc_headers
52endif
53
54compiler = meson.get_compiler('c')
55
Matt Johnstonbbfcc6e2024-09-17 16:48:15 +080056if not get_option('custom_alloc') and get_option('default_alloc').require(
Matt Johnston6586fc12024-09-10 16:01:27 +080057 compiler.links('''
58 #include <stdlib.h>
59 void main()
60 {
61 free(malloc(4096));
62 }
63 ''')).allowed()
64 add_project_arguments('-DMCTP_DEFAULT_ALLOC', language : 'c')
65endif
66
Matt Johnstonbbfcc6e2024-09-17 16:48:15 +080067if get_option('custom_alloc')
68 add_project_arguments('-DMCTP_CUSTOM_ALLOC', language : 'c')
69endif
70
Matt Johnston63338a22024-09-11 09:53:59 +080071feat_fileio = get_option('fileio').require(
72 compiler.links('''
73 #include <poll.h>
74 #include <unistd.h>
75 void main()
76 {
77 poll(NULL, 0, -1);
78 }
79 '''))
80if feat_fileio.allowed()
Matt Johnston6586fc12024-09-10 16:01:27 +080081 add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c')
82endif
83
84if get_option('syslog').require(
85 compiler.links('''
86 #include <stdarg.h>
87 #include <syslog.h>
88 void check_vsyslog(int level, const char *fmt, ...)
89 {
90 va_list ap;
91 va_start(ap, fmt);
92 vsyslog(0, fmt, ap);
93 va_end(ap);
94 }
95 void main()
96 {
97 check_vsyslog(0, "\n");
98 }
99 ''')).allowed()
100 add_project_arguments('-DMCTP_HAVE_SYSLOG', language : 'c')
101endif
102
103if get_option('stdio').require(
104 compiler.links('''
105 #include <stdarg.h>
106 #include <stdio.h>
107 void check_vsyslog(const char *fmt, ...)
108 {
109 va_list ap;
110 va_start(ap, fmt);
111 vprintf(fmt, ap);
112 va_end(ap);
113 }
114 void main()
115 {
116 check_vsyslog("\n");
117 }
118 ''')).allowed()
119 add_project_arguments('-DMCTP_HAVE_STDIO', language : 'c')
120endif
121
122# pcap is necessary for mctp-demux-daemon to be functional
123pcap_dep = dependency('libpcap', required: false)
124
125systemd_dep = dependency('systemd', required: false)
126libsystemd_dep = dependency('libsystemd', required: false)
127
128libmctp_include_dir = include_directories('.', is_system: true)
129libmctp = library('mctp',
130 libmctp_sources,
131 include_directories: libmctp_include_dir,
132 version: meson.project_version(),
133 install: true,
134)
135install_headers(libmctp_headers)
136
137if systemd_dep.found()
138 unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir')
139 install_data('systemd/system/mctp-demux.service', install_dir: unitdir)
140 install_data('systemd/system/mctp-demux.socket', install_dir: unitdir)
141endif
142
143import('pkgconfig').generate(libmctp,
144 name: 'libmctp',
145 description: 'MCTP protocol implementation',
146 version: meson.project_version(),
147)
148
149libmctp_dep = declare_dependency(
150 include_directories: libmctp_include_dir,
151 link_with: libmctp,
152)
153
Matt Johnston63338a22024-09-11 09:53:59 +0800154if feat_fileio.allowed()
155 subdir('utils')
156endif
Matt Johnston6586fc12024-09-10 16:01:27 +0800157
158if get_option('tests').allowed()
159 subdir('tests')
160endif