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