xref: /openbmc/libmctp/meson.build (revision 63338a2e)
16586fc10SMatt Johnstonproject(
26586fc10SMatt Johnston    'libmctp', 'c',
36586fc10SMatt Johnston    meson_version: '>= 1.1',
46586fc10SMatt Johnston    version: '0.11',
56586fc10SMatt Johnston    default_options: [
66586fc10SMatt Johnston        'debug=true',
76586fc10SMatt Johnston        'optimization=g',
86586fc10SMatt Johnston        'warning_level=2',
96586fc10SMatt Johnston        'werror=true',
106586fc10SMatt Johnston        'tests=' + (meson.is_subproject() ? 'disabled' : 'enabled'),
116586fc10SMatt Johnston    ],
126586fc10SMatt Johnston)
136586fc10SMatt Johnston
146586fc10SMatt Johnstonsources = [
156586fc10SMatt Johnston     'core.c',
166586fc10SMatt Johnston     'alloc.c',
176586fc10SMatt Johnston     'log.c',
186586fc10SMatt Johnston]
196586fc10SMatt Johnston
206586fc10SMatt Johnstonheaders = [
216586fc10SMatt Johnston    'libmctp.h',
226586fc10SMatt Johnston]
236586fc10SMatt Johnston
246586fc10SMatt Johnstonserial_sources = [
256586fc10SMatt Johnston    'serial.c',
266586fc10SMatt Johnston    'crc-16-ccitt.c',
276586fc10SMatt Johnston]
286586fc10SMatt Johnston
296586fc10SMatt Johnstonserial_headers = [
306586fc10SMatt Johnston    'libmctp-serial.h'
316586fc10SMatt Johnston]
326586fc10SMatt Johnston
336586fc10SMatt Johnstonastlpc_sources = [
346586fc10SMatt Johnston    'astlpc.c',
356586fc10SMatt Johnston    'crc32.c',
366586fc10SMatt Johnston]
376586fc10SMatt Johnston
386586fc10SMatt Johnstonastlpc_headers = [
396586fc10SMatt Johnston    'libmctp-astlpc.h',
406586fc10SMatt Johnston]
416586fc10SMatt Johnston
426586fc10SMatt Johnstonlibmctp_sources = sources
436586fc10SMatt Johnstonlibmctp_headers = headers
446586fc10SMatt Johnston
456586fc10SMatt Johnstonif get_option('bindings').contains('serial')
466586fc10SMatt Johnston    libmctp_sources += serial_sources
476586fc10SMatt Johnston    libmctp_headers += serial_headers
486586fc10SMatt Johnstonendif
496586fc10SMatt Johnstonif get_option('bindings').contains('astlpc')
506586fc10SMatt Johnston    libmctp_sources += astlpc_sources
516586fc10SMatt Johnston    libmctp_headers += astlpc_headers
526586fc10SMatt Johnstonendif
536586fc10SMatt Johnston
546586fc10SMatt Johnstoncompiler = meson.get_compiler('c')
556586fc10SMatt Johnston
566586fc10SMatt Johnstonif get_option('default_alloc').require(
576586fc10SMatt Johnston    compiler.links('''
586586fc10SMatt Johnston        #include <stdlib.h>
596586fc10SMatt Johnston        void main()
606586fc10SMatt Johnston        {
616586fc10SMatt Johnston            free(malloc(4096));
626586fc10SMatt Johnston        }
636586fc10SMatt Johnston    ''')).allowed()
646586fc10SMatt Johnston    add_project_arguments('-DMCTP_DEFAULT_ALLOC', language : 'c')
656586fc10SMatt Johnstonendif
666586fc10SMatt Johnston
67*63338a2eSMatt Johnstonfeat_fileio = get_option('fileio').require(
68*63338a2eSMatt Johnston    compiler.links('''
69*63338a2eSMatt Johnston        #include <poll.h>
70*63338a2eSMatt Johnston        #include <unistd.h>
71*63338a2eSMatt Johnston        void main()
72*63338a2eSMatt Johnston        {
73*63338a2eSMatt Johnston            poll(NULL, 0, -1);
74*63338a2eSMatt Johnston        }
75*63338a2eSMatt Johnston    '''))
76*63338a2eSMatt Johnstonif feat_fileio.allowed()
776586fc10SMatt Johnston    add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c')
786586fc10SMatt Johnstonendif
796586fc10SMatt Johnston
806586fc10SMatt Johnstonif get_option('syslog').require(
816586fc10SMatt Johnston    compiler.links('''
826586fc10SMatt Johnston        #include <stdarg.h>
836586fc10SMatt Johnston        #include <syslog.h>
846586fc10SMatt Johnston        void check_vsyslog(int level, const char *fmt, ...)
856586fc10SMatt Johnston        {
866586fc10SMatt Johnston            va_list ap;
876586fc10SMatt Johnston            va_start(ap, fmt);
886586fc10SMatt Johnston            vsyslog(0, fmt, ap);
896586fc10SMatt Johnston            va_end(ap);
906586fc10SMatt Johnston        }
916586fc10SMatt Johnston        void main()
926586fc10SMatt Johnston        {
936586fc10SMatt Johnston            check_vsyslog(0, "\n");
946586fc10SMatt Johnston        }
956586fc10SMatt Johnston        ''')).allowed()
966586fc10SMatt Johnston    add_project_arguments('-DMCTP_HAVE_SYSLOG', language : 'c')
976586fc10SMatt Johnstonendif
986586fc10SMatt Johnston
996586fc10SMatt Johnstonif get_option('stdio').require(
1006586fc10SMatt Johnston    compiler.links('''
1016586fc10SMatt Johnston        #include <stdarg.h>
1026586fc10SMatt Johnston        #include <stdio.h>
1036586fc10SMatt Johnston        void check_vsyslog(const char *fmt, ...)
1046586fc10SMatt Johnston        {
1056586fc10SMatt Johnston            va_list ap;
1066586fc10SMatt Johnston            va_start(ap, fmt);
1076586fc10SMatt Johnston            vprintf(fmt, ap);
1086586fc10SMatt Johnston            va_end(ap);
1096586fc10SMatt Johnston        }
1106586fc10SMatt Johnston        void main()
1116586fc10SMatt Johnston        {
1126586fc10SMatt Johnston            check_vsyslog("\n");
1136586fc10SMatt Johnston        }
1146586fc10SMatt Johnston        ''')).allowed()
1156586fc10SMatt Johnston    add_project_arguments('-DMCTP_HAVE_STDIO', language : 'c')
1166586fc10SMatt Johnstonendif
1176586fc10SMatt Johnston
1186586fc10SMatt Johnston# pcap is necessary for mctp-demux-daemon to be functional
1196586fc10SMatt Johnstonpcap_dep = dependency('libpcap', required: false)
1206586fc10SMatt Johnston
1216586fc10SMatt Johnstonsystemd_dep = dependency('systemd', required: false)
1226586fc10SMatt Johnstonlibsystemd_dep = dependency('libsystemd', required: false)
1236586fc10SMatt Johnston
1246586fc10SMatt Johnstonlibmctp_include_dir = include_directories('.', is_system: true)
1256586fc10SMatt Johnstonlibmctp = library('mctp',
1266586fc10SMatt Johnston    libmctp_sources,
1276586fc10SMatt Johnston    include_directories: libmctp_include_dir,
1286586fc10SMatt Johnston    version: meson.project_version(),
1296586fc10SMatt Johnston    install: true,
1306586fc10SMatt Johnston)
1316586fc10SMatt Johnstoninstall_headers(libmctp_headers)
1326586fc10SMatt Johnston
1336586fc10SMatt Johnstonif systemd_dep.found()
1346586fc10SMatt Johnston    unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir')
1356586fc10SMatt Johnston    install_data('systemd/system/mctp-demux.service', install_dir: unitdir)
1366586fc10SMatt Johnston    install_data('systemd/system/mctp-demux.socket', install_dir: unitdir)
1376586fc10SMatt Johnstonendif
1386586fc10SMatt Johnston
1396586fc10SMatt Johnstonimport('pkgconfig').generate(libmctp,
1406586fc10SMatt Johnston    name: 'libmctp',
1416586fc10SMatt Johnston    description: 'MCTP protocol implementation',
1426586fc10SMatt Johnston    version: meson.project_version(),
1436586fc10SMatt Johnston)
1446586fc10SMatt Johnston
1456586fc10SMatt Johnstonlibmctp_dep = declare_dependency(
1466586fc10SMatt Johnston    include_directories: libmctp_include_dir,
1476586fc10SMatt Johnston    link_with: libmctp,
1486586fc10SMatt Johnston)
1496586fc10SMatt Johnston
150*63338a2eSMatt Johnstonif feat_fileio.allowed()
1516586fc10SMatt Johnston    subdir('utils')
152*63338a2eSMatt Johnstonendif
1536586fc10SMatt Johnston
1546586fc10SMatt Johnstonif get_option('tests').allowed()
1556586fc10SMatt Johnston    subdir('tests')
1566586fc10SMatt Johnstonendif
157