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 | |
| 41 | libmctp_sources = sources |
| 42 | libmctp_headers = headers |
| 43 | |
| 44 | if get_option('bindings').contains('serial') |
| 45 | libmctp_sources += serial_sources |
| 46 | libmctp_headers += serial_headers |
| 47 | endif |
| 48 | if get_option('bindings').contains('astlpc') |
| 49 | libmctp_sources += astlpc_sources |
| 50 | libmctp_headers += astlpc_headers |
| 51 | endif |
| 52 | |
| 53 | compiler = meson.get_compiler('c') |
| 54 | |
Matt Johnston | bbfcc6e | 2024-09-17 16:48:15 +0800 | [diff] [blame] | 55 | if not get_option('custom_alloc') and get_option('default_alloc').require( |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 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') |
| 64 | endif |
| 65 | |
Matt Johnston | bbfcc6e | 2024-09-17 16:48:15 +0800 | [diff] [blame] | 66 | if get_option('custom_alloc') |
| 67 | add_project_arguments('-DMCTP_CUSTOM_ALLOC', language : 'c') |
| 68 | endif |
| 69 | |
Matt Johnston | 1250727 | 2024-10-01 12:17:19 +0800 | [diff] [blame] | 70 | if get_option('nolog') |
| 71 | add_project_arguments('-DMCTP_NOLOG', language : 'c') |
| 72 | else |
| 73 | libmctp_sources += ['log.c'] |
| 74 | endif |
| 75 | |
Matt Johnston | 63338a2 | 2024-09-11 09:53:59 +0800 | [diff] [blame] | 76 | feat_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 | ''')) |
| 85 | if feat_fileio.allowed() |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 86 | add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c') |
| 87 | endif |
| 88 | |
| 89 | if 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') |
| 106 | endif |
| 107 | |
| 108 | if 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') |
| 125 | endif |
| 126 | |
| 127 | # pcap is necessary for mctp-demux-daemon to be functional |
| 128 | pcap_dep = dependency('libpcap', required: false) |
| 129 | |
| 130 | systemd_dep = dependency('systemd', required: false) |
| 131 | libsystemd_dep = dependency('libsystemd', required: false) |
| 132 | |
| 133 | libmctp_include_dir = include_directories('.', is_system: true) |
| 134 | libmctp = library('mctp', |
| 135 | libmctp_sources, |
| 136 | include_directories: libmctp_include_dir, |
| 137 | version: meson.project_version(), |
| 138 | install: true, |
| 139 | ) |
| 140 | install_headers(libmctp_headers) |
| 141 | |
| 142 | if 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) |
| 146 | endif |
| 147 | |
| 148 | import('pkgconfig').generate(libmctp, |
| 149 | name: 'libmctp', |
| 150 | description: 'MCTP protocol implementation', |
| 151 | version: meson.project_version(), |
| 152 | ) |
| 153 | |
| 154 | libmctp_dep = declare_dependency( |
| 155 | include_directories: libmctp_include_dir, |
| 156 | link_with: libmctp, |
| 157 | ) |
| 158 | |
Matt Johnston | f9b99f1 | 2024-09-17 16:48:34 +0800 | [diff] [blame] | 159 | sizeof_mctp = compiler.sizeof('struct mctp', |
| 160 | include_directories: libmctp_include_dir, |
| 161 | prefix: '#include "core-internal.h"') |
| 162 | sizes_h = configure_file(configuration: { |
| 163 | 'sizeof_struct_mctp': sizeof_mctp, |
| 164 | }, |
| 165 | input: 'libmctp-sizes.h.in', |
| 166 | output: 'libmctp-sizes.h', |
| 167 | ) |
| 168 | install_headers(sizes_h) |
| 169 | |
Matt Johnston | 63338a2 | 2024-09-11 09:53:59 +0800 | [diff] [blame] | 170 | if feat_fileio.allowed() |
| 171 | subdir('utils') |
| 172 | endif |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 173 | |
| 174 | if get_option('tests').allowed() |
| 175 | subdir('tests') |
| 176 | endif |