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 | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 17 | ] |
| 18 | |
| 19 | headers = [ |
| 20 | 'libmctp.h', |
| 21 | ] |
| 22 | |
| 23 | serial_sources = [ |
| 24 | 'serial.c', |
| 25 | 'crc-16-ccitt.c', |
| 26 | ] |
| 27 | |
| 28 | serial_headers = [ |
| 29 | 'libmctp-serial.h' |
| 30 | ] |
| 31 | |
| 32 | astlpc_sources = [ |
| 33 | 'astlpc.c', |
| 34 | 'crc32.c', |
| 35 | ] |
| 36 | |
| 37 | astlpc_headers = [ |
| 38 | 'libmctp-astlpc.h', |
| 39 | ] |
| 40 | |
Matt Johnston | e5b941d | 2024-09-17 16:44:38 +0800 | [diff] [blame] | 41 | i2c_sources = [ |
| 42 | 'i2c.c', |
| 43 | ] |
| 44 | |
| 45 | i2c_headers = [ |
| 46 | 'libmctp-i2c.h', |
| 47 | ] |
| 48 | |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 49 | libmctp_sources = sources |
| 50 | libmctp_headers = headers |
| 51 | |
| 52 | if get_option('bindings').contains('serial') |
| 53 | libmctp_sources += serial_sources |
| 54 | libmctp_headers += serial_headers |
| 55 | endif |
| 56 | if get_option('bindings').contains('astlpc') |
| 57 | libmctp_sources += astlpc_sources |
| 58 | libmctp_headers += astlpc_headers |
| 59 | endif |
Matt Johnston | e5b941d | 2024-09-17 16:44:38 +0800 | [diff] [blame] | 60 | if get_option('bindings').contains('i2c') |
| 61 | libmctp_sources += i2c_sources |
| 62 | libmctp_headers += i2c_headers |
| 63 | endif |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 64 | |
| 65 | compiler = meson.get_compiler('c') |
| 66 | |
Matt Johnston | bbfcc6e | 2024-09-17 16:48:15 +0800 | [diff] [blame] | 67 | if not get_option('custom_alloc') and get_option('default_alloc').require( |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 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') |
| 76 | endif |
| 77 | |
Matt Johnston | bbfcc6e | 2024-09-17 16:48:15 +0800 | [diff] [blame] | 78 | if get_option('custom_alloc') |
| 79 | add_project_arguments('-DMCTP_CUSTOM_ALLOC', language : 'c') |
| 80 | endif |
| 81 | |
Matt Johnston | 1250727 | 2024-10-01 12:17:19 +0800 | [diff] [blame] | 82 | if get_option('nolog') |
| 83 | add_project_arguments('-DMCTP_NOLOG', language : 'c') |
| 84 | else |
| 85 | libmctp_sources += ['log.c'] |
| 86 | endif |
| 87 | |
Matt Johnston | 63338a2 | 2024-09-11 09:53:59 +0800 | [diff] [blame] | 88 | feat_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 | ''')) |
| 97 | if feat_fileio.allowed() |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 98 | add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c') |
| 99 | endif |
| 100 | |
| 101 | if 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') |
| 118 | endif |
| 119 | |
| 120 | if 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') |
| 137 | endif |
| 138 | |
| 139 | # pcap is necessary for mctp-demux-daemon to be functional |
| 140 | pcap_dep = dependency('libpcap', required: false) |
| 141 | |
| 142 | systemd_dep = dependency('systemd', required: false) |
| 143 | libsystemd_dep = dependency('libsystemd', required: false) |
| 144 | |
| 145 | libmctp_include_dir = include_directories('.', is_system: true) |
| 146 | libmctp = library('mctp', |
| 147 | libmctp_sources, |
| 148 | include_directories: libmctp_include_dir, |
| 149 | version: meson.project_version(), |
| 150 | install: true, |
| 151 | ) |
| 152 | install_headers(libmctp_headers) |
| 153 | |
| 154 | if 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) |
| 158 | endif |
| 159 | |
| 160 | import('pkgconfig').generate(libmctp, |
| 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. |
Matt Johnston | f9b99f1 | 2024-09-17 16:48:34 +0800 | [diff] [blame] | 173 | sizeof_mctp = compiler.sizeof('struct mctp', |
| 174 | include_directories: libmctp_include_dir, |
| 175 | prefix: '#include "core-internal.h"') |
Matt Johnston | e5b941d | 2024-09-17 16:44:38 +0800 | [diff] [blame] | 176 | sizeof_binding_i2c = compiler.sizeof('struct mctp_binding_i2c', |
| 177 | include_directories: libmctp_include_dir, |
| 178 | prefix: '#include "i2c-internal.h"') |
Matt Johnston | f9b99f1 | 2024-09-17 16:48:34 +0800 | [diff] [blame] | 179 | sizes_h = configure_file(configuration: { |
| 180 | 'sizeof_struct_mctp': sizeof_mctp, |
Matt Johnston | e5b941d | 2024-09-17 16:44:38 +0800 | [diff] [blame] | 181 | 'sizeof_binding_i2c': sizeof_binding_i2c, |
Matt Johnston | f9b99f1 | 2024-09-17 16:48:34 +0800 | [diff] [blame] | 182 | }, |
| 183 | input: 'libmctp-sizes.h.in', |
| 184 | output: 'libmctp-sizes.h', |
| 185 | ) |
| 186 | install_headers(sizes_h) |
| 187 | |
Matt Johnston | 63338a2 | 2024-09-11 09:53:59 +0800 | [diff] [blame] | 188 | if feat_fileio.allowed() |
| 189 | subdir('utils') |
| 190 | endif |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 191 | |
| 192 | if get_option('tests').allowed() |
| 193 | subdir('tests') |
| 194 | endif |