Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 1 | project( |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 2 | 'libmctp', |
| 3 | 'c', |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 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 | |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 15 | sources = ['core.c', 'alloc.c', 'control.c'] |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 16 | |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 17 | headers = ['libmctp.h'] |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 18 | |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 19 | serial_sources = ['serial.c', 'crc-16-ccitt.c'] |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 20 | |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 21 | serial_headers = ['libmctp-serial.h'] |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 22 | |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 23 | astlpc_sources = ['astlpc.c', 'crc32.c'] |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 24 | |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 25 | astlpc_headers = ['libmctp-astlpc.h'] |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 26 | |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 27 | i2c_sources = ['i2c.c'] |
Matt Johnston | e5b941d | 2024-09-17 16:44:38 +0800 | [diff] [blame] | 28 | |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 29 | i2c_headers = ['libmctp-i2c.h'] |
| 30 | control_sources = ['control.c'] |
Matt Johnston | e5b941d | 2024-09-17 16:44:38 +0800 | [diff] [blame] | 31 | |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 32 | libmctp_sources = sources |
| 33 | libmctp_headers = headers |
| 34 | |
| 35 | if get_option('bindings').contains('serial') |
| 36 | libmctp_sources += serial_sources |
| 37 | libmctp_headers += serial_headers |
| 38 | endif |
| 39 | if get_option('bindings').contains('astlpc') |
| 40 | libmctp_sources += astlpc_sources |
| 41 | libmctp_headers += astlpc_headers |
| 42 | endif |
Matt Johnston | e5b941d | 2024-09-17 16:44:38 +0800 | [diff] [blame] | 43 | if get_option('bindings').contains('i2c') |
| 44 | libmctp_sources += i2c_sources |
| 45 | libmctp_headers += i2c_headers |
| 46 | endif |
Matt Johnston | 4058b2c | 2024-11-07 14:53:50 +0800 | [diff] [blame] | 47 | if get_option('control') |
| 48 | libmctp_sources += control_sources |
| 49 | endif |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 50 | |
| 51 | compiler = meson.get_compiler('c') |
| 52 | |
Matt Johnston | bbfcc6e | 2024-09-17 16:48:15 +0800 | [diff] [blame] | 53 | if not get_option('custom_alloc') and get_option('default_alloc').require( |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 54 | compiler.links( |
| 55 | ''' |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 56 | #include <stdlib.h> |
| 57 | void main() |
| 58 | { |
| 59 | free(malloc(4096)); |
| 60 | } |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 61 | ''', |
| 62 | ), |
| 63 | ).allowed() |
| 64 | add_project_arguments('-DMCTP_DEFAULT_ALLOC', language: 'c') |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 65 | endif |
| 66 | |
Matt Johnston | bbfcc6e | 2024-09-17 16:48:15 +0800 | [diff] [blame] | 67 | if get_option('custom_alloc') |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 68 | add_project_arguments('-DMCTP_CUSTOM_ALLOC', language: 'c') |
Matt Johnston | bbfcc6e | 2024-09-17 16:48:15 +0800 | [diff] [blame] | 69 | endif |
| 70 | |
Matt Johnston | 1250727 | 2024-10-01 12:17:19 +0800 | [diff] [blame] | 71 | if get_option('nolog') |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 72 | add_project_arguments('-DMCTP_NOLOG', language: 'c') |
Matt Johnston | 1250727 | 2024-10-01 12:17:19 +0800 | [diff] [blame] | 73 | else |
| 74 | libmctp_sources += ['log.c'] |
| 75 | endif |
| 76 | |
Matt Johnston | b04447c | 2025-09-18 15:51:04 +0800 | [diff] [blame^] | 77 | option_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 | |
| 89 | add_project_arguments(option_args, language: 'c') |
| 90 | |
Matt Johnston | 63338a2 | 2024-09-11 09:53:59 +0800 | [diff] [blame] | 91 | feat_fileio = get_option('fileio').require( |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 92 | compiler.links( |
| 93 | ''' |
Matt Johnston | 63338a2 | 2024-09-11 09:53:59 +0800 | [diff] [blame] | 94 | #include <poll.h> |
| 95 | #include <unistd.h> |
| 96 | void main() |
| 97 | { |
| 98 | poll(NULL, 0, -1); |
| 99 | } |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 100 | ''', |
| 101 | ), |
| 102 | ) |
Matt Johnston | 63338a2 | 2024-09-11 09:53:59 +0800 | [diff] [blame] | 103 | if feat_fileio.allowed() |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 104 | add_project_arguments('-DMCTP_HAVE_FILEIO', language: 'c') |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 105 | endif |
| 106 | |
| 107 | if get_option('syslog').require( |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 108 | compiler.links( |
| 109 | ''' |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 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 | } |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 123 | ''', |
| 124 | ), |
| 125 | ).allowed() |
| 126 | add_project_arguments('-DMCTP_HAVE_SYSLOG', language: 'c') |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 127 | endif |
| 128 | |
| 129 | if get_option('stdio').require( |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 130 | compiler.links( |
| 131 | ''' |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 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 | } |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 145 | ''', |
| 146 | ), |
| 147 | ).allowed() |
| 148 | add_project_arguments('-DMCTP_HAVE_STDIO', language: 'c') |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 149 | endif |
| 150 | |
| 151 | # pcap is necessary for mctp-demux-daemon to be functional |
| 152 | pcap_dep = dependency('libpcap', required: false) |
| 153 | |
| 154 | systemd_dep = dependency('systemd', required: false) |
| 155 | libsystemd_dep = dependency('libsystemd', required: false) |
| 156 | |
| 157 | libmctp_include_dir = include_directories('.', is_system: true) |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 158 | libmctp = library( |
| 159 | 'mctp', |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 160 | libmctp_sources, |
| 161 | include_directories: libmctp_include_dir, |
| 162 | version: meson.project_version(), |
| 163 | install: true, |
| 164 | ) |
| 165 | install_headers(libmctp_headers) |
| 166 | |
| 167 | if systemd_dep.found() |
Patrick Williams | c243823 | 2025-07-09 11:27:39 -0400 | [diff] [blame] | 168 | unitdir = systemd_dep.get_variable(pkgconfig: 'systemd_system_unit_dir') |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 169 | install_data('systemd/system/mctp-demux.service', install_dir: unitdir) |
| 170 | install_data('systemd/system/mctp-demux.socket', install_dir: unitdir) |
| 171 | endif |
| 172 | |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 173 | import('pkgconfig').generate( |
| 174 | libmctp, |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 175 | name: 'libmctp', |
| 176 | description: 'MCTP protocol implementation', |
| 177 | version: meson.project_version(), |
| 178 | ) |
| 179 | |
| 180 | libmctp_dep = declare_dependency( |
| 181 | include_directories: libmctp_include_dir, |
| 182 | link_with: libmctp, |
| 183 | ) |
| 184 | |
Matt Johnston | e5b941d | 2024-09-17 16:44:38 +0800 | [diff] [blame] | 185 | # TODO: these should depend on the -internal.h headers so they rebuild |
| 186 | # on changes, unclear how to do that. |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 187 | sizeof_mctp = compiler.sizeof( |
| 188 | 'struct mctp', |
Matt Johnston | f9b99f1 | 2024-09-17 16:48:34 +0800 | [diff] [blame] | 189 | include_directories: libmctp_include_dir, |
Matt Johnston | b04447c | 2025-09-18 15:51:04 +0800 | [diff] [blame^] | 190 | args: option_args, |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 191 | prefix: '#include "core-internal.h"', |
| 192 | ) |
| 193 | sizeof_binding_i2c = compiler.sizeof( |
| 194 | 'struct mctp_binding_i2c', |
Matt Johnston | e5b941d | 2024-09-17 16:44:38 +0800 | [diff] [blame] | 195 | include_directories: libmctp_include_dir, |
Matt Johnston | b04447c | 2025-09-18 15:51:04 +0800 | [diff] [blame^] | 196 | args: option_args, |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 197 | prefix: '#include "i2c-internal.h"', |
| 198 | ) |
| 199 | sizes_h = configure_file( |
| 200 | configuration: { |
Matt Johnston | f9b99f1 | 2024-09-17 16:48:34 +0800 | [diff] [blame] | 201 | 'sizeof_struct_mctp': sizeof_mctp, |
Matt Johnston | e5b941d | 2024-09-17 16:44:38 +0800 | [diff] [blame] | 202 | 'sizeof_binding_i2c': sizeof_binding_i2c, |
Matt Johnston | f9b99f1 | 2024-09-17 16:48:34 +0800 | [diff] [blame] | 203 | }, |
| 204 | input: 'libmctp-sizes.h.in', |
| 205 | output: 'libmctp-sizes.h', |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame] | 206 | ) |
Matt Johnston | f9b99f1 | 2024-09-17 16:48:34 +0800 | [diff] [blame] | 207 | install_headers(sizes_h) |
| 208 | |
Matt Johnston | 63338a2 | 2024-09-11 09:53:59 +0800 | [diff] [blame] | 209 | if feat_fileio.allowed() |
| 210 | subdir('utils') |
| 211 | endif |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 212 | |
| 213 | if get_option('tests').allowed() |
| 214 | subdir('tests') |
| 215 | endif |