xref: /openbmc/libmctp/meson.build (revision 5cc20932a8a52bd43eb124388b7466036705451b)
16586fc10SMatt Johnstonproject(
2*5cc20932SPatrick Williams    'libmctp',
3*5cc20932SPatrick Williams    'c',
46586fc10SMatt Johnston    meson_version: '>= 1.1',
56586fc10SMatt Johnston    version: '0.11',
66586fc10SMatt Johnston    default_options: [
76586fc10SMatt Johnston        'debug=true',
86586fc10SMatt Johnston        'optimization=g',
96586fc10SMatt Johnston        'warning_level=2',
106586fc10SMatt Johnston        'werror=true',
116586fc10SMatt Johnston        'tests=' + (meson.is_subproject() ? 'disabled' : 'enabled'),
126586fc10SMatt Johnston    ],
136586fc10SMatt Johnston)
146586fc10SMatt Johnston
15*5cc20932SPatrick Williamssources = ['core.c', 'alloc.c', 'control.c']
166586fc10SMatt Johnston
17*5cc20932SPatrick Williamsheaders = ['libmctp.h']
186586fc10SMatt Johnston
19*5cc20932SPatrick Williamsserial_sources = ['serial.c', 'crc-16-ccitt.c']
206586fc10SMatt Johnston
21*5cc20932SPatrick Williamsserial_headers = ['libmctp-serial.h']
226586fc10SMatt Johnston
23*5cc20932SPatrick Williamsastlpc_sources = ['astlpc.c', 'crc32.c']
246586fc10SMatt Johnston
25*5cc20932SPatrick Williamsastlpc_headers = ['libmctp-astlpc.h']
266586fc10SMatt Johnston
27*5cc20932SPatrick Williamsi2c_sources = ['i2c.c']
28e5b941d9SMatt Johnston
29*5cc20932SPatrick Williamsi2c_headers = ['libmctp-i2c.h']
30*5cc20932SPatrick Williamscontrol_sources = ['control.c']
31e5b941d9SMatt Johnston
326586fc10SMatt Johnstonlibmctp_sources = sources
336586fc10SMatt Johnstonlibmctp_headers = headers
346586fc10SMatt Johnston
356586fc10SMatt Johnstonif get_option('bindings').contains('serial')
366586fc10SMatt Johnston    libmctp_sources += serial_sources
376586fc10SMatt Johnston    libmctp_headers += serial_headers
386586fc10SMatt Johnstonendif
396586fc10SMatt Johnstonif get_option('bindings').contains('astlpc')
406586fc10SMatt Johnston    libmctp_sources += astlpc_sources
416586fc10SMatt Johnston    libmctp_headers += astlpc_headers
426586fc10SMatt Johnstonendif
43e5b941d9SMatt Johnstonif get_option('bindings').contains('i2c')
44e5b941d9SMatt Johnston    libmctp_sources += i2c_sources
45e5b941d9SMatt Johnston    libmctp_headers += i2c_headers
46e5b941d9SMatt Johnstonendif
474058b2cbSMatt Johnstonif get_option('control')
484058b2cbSMatt Johnston    libmctp_sources += control_sources
494058b2cbSMatt Johnstonendif
506586fc10SMatt Johnston
516586fc10SMatt Johnstoncompiler = meson.get_compiler('c')
526586fc10SMatt Johnston
53bbfcc6e1SMatt Johnstonif not get_option('custom_alloc') and get_option('default_alloc').require(
54*5cc20932SPatrick Williams    compiler.links(
55*5cc20932SPatrick Williams        '''
566586fc10SMatt Johnston        #include <stdlib.h>
576586fc10SMatt Johnston        void main()
586586fc10SMatt Johnston        {
596586fc10SMatt Johnston            free(malloc(4096));
606586fc10SMatt Johnston        }
61*5cc20932SPatrick Williams    ''',
62*5cc20932SPatrick Williams    ),
63*5cc20932SPatrick Williams).allowed()
646586fc10SMatt Johnston    add_project_arguments('-DMCTP_DEFAULT_ALLOC', language: 'c')
656586fc10SMatt Johnstonendif
666586fc10SMatt Johnston
67bbfcc6e1SMatt Johnstonif get_option('custom_alloc')
68bbfcc6e1SMatt Johnston    add_project_arguments('-DMCTP_CUSTOM_ALLOC', language: 'c')
69bbfcc6e1SMatt Johnstonendif
70bbfcc6e1SMatt Johnston
711250727fSMatt Johnstonif get_option('nolog')
721250727fSMatt Johnston    add_project_arguments('-DMCTP_NOLOG', language: 'c')
731250727fSMatt Johnstonelse
741250727fSMatt Johnston    libmctp_sources += ['log.c']
751250727fSMatt Johnstonendif
761250727fSMatt Johnston
7763338a2eSMatt Johnstonfeat_fileio = get_option('fileio').require(
78*5cc20932SPatrick Williams    compiler.links(
79*5cc20932SPatrick Williams        '''
8063338a2eSMatt Johnston        #include <poll.h>
8163338a2eSMatt Johnston        #include <unistd.h>
8263338a2eSMatt Johnston        void main()
8363338a2eSMatt Johnston        {
8463338a2eSMatt Johnston            poll(NULL, 0, -1);
8563338a2eSMatt Johnston        }
86*5cc20932SPatrick Williams    ''',
87*5cc20932SPatrick Williams    ),
88*5cc20932SPatrick Williams)
8963338a2eSMatt Johnstonif feat_fileio.allowed()
906586fc10SMatt Johnston    add_project_arguments('-DMCTP_HAVE_FILEIO', language: 'c')
916586fc10SMatt Johnstonendif
926586fc10SMatt Johnston
936586fc10SMatt Johnstonif get_option('syslog').require(
94*5cc20932SPatrick Williams    compiler.links(
95*5cc20932SPatrick Williams        '''
966586fc10SMatt Johnston        #include <stdarg.h>
976586fc10SMatt Johnston        #include <syslog.h>
986586fc10SMatt Johnston        void check_vsyslog(int level, const char *fmt, ...)
996586fc10SMatt Johnston        {
1006586fc10SMatt Johnston            va_list ap;
1016586fc10SMatt Johnston            va_start(ap, fmt);
1026586fc10SMatt Johnston            vsyslog(0, fmt, ap);
1036586fc10SMatt Johnston            va_end(ap);
1046586fc10SMatt Johnston        }
1056586fc10SMatt Johnston        void main()
1066586fc10SMatt Johnston        {
1076586fc10SMatt Johnston            check_vsyslog(0, "\n");
1086586fc10SMatt Johnston        }
109*5cc20932SPatrick Williams        ''',
110*5cc20932SPatrick Williams    ),
111*5cc20932SPatrick Williams).allowed()
1126586fc10SMatt Johnston    add_project_arguments('-DMCTP_HAVE_SYSLOG', language: 'c')
1136586fc10SMatt Johnstonendif
1146586fc10SMatt Johnston
1156586fc10SMatt Johnstonif get_option('stdio').require(
116*5cc20932SPatrick Williams    compiler.links(
117*5cc20932SPatrick Williams        '''
1186586fc10SMatt Johnston        #include <stdarg.h>
1196586fc10SMatt Johnston        #include <stdio.h>
1206586fc10SMatt Johnston        void check_vsyslog(const char *fmt, ...)
1216586fc10SMatt Johnston        {
1226586fc10SMatt Johnston            va_list ap;
1236586fc10SMatt Johnston            va_start(ap, fmt);
1246586fc10SMatt Johnston            vprintf(fmt, ap);
1256586fc10SMatt Johnston            va_end(ap);
1266586fc10SMatt Johnston        }
1276586fc10SMatt Johnston        void main()
1286586fc10SMatt Johnston        {
1296586fc10SMatt Johnston            check_vsyslog("\n");
1306586fc10SMatt Johnston        }
131*5cc20932SPatrick Williams        ''',
132*5cc20932SPatrick Williams    ),
133*5cc20932SPatrick Williams).allowed()
1346586fc10SMatt Johnston    add_project_arguments('-DMCTP_HAVE_STDIO', language: 'c')
1356586fc10SMatt Johnstonendif
1366586fc10SMatt Johnston
1376586fc10SMatt Johnston# pcap is necessary for mctp-demux-daemon to be functional
1386586fc10SMatt Johnstonpcap_dep = dependency('libpcap', required: false)
1396586fc10SMatt Johnston
1406586fc10SMatt Johnstonsystemd_dep = dependency('systemd', required: false)
1416586fc10SMatt Johnstonlibsystemd_dep = dependency('libsystemd', required: false)
1426586fc10SMatt Johnston
1436586fc10SMatt Johnstonlibmctp_include_dir = include_directories('.', is_system: true)
144*5cc20932SPatrick Williamslibmctp = library(
145*5cc20932SPatrick Williams    'mctp',
1466586fc10SMatt Johnston    libmctp_sources,
1476586fc10SMatt Johnston    include_directories: libmctp_include_dir,
1486586fc10SMatt Johnston    version: meson.project_version(),
1496586fc10SMatt Johnston    install: true,
1506586fc10SMatt Johnston)
1516586fc10SMatt Johnstoninstall_headers(libmctp_headers)
1526586fc10SMatt Johnston
1536586fc10SMatt Johnstonif systemd_dep.found()
1546586fc10SMatt Johnston    unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir')
1556586fc10SMatt Johnston    install_data('systemd/system/mctp-demux.service', install_dir: unitdir)
1566586fc10SMatt Johnston    install_data('systemd/system/mctp-demux.socket', install_dir: unitdir)
1576586fc10SMatt Johnstonendif
1586586fc10SMatt Johnston
159*5cc20932SPatrick Williamsimport('pkgconfig').generate(
160*5cc20932SPatrick Williams    libmctp,
1616586fc10SMatt Johnston    name: 'libmctp',
1626586fc10SMatt Johnston    description: 'MCTP protocol implementation',
1636586fc10SMatt Johnston    version: meson.project_version(),
1646586fc10SMatt Johnston)
1656586fc10SMatt Johnston
1666586fc10SMatt Johnstonlibmctp_dep = declare_dependency(
1676586fc10SMatt Johnston    include_directories: libmctp_include_dir,
1686586fc10SMatt Johnston    link_with: libmctp,
1696586fc10SMatt Johnston)
1706586fc10SMatt Johnston
171e5b941d9SMatt Johnston# TODO: these should depend on the -internal.h headers so they rebuild
172e5b941d9SMatt Johnston# on changes, unclear how to do that.
173*5cc20932SPatrick Williamssizeof_mctp = compiler.sizeof(
174*5cc20932SPatrick Williams    'struct mctp',
175f9b99f1fSMatt Johnston    include_directories: libmctp_include_dir,
176*5cc20932SPatrick Williams    prefix: '#include "core-internal.h"',
177*5cc20932SPatrick Williams)
178*5cc20932SPatrick Williamssizeof_binding_i2c = compiler.sizeof(
179*5cc20932SPatrick Williams    'struct mctp_binding_i2c',
180e5b941d9SMatt Johnston    include_directories: libmctp_include_dir,
181*5cc20932SPatrick Williams    prefix: '#include "i2c-internal.h"',
182*5cc20932SPatrick Williams)
183*5cc20932SPatrick Williamssizes_h = configure_file(
184*5cc20932SPatrick Williams    configuration: {
185f9b99f1fSMatt Johnston        'sizeof_struct_mctp': sizeof_mctp,
186e5b941d9SMatt Johnston        'sizeof_binding_i2c': sizeof_binding_i2c,
187f9b99f1fSMatt Johnston    },
188f9b99f1fSMatt Johnston    input: 'libmctp-sizes.h.in',
189f9b99f1fSMatt Johnston    output: 'libmctp-sizes.h',
190f9b99f1fSMatt Johnston)
191f9b99f1fSMatt Johnstoninstall_headers(sizes_h)
192f9b99f1fSMatt Johnston
19363338a2eSMatt Johnstonif feat_fileio.allowed()
1946586fc10SMatt Johnston    subdir('utils')
19563338a2eSMatt Johnstonendif
1966586fc10SMatt Johnston
1976586fc10SMatt Johnstonif get_option('tests').allowed()
1986586fc10SMatt Johnston    subdir('tests')
1996586fc10SMatt Johnstonendif
200