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