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', |
| 17 | 'log.c', |
| 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 | |
| 42 | libmctp_sources = sources |
| 43 | libmctp_headers = headers |
| 44 | |
| 45 | if get_option('bindings').contains('serial') |
| 46 | libmctp_sources += serial_sources |
| 47 | libmctp_headers += serial_headers |
| 48 | endif |
| 49 | if get_option('bindings').contains('astlpc') |
| 50 | libmctp_sources += astlpc_sources |
| 51 | libmctp_headers += astlpc_headers |
| 52 | endif |
| 53 | |
| 54 | compiler = meson.get_compiler('c') |
| 55 | |
| 56 | if get_option('default_alloc').require( |
| 57 | compiler.links(''' |
| 58 | #include <stdlib.h> |
| 59 | void main() |
| 60 | { |
| 61 | free(malloc(4096)); |
| 62 | } |
| 63 | ''')).allowed() |
| 64 | add_project_arguments('-DMCTP_DEFAULT_ALLOC', language : 'c') |
| 65 | endif |
| 66 | |
Matt Johnston | 63338a2 | 2024-09-11 09:53:59 +0800 | [diff] [blame] | 67 | feat_fileio = get_option('fileio').require( |
| 68 | compiler.links(''' |
| 69 | #include <poll.h> |
| 70 | #include <unistd.h> |
| 71 | void main() |
| 72 | { |
| 73 | poll(NULL, 0, -1); |
| 74 | } |
| 75 | ''')) |
| 76 | if feat_fileio.allowed() |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 77 | add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c') |
| 78 | endif |
| 79 | |
| 80 | if get_option('syslog').require( |
| 81 | compiler.links(''' |
| 82 | #include <stdarg.h> |
| 83 | #include <syslog.h> |
| 84 | void check_vsyslog(int level, const char *fmt, ...) |
| 85 | { |
| 86 | va_list ap; |
| 87 | va_start(ap, fmt); |
| 88 | vsyslog(0, fmt, ap); |
| 89 | va_end(ap); |
| 90 | } |
| 91 | void main() |
| 92 | { |
| 93 | check_vsyslog(0, "\n"); |
| 94 | } |
| 95 | ''')).allowed() |
| 96 | add_project_arguments('-DMCTP_HAVE_SYSLOG', language : 'c') |
| 97 | endif |
| 98 | |
| 99 | if get_option('stdio').require( |
| 100 | compiler.links(''' |
| 101 | #include <stdarg.h> |
| 102 | #include <stdio.h> |
| 103 | void check_vsyslog(const char *fmt, ...) |
| 104 | { |
| 105 | va_list ap; |
| 106 | va_start(ap, fmt); |
| 107 | vprintf(fmt, ap); |
| 108 | va_end(ap); |
| 109 | } |
| 110 | void main() |
| 111 | { |
| 112 | check_vsyslog("\n"); |
| 113 | } |
| 114 | ''')).allowed() |
| 115 | add_project_arguments('-DMCTP_HAVE_STDIO', language : 'c') |
| 116 | endif |
| 117 | |
| 118 | # pcap is necessary for mctp-demux-daemon to be functional |
| 119 | pcap_dep = dependency('libpcap', required: false) |
| 120 | |
| 121 | systemd_dep = dependency('systemd', required: false) |
| 122 | libsystemd_dep = dependency('libsystemd', required: false) |
| 123 | |
| 124 | libmctp_include_dir = include_directories('.', is_system: true) |
| 125 | libmctp = library('mctp', |
| 126 | libmctp_sources, |
| 127 | include_directories: libmctp_include_dir, |
| 128 | version: meson.project_version(), |
| 129 | install: true, |
| 130 | ) |
| 131 | install_headers(libmctp_headers) |
| 132 | |
| 133 | if systemd_dep.found() |
| 134 | unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir') |
| 135 | install_data('systemd/system/mctp-demux.service', install_dir: unitdir) |
| 136 | install_data('systemd/system/mctp-demux.socket', install_dir: unitdir) |
| 137 | endif |
| 138 | |
| 139 | import('pkgconfig').generate(libmctp, |
| 140 | name: 'libmctp', |
| 141 | description: 'MCTP protocol implementation', |
| 142 | version: meson.project_version(), |
| 143 | ) |
| 144 | |
| 145 | libmctp_dep = declare_dependency( |
| 146 | include_directories: libmctp_include_dir, |
| 147 | link_with: libmctp, |
| 148 | ) |
| 149 | |
Matt Johnston | 63338a2 | 2024-09-11 09:53:59 +0800 | [diff] [blame] | 150 | if feat_fileio.allowed() |
| 151 | subdir('utils') |
| 152 | endif |
Matt Johnston | 6586fc1 | 2024-09-10 16:01:27 +0800 | [diff] [blame] | 153 | |
| 154 | if get_option('tests').allowed() |
| 155 | subdir('tests') |
| 156 | endif |