blob: d884c6ab739d286567572212ecce93c0bb85aa74 [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
56if get_option('default_alloc').require(
57 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 Johnston63338a22024-09-11 09:53:59 +080067feat_fileio = get_option('fileio').require(
68 compiler.links('''
69 #include <poll.h>
70 #include <unistd.h>
71 void main()
72 {
73 poll(NULL, 0, -1);
74 }
75 '''))
76if feat_fileio.allowed()
Matt Johnston6586fc12024-09-10 16:01:27 +080077 add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c')
78endif
79
80if get_option('syslog').require(
81 compiler.links('''
82 #include <stdarg.h>
83 #include <syslog.h>
84 void check_vsyslog(int level, const char *fmt, ...)
85 {
86 va_list ap;
87 va_start(ap, fmt);
88 vsyslog(0, fmt, ap);
89 va_end(ap);
90 }
91 void main()
92 {
93 check_vsyslog(0, "\n");
94 }
95 ''')).allowed()
96 add_project_arguments('-DMCTP_HAVE_SYSLOG', language : 'c')
97endif
98
99if get_option('stdio').require(
100 compiler.links('''
101 #include <stdarg.h>
102 #include <stdio.h>
103 void check_vsyslog(const char *fmt, ...)
104 {
105 va_list ap;
106 va_start(ap, fmt);
107 vprintf(fmt, ap);
108 va_end(ap);
109 }
110 void main()
111 {
112 check_vsyslog("\n");
113 }
114 ''')).allowed()
115 add_project_arguments('-DMCTP_HAVE_STDIO', language : 'c')
116endif
117
118# pcap is necessary for mctp-demux-daemon to be functional
119pcap_dep = dependency('libpcap', required: false)
120
121systemd_dep = dependency('systemd', required: false)
122libsystemd_dep = dependency('libsystemd', required: false)
123
124libmctp_include_dir = include_directories('.', is_system: true)
125libmctp = library('mctp',
126 libmctp_sources,
127 include_directories: libmctp_include_dir,
128 version: meson.project_version(),
129 install: true,
130)
131install_headers(libmctp_headers)
132
133if systemd_dep.found()
134 unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir')
135 install_data('systemd/system/mctp-demux.service', install_dir: unitdir)
136 install_data('systemd/system/mctp-demux.socket', install_dir: unitdir)
137endif
138
139import('pkgconfig').generate(libmctp,
140 name: 'libmctp',
141 description: 'MCTP protocol implementation',
142 version: meson.project_version(),
143)
144
145libmctp_dep = declare_dependency(
146 include_directories: libmctp_include_dir,
147 link_with: libmctp,
148)
149
Matt Johnston63338a22024-09-11 09:53:59 +0800150if feat_fileio.allowed()
151 subdir('utils')
152endif
Matt Johnston6586fc12024-09-10 16:01:27 +0800153
154if get_option('tests').allowed()
155 subdir('tests')
156endif