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