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 | |
| 67 | if get_option('fileio').require( |
| 68 | compiler.check_header('unistd.h') and compiler.check_header('fcntl.h') |
| 69 | ).allowed() |
| 70 | add_project_arguments('-DMCTP_HAVE_FILEIO', language : 'c') |
| 71 | endif |
| 72 | |
| 73 | if get_option('syslog').require( |
| 74 | compiler.links(''' |
| 75 | #include <stdarg.h> |
| 76 | #include <syslog.h> |
| 77 | void check_vsyslog(int level, const char *fmt, ...) |
| 78 | { |
| 79 | va_list ap; |
| 80 | va_start(ap, fmt); |
| 81 | vsyslog(0, fmt, ap); |
| 82 | va_end(ap); |
| 83 | } |
| 84 | void main() |
| 85 | { |
| 86 | check_vsyslog(0, "\n"); |
| 87 | } |
| 88 | ''')).allowed() |
| 89 | add_project_arguments('-DMCTP_HAVE_SYSLOG', language : 'c') |
| 90 | endif |
| 91 | |
| 92 | if get_option('stdio').require( |
| 93 | compiler.links(''' |
| 94 | #include <stdarg.h> |
| 95 | #include <stdio.h> |
| 96 | void check_vsyslog(const char *fmt, ...) |
| 97 | { |
| 98 | va_list ap; |
| 99 | va_start(ap, fmt); |
| 100 | vprintf(fmt, ap); |
| 101 | va_end(ap); |
| 102 | } |
| 103 | void main() |
| 104 | { |
| 105 | check_vsyslog("\n"); |
| 106 | } |
| 107 | ''')).allowed() |
| 108 | add_project_arguments('-DMCTP_HAVE_STDIO', language : 'c') |
| 109 | endif |
| 110 | |
| 111 | # pcap is necessary for mctp-demux-daemon to be functional |
| 112 | pcap_dep = dependency('libpcap', required: false) |
| 113 | |
| 114 | systemd_dep = dependency('systemd', required: false) |
| 115 | libsystemd_dep = dependency('libsystemd', required: false) |
| 116 | |
| 117 | libmctp_include_dir = include_directories('.', is_system: true) |
| 118 | libmctp = library('mctp', |
| 119 | libmctp_sources, |
| 120 | include_directories: libmctp_include_dir, |
| 121 | version: meson.project_version(), |
| 122 | install: true, |
| 123 | ) |
| 124 | install_headers(libmctp_headers) |
| 125 | |
| 126 | if systemd_dep.found() |
| 127 | unitdir = systemd_dep.get_variable(pkgconfig: 'systemdsystemunitdir') |
| 128 | install_data('systemd/system/mctp-demux.service', install_dir: unitdir) |
| 129 | install_data('systemd/system/mctp-demux.socket', install_dir: unitdir) |
| 130 | endif |
| 131 | |
| 132 | import('pkgconfig').generate(libmctp, |
| 133 | name: 'libmctp', |
| 134 | description: 'MCTP protocol implementation', |
| 135 | version: meson.project_version(), |
| 136 | ) |
| 137 | |
| 138 | libmctp_dep = declare_dependency( |
| 139 | include_directories: libmctp_include_dir, |
| 140 | link_with: libmctp, |
| 141 | ) |
| 142 | |
| 143 | subdir('utils') |
| 144 | |
| 145 | if get_option('tests').allowed() |
| 146 | subdir('tests') |
| 147 | endif |