1project( 2 'libmctp', 3 'c', 4 meson_version: '>= 1.1', 5 version: '0.11', 6 default_options: [ 7 'debug=true', 8 'optimization=g', 9 'warning_level=2', 10 'werror=true', 11 'tests=' + (meson.is_subproject() ? 'disabled' : 'enabled'), 12 ], 13) 14 15sources = ['core.c', 'alloc.c', 'control.c'] 16 17headers = ['libmctp.h'] 18 19serial_sources = ['serial.c', 'crc-16-ccitt.c'] 20 21serial_headers = ['libmctp-serial.h'] 22 23astlpc_sources = ['astlpc.c', 'crc32.c'] 24 25astlpc_headers = ['libmctp-astlpc.h'] 26 27i2c_sources = ['i2c.c'] 28 29i2c_headers = ['libmctp-i2c.h'] 30control_sources = ['control.c'] 31 32libmctp_sources = sources 33libmctp_headers = headers 34 35if get_option('bindings').contains('serial') 36 libmctp_sources += serial_sources 37 libmctp_headers += serial_headers 38endif 39if get_option('bindings').contains('astlpc') 40 libmctp_sources += astlpc_sources 41 libmctp_headers += astlpc_headers 42endif 43if get_option('bindings').contains('i2c') 44 libmctp_sources += i2c_sources 45 libmctp_headers += i2c_headers 46endif 47if get_option('control') 48 libmctp_sources += control_sources 49endif 50 51compiler = meson.get_compiler('c') 52 53if not get_option('custom_alloc') and get_option('default_alloc').require( 54 compiler.links( 55 ''' 56 #include <stdlib.h> 57 void main() 58 { 59 free(malloc(4096)); 60 } 61 ''', 62 ), 63).allowed() 64 add_project_arguments('-DMCTP_DEFAULT_ALLOC', language: 'c') 65endif 66 67if get_option('custom_alloc') 68 add_project_arguments('-DMCTP_CUSTOM_ALLOC', language: 'c') 69endif 70 71if get_option('nolog') 72 add_project_arguments('-DMCTP_NOLOG', language: 'c') 73else 74 libmctp_sources += ['log.c'] 75endif 76 77option_args = [ 78 '-DMCTP_MAX_MESSAGE_SIZE=@0@'.format(get_option('max_message_size')), 79 '-DMCTP_REASSEMBLY_CTXS=@0@'.format(get_option('reassembly_contexts')), 80 '-DMCTP_REQ_TAGS=@0@'.format(get_option('request_tags')), 81 '-DMCTP_DEFAULT_CLOCK_GETTIME=@0@'.format( 82 get_option('default_clock_gettime').to_int(), 83 ), 84 '-DMCTP_CONTROL_HANDLER=@0@'.format(get_option('control').to_int()), 85 '-DI2C_BTU=@0@'.format(get_option('i2c_mtu')), 86 '-DMCTP_I2C_NEIGH_COUNT=@0@'.format(get_option('i2c_neigh_count')), 87] 88 89add_project_arguments(option_args, language: 'c') 90 91feat_fileio = get_option('fileio').require( 92 compiler.links( 93 ''' 94 #include <poll.h> 95 #include <unistd.h> 96 void main() 97 { 98 poll(NULL, 0, -1); 99 } 100 ''', 101 ), 102) 103if feat_fileio.allowed() 104 add_project_arguments('-DMCTP_HAVE_FILEIO', language: 'c') 105endif 106 107if get_option('syslog').require( 108 compiler.links( 109 ''' 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 ''', 124 ), 125).allowed() 126 add_project_arguments('-DMCTP_HAVE_SYSLOG', language: 'c') 127endif 128 129if get_option('stdio').require( 130 compiler.links( 131 ''' 132 #include <stdarg.h> 133 #include <stdio.h> 134 void check_vsyslog(const char *fmt, ...) 135 { 136 va_list ap; 137 va_start(ap, fmt); 138 vprintf(fmt, ap); 139 va_end(ap); 140 } 141 void main() 142 { 143 check_vsyslog("\n"); 144 } 145 ''', 146 ), 147).allowed() 148 add_project_arguments('-DMCTP_HAVE_STDIO', language: 'c') 149endif 150 151# pcap is necessary for mctp-demux-daemon to be functional 152pcap_dep = dependency('libpcap', required: false) 153 154systemd_dep = dependency('systemd', required: false) 155libsystemd_dep = dependency('libsystemd', required: false) 156 157libmctp_include_dir = include_directories('.', is_system: true) 158libmctp = library( 159 'mctp', 160 libmctp_sources, 161 include_directories: libmctp_include_dir, 162 version: meson.project_version(), 163 install: true, 164) 165install_headers(libmctp_headers) 166 167if systemd_dep.found() 168 unitdir = systemd_dep.get_variable(pkgconfig: 'systemd_system_unit_dir') 169 install_data('systemd/system/mctp-demux.service', install_dir: unitdir) 170 install_data('systemd/system/mctp-demux.socket', install_dir: unitdir) 171endif 172 173import('pkgconfig').generate( 174 libmctp, 175 name: 'libmctp', 176 description: 'MCTP protocol implementation', 177 version: meson.project_version(), 178) 179 180libmctp_dep = declare_dependency( 181 include_directories: libmctp_include_dir, 182 link_with: libmctp, 183) 184 185# TODO: these should depend on the -internal.h headers so they rebuild 186# on changes, unclear how to do that. 187sizeof_mctp = compiler.sizeof( 188 'struct mctp', 189 include_directories: libmctp_include_dir, 190 args: option_args, 191 prefix: '#include "core-internal.h"', 192) 193sizeof_binding_i2c = compiler.sizeof( 194 'struct mctp_binding_i2c', 195 include_directories: libmctp_include_dir, 196 args: option_args, 197 prefix: '#include "i2c-internal.h"', 198) 199sizes_h = configure_file( 200 configuration: { 201 'sizeof_struct_mctp': sizeof_mctp, 202 'sizeof_binding_i2c': sizeof_binding_i2c, 203 }, 204 input: 'libmctp-sizes.h.in', 205 output: 'libmctp-sizes.h', 206) 207install_headers(sizes_h) 208 209if feat_fileio.allowed() 210 subdir('utils') 211endif 212 213if get_option('tests').allowed() 214 subdir('tests') 215endif 216