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 'control.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 42i2c_sources = [ 43 'i2c.c', 44] 45 46i2c_headers = [ 47 'libmctp-i2c.h', 48] 49control_sources = [ 50 'control.c', 51] 52 53libmctp_sources = sources 54libmctp_headers = headers 55 56if get_option('bindings').contains('serial') 57 libmctp_sources += serial_sources 58 libmctp_headers += serial_headers 59endif 60if get_option('bindings').contains('astlpc') 61 libmctp_sources += astlpc_sources 62 libmctp_headers += astlpc_headers 63endif 64if get_option('bindings').contains('i2c') 65 libmctp_sources += i2c_sources 66 libmctp_headers += i2c_headers 67endif 68if get_option('control') 69 libmctp_sources += control_sources 70endif 71 72compiler = meson.get_compiler('c') 73 74if not get_option('custom_alloc') and get_option('default_alloc').require( 75 compiler.links(''' 76 #include <stdlib.h> 77 void main() 78 { 79 free(malloc(4096)); 80 } 81 ''')).allowed() 82 add_project_arguments('-DMCTP_DEFAULT_ALLOC', language : 'c') 83endif 84 85if get_option('custom_alloc') 86 add_project_arguments('-DMCTP_CUSTOM_ALLOC', language : 'c') 87endif 88 89if get_option('nolog') 90 add_project_arguments('-DMCTP_NOLOG', language : 'c') 91else 92 libmctp_sources += ['log.c'] 93endif 94 95feat_fileio = get_option('fileio').require( 96 compiler.links(''' 97 #include <poll.h> 98 #include <unistd.h> 99 void main() 100 { 101 poll(NULL, 0, -1); 102 } 103 ''')) 104if feat_fileio.allowed() 105 add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c') 106endif 107 108if get_option('syslog').require( 109 compiler.links(''' 110 #include <stdarg.h> 111 #include <syslog.h> 112 void check_vsyslog(int level, const char *fmt, ...) 113 { 114 va_list ap; 115 va_start(ap, fmt); 116 vsyslog(0, fmt, ap); 117 va_end(ap); 118 } 119 void main() 120 { 121 check_vsyslog(0, "\n"); 122 } 123 ''')).allowed() 124 add_project_arguments('-DMCTP_HAVE_SYSLOG', language : 'c') 125endif 126 127if get_option('stdio').require( 128 compiler.links(''' 129 #include <stdarg.h> 130 #include <stdio.h> 131 void check_vsyslog(const char *fmt, ...) 132 { 133 va_list ap; 134 va_start(ap, fmt); 135 vprintf(fmt, ap); 136 va_end(ap); 137 } 138 void main() 139 { 140 check_vsyslog("\n"); 141 } 142 ''')).allowed() 143 add_project_arguments('-DMCTP_HAVE_STDIO', language : 'c') 144endif 145 146# pcap is necessary for mctp-demux-daemon to be functional 147pcap_dep = dependency('libpcap', required: false) 148 149systemd_dep = dependency('systemd', required: false) 150libsystemd_dep = dependency('libsystemd', required: false) 151 152libmctp_include_dir = include_directories('.', is_system: true) 153libmctp = library('mctp', 154 libmctp_sources, 155 include_directories: libmctp_include_dir, 156 version: meson.project_version(), 157 install: true, 158) 159install_headers(libmctp_headers) 160 161if systemd_dep.found() 162 unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir') 163 install_data('systemd/system/mctp-demux.service', install_dir: unitdir) 164 install_data('systemd/system/mctp-demux.socket', install_dir: unitdir) 165endif 166 167import('pkgconfig').generate(libmctp, 168 name: 'libmctp', 169 description: 'MCTP protocol implementation', 170 version: meson.project_version(), 171) 172 173libmctp_dep = declare_dependency( 174 include_directories: libmctp_include_dir, 175 link_with: libmctp, 176) 177 178# TODO: these should depend on the -internal.h headers so they rebuild 179# on changes, unclear how to do that. 180sizeof_mctp = compiler.sizeof('struct mctp', 181 include_directories: libmctp_include_dir, 182 prefix: '#include "core-internal.h"') 183sizeof_binding_i2c = compiler.sizeof('struct mctp_binding_i2c', 184 include_directories: libmctp_include_dir, 185 prefix: '#include "i2c-internal.h"') 186sizes_h = configure_file(configuration: { 187 'sizeof_struct_mctp': sizeof_mctp, 188 'sizeof_binding_i2c': sizeof_binding_i2c, 189 }, 190 input: 'libmctp-sizes.h.in', 191 output: 'libmctp-sizes.h', 192 ) 193install_headers(sizes_h) 194 195if feat_fileio.allowed() 196 subdir('utils') 197endif 198 199if get_option('tests').allowed() 200 subdir('tests') 201endif 202