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] 186586fc10SMatt Johnston 196586fc10SMatt Johnstonheaders = [ 206586fc10SMatt Johnston 'libmctp.h', 216586fc10SMatt Johnston] 226586fc10SMatt Johnston 236586fc10SMatt Johnstonserial_sources = [ 246586fc10SMatt Johnston 'serial.c', 256586fc10SMatt Johnston 'crc-16-ccitt.c', 266586fc10SMatt Johnston] 276586fc10SMatt Johnston 286586fc10SMatt Johnstonserial_headers = [ 296586fc10SMatt Johnston 'libmctp-serial.h' 306586fc10SMatt Johnston] 316586fc10SMatt Johnston 326586fc10SMatt Johnstonastlpc_sources = [ 336586fc10SMatt Johnston 'astlpc.c', 346586fc10SMatt Johnston 'crc32.c', 356586fc10SMatt Johnston] 366586fc10SMatt Johnston 376586fc10SMatt Johnstonastlpc_headers = [ 386586fc10SMatt Johnston 'libmctp-astlpc.h', 396586fc10SMatt Johnston] 406586fc10SMatt Johnston 41*e5b941d9SMatt Johnstoni2c_sources = [ 42*e5b941d9SMatt Johnston 'i2c.c', 43*e5b941d9SMatt Johnston] 44*e5b941d9SMatt Johnston 45*e5b941d9SMatt Johnstoni2c_headers = [ 46*e5b941d9SMatt Johnston 'libmctp-i2c.h', 47*e5b941d9SMatt Johnston] 48*e5b941d9SMatt Johnston 496586fc10SMatt Johnstonlibmctp_sources = sources 506586fc10SMatt Johnstonlibmctp_headers = headers 516586fc10SMatt Johnston 526586fc10SMatt Johnstonif get_option('bindings').contains('serial') 536586fc10SMatt Johnston libmctp_sources += serial_sources 546586fc10SMatt Johnston libmctp_headers += serial_headers 556586fc10SMatt Johnstonendif 566586fc10SMatt Johnstonif get_option('bindings').contains('astlpc') 576586fc10SMatt Johnston libmctp_sources += astlpc_sources 586586fc10SMatt Johnston libmctp_headers += astlpc_headers 596586fc10SMatt Johnstonendif 60*e5b941d9SMatt Johnstonif get_option('bindings').contains('i2c') 61*e5b941d9SMatt Johnston libmctp_sources += i2c_sources 62*e5b941d9SMatt Johnston libmctp_headers += i2c_headers 63*e5b941d9SMatt Johnstonendif 646586fc10SMatt Johnston 656586fc10SMatt Johnstoncompiler = meson.get_compiler('c') 666586fc10SMatt Johnston 67bbfcc6e1SMatt Johnstonif not get_option('custom_alloc') and get_option('default_alloc').require( 686586fc10SMatt Johnston compiler.links(''' 696586fc10SMatt Johnston #include <stdlib.h> 706586fc10SMatt Johnston void main() 716586fc10SMatt Johnston { 726586fc10SMatt Johnston free(malloc(4096)); 736586fc10SMatt Johnston } 746586fc10SMatt Johnston ''')).allowed() 756586fc10SMatt Johnston add_project_arguments('-DMCTP_DEFAULT_ALLOC', language : 'c') 766586fc10SMatt Johnstonendif 776586fc10SMatt Johnston 78bbfcc6e1SMatt Johnstonif get_option('custom_alloc') 79bbfcc6e1SMatt Johnston add_project_arguments('-DMCTP_CUSTOM_ALLOC', language : 'c') 80bbfcc6e1SMatt Johnstonendif 81bbfcc6e1SMatt Johnston 821250727fSMatt Johnstonif get_option('nolog') 831250727fSMatt Johnston add_project_arguments('-DMCTP_NOLOG', language : 'c') 841250727fSMatt Johnstonelse 851250727fSMatt Johnston libmctp_sources += ['log.c'] 861250727fSMatt Johnstonendif 871250727fSMatt Johnston 8863338a2eSMatt Johnstonfeat_fileio = get_option('fileio').require( 8963338a2eSMatt Johnston compiler.links(''' 9063338a2eSMatt Johnston #include <poll.h> 9163338a2eSMatt Johnston #include <unistd.h> 9263338a2eSMatt Johnston void main() 9363338a2eSMatt Johnston { 9463338a2eSMatt Johnston poll(NULL, 0, -1); 9563338a2eSMatt Johnston } 9663338a2eSMatt Johnston ''')) 9763338a2eSMatt Johnstonif feat_fileio.allowed() 986586fc10SMatt Johnston add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c') 996586fc10SMatt Johnstonendif 1006586fc10SMatt Johnston 1016586fc10SMatt Johnstonif get_option('syslog').require( 1026586fc10SMatt Johnston compiler.links(''' 1036586fc10SMatt Johnston #include <stdarg.h> 1046586fc10SMatt Johnston #include <syslog.h> 1056586fc10SMatt Johnston void check_vsyslog(int level, const char *fmt, ...) 1066586fc10SMatt Johnston { 1076586fc10SMatt Johnston va_list ap; 1086586fc10SMatt Johnston va_start(ap, fmt); 1096586fc10SMatt Johnston vsyslog(0, fmt, ap); 1106586fc10SMatt Johnston va_end(ap); 1116586fc10SMatt Johnston } 1126586fc10SMatt Johnston void main() 1136586fc10SMatt Johnston { 1146586fc10SMatt Johnston check_vsyslog(0, "\n"); 1156586fc10SMatt Johnston } 1166586fc10SMatt Johnston ''')).allowed() 1176586fc10SMatt Johnston add_project_arguments('-DMCTP_HAVE_SYSLOG', language : 'c') 1186586fc10SMatt Johnstonendif 1196586fc10SMatt Johnston 1206586fc10SMatt Johnstonif get_option('stdio').require( 1216586fc10SMatt Johnston compiler.links(''' 1226586fc10SMatt Johnston #include <stdarg.h> 1236586fc10SMatt Johnston #include <stdio.h> 1246586fc10SMatt Johnston void check_vsyslog(const char *fmt, ...) 1256586fc10SMatt Johnston { 1266586fc10SMatt Johnston va_list ap; 1276586fc10SMatt Johnston va_start(ap, fmt); 1286586fc10SMatt Johnston vprintf(fmt, ap); 1296586fc10SMatt Johnston va_end(ap); 1306586fc10SMatt Johnston } 1316586fc10SMatt Johnston void main() 1326586fc10SMatt Johnston { 1336586fc10SMatt Johnston check_vsyslog("\n"); 1346586fc10SMatt Johnston } 1356586fc10SMatt Johnston ''')).allowed() 1366586fc10SMatt Johnston add_project_arguments('-DMCTP_HAVE_STDIO', language : 'c') 1376586fc10SMatt Johnstonendif 1386586fc10SMatt Johnston 1396586fc10SMatt Johnston# pcap is necessary for mctp-demux-daemon to be functional 1406586fc10SMatt Johnstonpcap_dep = dependency('libpcap', required: false) 1416586fc10SMatt Johnston 1426586fc10SMatt Johnstonsystemd_dep = dependency('systemd', required: false) 1436586fc10SMatt Johnstonlibsystemd_dep = dependency('libsystemd', required: false) 1446586fc10SMatt Johnston 1456586fc10SMatt Johnstonlibmctp_include_dir = include_directories('.', is_system: true) 1466586fc10SMatt Johnstonlibmctp = library('mctp', 1476586fc10SMatt Johnston libmctp_sources, 1486586fc10SMatt Johnston include_directories: libmctp_include_dir, 1496586fc10SMatt Johnston version: meson.project_version(), 1506586fc10SMatt Johnston install: true, 1516586fc10SMatt Johnston) 1526586fc10SMatt Johnstoninstall_headers(libmctp_headers) 1536586fc10SMatt Johnston 1546586fc10SMatt Johnstonif systemd_dep.found() 1556586fc10SMatt Johnston unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir') 1566586fc10SMatt Johnston install_data('systemd/system/mctp-demux.service', install_dir: unitdir) 1576586fc10SMatt Johnston install_data('systemd/system/mctp-demux.socket', install_dir: unitdir) 1586586fc10SMatt Johnstonendif 1596586fc10SMatt Johnston 1606586fc10SMatt Johnstonimport('pkgconfig').generate(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 171*e5b941d9SMatt Johnston# TODO: these should depend on the -internal.h headers so they rebuild 172*e5b941d9SMatt Johnston# on changes, unclear how to do that. 173f9b99f1fSMatt Johnstonsizeof_mctp = compiler.sizeof('struct mctp', 174f9b99f1fSMatt Johnston include_directories: libmctp_include_dir, 175f9b99f1fSMatt Johnston prefix: '#include "core-internal.h"') 176*e5b941d9SMatt Johnstonsizeof_binding_i2c = compiler.sizeof('struct mctp_binding_i2c', 177*e5b941d9SMatt Johnston include_directories: libmctp_include_dir, 178*e5b941d9SMatt Johnston prefix: '#include "i2c-internal.h"') 179f9b99f1fSMatt Johnstonsizes_h = configure_file(configuration: { 180f9b99f1fSMatt Johnston 'sizeof_struct_mctp': sizeof_mctp, 181*e5b941d9SMatt Johnston 'sizeof_binding_i2c': sizeof_binding_i2c, 182f9b99f1fSMatt Johnston }, 183f9b99f1fSMatt Johnston input: 'libmctp-sizes.h.in', 184f9b99f1fSMatt Johnston output: 'libmctp-sizes.h', 185f9b99f1fSMatt Johnston ) 186f9b99f1fSMatt Johnstoninstall_headers(sizes_h) 187f9b99f1fSMatt Johnston 18863338a2eSMatt Johnstonif feat_fileio.allowed() 1896586fc10SMatt Johnston subdir('utils') 19063338a2eSMatt Johnstonendif 1916586fc10SMatt Johnston 1926586fc10SMatt Johnstonif get_option('tests').allowed() 1936586fc10SMatt Johnston subdir('tests') 1946586fc10SMatt Johnstonendif 195