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 41libmctp_sources = sources 42libmctp_headers = headers 43 44if get_option('bindings').contains('serial') 45 libmctp_sources += serial_sources 46 libmctp_headers += serial_headers 47endif 48if get_option('bindings').contains('astlpc') 49 libmctp_sources += astlpc_sources 50 libmctp_headers += astlpc_headers 51endif 52 53compiler = meson.get_compiler('c') 54 55if not get_option('custom_alloc') and get_option('default_alloc').require( 56 compiler.links(''' 57 #include <stdlib.h> 58 void main() 59 { 60 free(malloc(4096)); 61 } 62 ''')).allowed() 63 add_project_arguments('-DMCTP_DEFAULT_ALLOC', language : 'c') 64endif 65 66if get_option('custom_alloc') 67 add_project_arguments('-DMCTP_CUSTOM_ALLOC', language : 'c') 68endif 69 70if get_option('nolog') 71 add_project_arguments('-DMCTP_NOLOG', language : 'c') 72else 73 libmctp_sources += ['log.c'] 74endif 75 76feat_fileio = get_option('fileio').require( 77 compiler.links(''' 78 #include <poll.h> 79 #include <unistd.h> 80 void main() 81 { 82 poll(NULL, 0, -1); 83 } 84 ''')) 85if feat_fileio.allowed() 86 add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c') 87endif 88 89if get_option('syslog').require( 90 compiler.links(''' 91 #include <stdarg.h> 92 #include <syslog.h> 93 void check_vsyslog(int level, const char *fmt, ...) 94 { 95 va_list ap; 96 va_start(ap, fmt); 97 vsyslog(0, fmt, ap); 98 va_end(ap); 99 } 100 void main() 101 { 102 check_vsyslog(0, "\n"); 103 } 104 ''')).allowed() 105 add_project_arguments('-DMCTP_HAVE_SYSLOG', language : 'c') 106endif 107 108if get_option('stdio').require( 109 compiler.links(''' 110 #include <stdarg.h> 111 #include <stdio.h> 112 void check_vsyslog(const char *fmt, ...) 113 { 114 va_list ap; 115 va_start(ap, fmt); 116 vprintf(fmt, ap); 117 va_end(ap); 118 } 119 void main() 120 { 121 check_vsyslog("\n"); 122 } 123 ''')).allowed() 124 add_project_arguments('-DMCTP_HAVE_STDIO', language : 'c') 125endif 126 127# pcap is necessary for mctp-demux-daemon to be functional 128pcap_dep = dependency('libpcap', required: false) 129 130systemd_dep = dependency('systemd', required: false) 131libsystemd_dep = dependency('libsystemd', required: false) 132 133libmctp_include_dir = include_directories('.', is_system: true) 134libmctp = library('mctp', 135 libmctp_sources, 136 include_directories: libmctp_include_dir, 137 version: meson.project_version(), 138 install: true, 139) 140install_headers(libmctp_headers) 141 142if systemd_dep.found() 143 unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir') 144 install_data('systemd/system/mctp-demux.service', install_dir: unitdir) 145 install_data('systemd/system/mctp-demux.socket', install_dir: unitdir) 146endif 147 148import('pkgconfig').generate(libmctp, 149 name: 'libmctp', 150 description: 'MCTP protocol implementation', 151 version: meson.project_version(), 152) 153 154libmctp_dep = declare_dependency( 155 include_directories: libmctp_include_dir, 156 link_with: libmctp, 157) 158 159if feat_fileio.allowed() 160 subdir('utils') 161endif 162 163if get_option('tests').allowed() 164 subdir('tests') 165endif 166