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