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 | 63338a2 | 2024-09-11 09:53:59 +0800 | [diff] [blame] | 77 | feat_fileio = get_option('fileio').require( |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame^] | 78 | compiler.links( |
| 79 | ''' |
Matt Johnston | 63338a2 | 2024-09-11 09:53:59 +0800 | [diff] [blame] | 80 | #include <poll.h> |
| 81 | #include <unistd.h> |
| 82 | void main() |
| 83 | { |
| 84 | poll(NULL, 0, -1); |
| 85 | } |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame^] | 86 | ''', |
| 87 | ), |
| 88 | ) |
Matt Johnston | 63338a2 | 2024-09-11 09:53:59 +0800 | [diff] [blame] | 89 | if feat_fileio.allowed() |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame^] | 90 | add_project_arguments('-DMCTP_HAVE_FILEIO', language: 'c') |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 91 | endif |
| 92 | |
| 93 | if get_option('syslog').require( |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame^] | 94 | compiler.links( |
| 95 | ''' |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 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 | } |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame^] | 109 | ''', |
| 110 | ), |
| 111 | ).allowed() |
| 112 | add_project_arguments('-DMCTP_HAVE_SYSLOG', language: 'c') |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 113 | endif |
| 114 | |
| 115 | if get_option('stdio').require( |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame^] | 116 | compiler.links( |
| 117 | ''' |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 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 | } |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame^] | 131 | ''', |
| 132 | ), |
| 133 | ).allowed() |
| 134 | add_project_arguments('-DMCTP_HAVE_STDIO', language: 'c') |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 135 | endif |
| 136 | |
| 137 | # pcap is necessary for mctp-demux-daemon to be functional |
| 138 | pcap_dep = dependency('libpcap', required: false) |
| 139 | |
| 140 | systemd_dep = dependency('systemd', required: false) |
| 141 | libsystemd_dep = dependency('libsystemd', required: false) |
| 142 | |
| 143 | libmctp_include_dir = include_directories('.', is_system: true) |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame^] | 144 | libmctp = library( |
| 145 | 'mctp', |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 146 | libmctp_sources, |
| 147 | include_directories: libmctp_include_dir, |
| 148 | version: meson.project_version(), |
| 149 | install: true, |
| 150 | ) |
| 151 | install_headers(libmctp_headers) |
| 152 | |
| 153 | if 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) |
| 157 | endif |
| 158 | |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame^] | 159 | import('pkgconfig').generate( |
| 160 | libmctp, |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 161 | name: 'libmctp', |
| 162 | description: 'MCTP protocol implementation', |
| 163 | version: meson.project_version(), |
| 164 | ) |
| 165 | |
| 166 | libmctp_dep = declare_dependency( |
| 167 | include_directories: libmctp_include_dir, |
| 168 | link_with: libmctp, |
| 169 | ) |
| 170 | |
Matt Johnston | e5b941d | 2024-09-17 16:44:38 +0800 | [diff] [blame] | 171 | # TODO: these should depend on the -internal.h headers so they rebuild |
| 172 | # on changes, unclear how to do that. |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame^] | 173 | sizeof_mctp = compiler.sizeof( |
| 174 | 'struct mctp', |
Matt Johnston | f9b99f1 | 2024-09-17 16:48:34 +0800 | [diff] [blame] | 175 | include_directories: libmctp_include_dir, |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame^] | 176 | prefix: '#include "core-internal.h"', |
| 177 | ) |
| 178 | sizeof_binding_i2c = compiler.sizeof( |
| 179 | 'struct mctp_binding_i2c', |
Matt Johnston | e5b941d | 2024-09-17 16:44:38 +0800 | [diff] [blame] | 180 | include_directories: libmctp_include_dir, |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame^] | 181 | prefix: '#include "i2c-internal.h"', |
| 182 | ) |
| 183 | sizes_h = configure_file( |
| 184 | configuration: { |
Matt Johnston | f9b99f1 | 2024-09-17 16:48:34 +0800 | [diff] [blame] | 185 | 'sizeof_struct_mctp': sizeof_mctp, |
Matt Johnston | e5b941d | 2024-09-17 16:44:38 +0800 | [diff] [blame] | 186 | 'sizeof_binding_i2c': sizeof_binding_i2c, |
Matt Johnston | f9b99f1 | 2024-09-17 16:48:34 +0800 | [diff] [blame] | 187 | }, |
| 188 | input: 'libmctp-sizes.h.in', |
| 189 | output: 'libmctp-sizes.h', |
Patrick Williams | 5cc2093 | 2025-02-01 08:37:58 -0500 | [diff] [blame^] | 190 | ) |
Matt Johnston | f9b99f1 | 2024-09-17 16:48:34 +0800 | [diff] [blame] | 191 | install_headers(sizes_h) |
| 192 | |
Matt Johnston | 63338a2 | 2024-09-11 09:53:59 +0800 | [diff] [blame] | 193 | if feat_fileio.allowed() |
| 194 | subdir('utils') |
| 195 | endif |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 196 | |
| 197 | if get_option('tests').allowed() |
| 198 | subdir('tests') |
| 199 | endif |