| 1 |
# librist. Copyright (c) 2019 SipRadius LLC. All right reserved. |
| 2 |
# Author: Kuldeep Singh Dhaka <[email protected]> |
| 3 |
# Author: Sergio Ammirata, Ph.D. <[email protected]> |
| 4 |
# SPDX-License-Identifier: BSD-2-Clause |
| 5 |
|
| 6 |
project('libRIST', 'c', |
| 7 |
version: '0.2.18', |
| 8 |
default_options: ['c_std=c99', 'warning_level=3', 'libdir=lib'], |
| 9 |
meson_version: '>= 0.51.0') |
| 10 |
|
| 11 |
cc = meson.get_compiler('c') |
| 12 |
# Configuration data for config.h |
| 13 |
cdata = configuration_data() |
| 14 |
|
| 15 |
#librist ABI version, libtool rules (taken from https://github.com/pvanhoof/dir-examples) |
| 16 |
#If the library source code has changed at all since the last update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’). |
| 17 |
#If any interfaces have been added, removed, or changed since the last update, increment current, and set revision to 0. |
| 18 |
#If any interfaces have been added since the last public release, then increment age. |
| 19 |
#If any interfaces have been removed or changed since the last public release, then set age to 0. |
| 20 |
librist_abi_current = 15 |
| 21 |
librist_abi_revision = 0 |
| 22 |
librist_abi_age = 11 |
| 23 |
librist_soversion = librist_abi_current - librist_abi_age |
| 24 |
librist_version = '@0@.@1@.@2@'.format(librist_abi_current - librist_abi_age, librist_abi_age, librist_abi_revision) |
| 25 |
|
| 26 |
# libRIST version |
| 27 |
#API follows semver rules: |
| 28 |
#MAJOR version when you make incompatible API changes, |
| 29 |
#MINOR version when you add functionality in a backwards-compatible manner, and |
| 30 |
#PATCH not used (doesn't make sense for API version, remains here for backwards compat) |
| 31 |
|
| 32 |
librist_api_version_major = 4 |
| 33 |
librist_api_version_minor = 12 |
| 34 |
librist_api_version_patch = 0 |
| 35 |
|
| 36 |
librist_src_root = meson.current_source_dir() |
| 37 |
|
| 38 |
deps = [] |
| 39 |
platform_files = [] |
| 40 |
inc = [] |
| 41 |
inc += include_directories('.', 'src', 'include/librist', 'include', 'contrib') |
| 42 |
|
| 43 |
builtin_lz4 = get_option('builtin_lz4') |
| 44 |
builtin_cjson = get_option('builtin_cjson') |
| 45 |
builtin_mbedtls = get_option('builtin_mbedtls') |
| 46 |
|
| 47 |
if (host_machine.system() == 'darwin' |
| 48 |
and not meson.is_cross_build() |
| 49 |
and find_program('brew', required : false).found() |
| 50 |
and (not builtin_cjson or not builtin_mbedtls)) |
| 51 |
r = run_command('brew', '--prefix', check: true) |
| 52 |
brewoutput = r.stdout().strip() |
| 53 |
inc += include_directories(brewoutput + '/include') |
| 54 |
endif |
| 55 |
use_mbedtls = get_option('use_mbedtls') |
| 56 |
use_nettle = get_option('use_nettle') |
| 57 |
use_gnutls = get_option('use_gnutls') |
| 58 |
|
| 59 |
if not use_gnutls |
| 60 |
if use_nettle |
| 61 |
warning('use_nettle is deprecated, use use_gnutls') |
| 62 |
endif |
| 63 |
use_gnutls = use_nettle |
| 64 |
endif |
| 65 |
|
| 66 |
cdata.set10('ALLOW_INSECURE_IV_FALLBACK', get_option('allow_insecure_iv_fallback')) |
| 67 |
|
| 68 |
required_library = false |
| 69 |
if not get_option('fallback_builtin') |
| 70 |
required_library = true |
| 71 |
endif |
| 72 |
|
| 73 |
should_install = true |
| 74 |
if meson.is_subproject() |
| 75 |
should_install = false |
| 76 |
endif |
| 77 |
|
| 78 |
have_pthreads = cc.has_header('pthread.h') |
| 79 |
have_clock_gettime = false |
| 80 |
|
| 81 |
threads = [] |
| 82 |
test_args = [] |
| 83 |
if host_machine.system() == 'windows' |
| 84 |
platform_files += 'src/tun_win.c' |
| 85 |
deps += [ |
| 86 |
cc.find_library('ws2_32'), |
| 87 |
cc.find_library('iphlpapi'), |
| 88 |
cc.find_library('bcrypt') |
| 89 |
] |
| 90 |
|
| 91 |
windows_version_test = ''' |
| 92 |
#include <windef.h> |
| 93 |
#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600 |
| 94 |
# error _WIN32_WINNT toolchain default not high enough |
| 95 |
#endif |
| 96 |
''' |
| 97 |
if not cc.compiles(windows_version_test, name: '_WIN32_WINNT includes Vista') |
| 98 |
add_project_arguments(['-D_WIN32_WINNT=0x0600'], language: 'c') |
| 99 |
endif |
| 100 |
|
| 101 |
if get_option('default_library') != 'static' |
| 102 |
add_project_arguments(['-DLIBRIST_BUILDING_DLL'], language: 'c') |
| 103 |
endif |
| 104 |
if get_option('have_mingw_pthreads') |
| 105 |
if have_pthreads |
| 106 |
threads = dependency('threads') |
| 107 |
deps += threads |
| 108 |
cdata.set('HAVE_PTHREADS', 1) |
| 109 |
endif |
| 110 |
else |
| 111 |
have_pthreads = false |
| 112 |
endif |
| 113 |
# Use has_header_symbol so mingw-w64's static inline clock_gettime |
| 114 |
# (in <time.h>, regardless of winpthreads) is detected. |
| 115 |
# Must stay outside the have_mingw_pthreads block: modern mingw-w64 |
| 116 |
# ships the inline unconditionally and contrib/time-shim.c must |
| 117 |
# not redefine it. |
| 118 |
have_clock_gettime = cc.has_header_symbol('time.h', 'clock_gettime', args : test_args) |
| 119 |
if cc.get_id() == 'msvc' |
| 120 |
# librist uses C11 features (stdatomic.h, mixed declarations). |
| 121 |
# MSVC only exposes them under /std:c11 or /std:c17. |
| 122 |
if cc.has_argument('/std:c11') |
| 123 |
add_project_arguments(['/std:c11'], language: 'c') |
| 124 |
elif cc.has_argument('/std:c17') |
| 125 |
add_project_arguments(['/std:c17'], language: 'c') |
| 126 |
endif |
| 127 |
endif |
| 128 |
add_project_arguments(['-DWIN32_LEAN_AND_MEAN'], language: 'c') |
| 129 |
add_project_arguments(['-D__USE_MINGW_ANSI_STDIO=1'], language: 'c') |
| 130 |
add_project_arguments(['-D_CRT_NONSTDC_NO_DEPRECATE'], language: 'c') |
| 131 |
add_project_arguments(['-D_CRT_SECURE_NO_WARNINGS'], language: 'c') |
| 132 |
add_project_arguments(cc.get_supported_arguments(['-wd4996', '-wd4324']), language: 'c') |
| 133 |
#Windows meson tends to break on pkgconfig/Cmake finding, so use builtin libraries |
| 134 |
librist_soversion = '' |
| 135 |
else |
| 136 |
if host_machine.system() == 'linux' or host_machine.system() == 'android' |
| 137 |
platform_files += 'src/tun_linux.c' |
| 138 |
test_args += '-D_GNU_SOURCE' |
| 139 |
add_project_arguments('-D_GNU_SOURCE', language: 'c') |
| 140 |
if cc.check_header('linux/if_alg.h') |
| 141 |
add_project_arguments(['-DLINUX_CRYPTO'], language: 'c') |
| 142 |
platform_files += 'contrib/linux-crypto.c' |
| 143 |
endif |
| 144 |
checkgetif = ''' |
| 145 |
#include <ifaddrs.h> |
| 146 |
|
| 147 |
void test(void) { |
| 148 |
struct ifaddrs *ifaddr = NULL; |
| 149 |
getifaddrs(&ifaddr); |
| 150 |
} |
| 151 |
''' |
| 152 |
hasgetifaddrs = cc.compiles(checkgetif) |
| 153 |
if not hasgetifaddrs and host_machine.system() == 'android' |
| 154 |
platform_files += 'compat/android/ifaddrs.c' |
| 155 |
inc += include_directories('compat/android') |
| 156 |
endif |
| 157 |
elif host_machine.system() == 'darwin' |
| 158 |
platform_files += 'src/tun_darwin.c' |
| 159 |
test_args += '-D_DARWIN_C_SOURCE' |
| 160 |
add_project_arguments('-D_DARWIN_C_SOURCE', language: 'c') |
| 161 |
elif host_machine.system() == 'gnu' |
| 162 |
test_args += '-D_GNU_SOURCE' |
| 163 |
add_project_arguments('-D_GNU_SOURCE', language: 'c') |
| 164 |
elif host_machine.system() == 'emscripten' |
| 165 |
platform_files += 'src/tun_emscripten.c' |
| 166 |
add_project_arguments('-D_GNU_SOURCE', language: 'c') |
| 167 |
endif |
| 168 |
librist_soversion = librist_soversion |
| 169 |
if host_machine.system() == 'emscripten' |
| 170 |
have_clock_gettime = true |
| 171 |
else |
| 172 |
have_clock_gettime = cc.has_function('clock_gettime', prefix : '#include <time.h>', args : test_args) |
| 173 |
if not have_clock_gettime and host_machine.system() != 'darwin' |
| 174 |
lib_rt = cc.find_library('rt', required: false) |
| 175 |
have_clock_gettime = cc.has_function('clock_gettime', prefix : '#include <time.h>', args : test_args, dependencies : lib_rt) |
| 176 |
if not have_clock_gettime |
| 177 |
error('clock_gettime not found') |
| 178 |
endif |
| 179 |
deps += [ lib_rt ] |
| 180 |
endif |
| 181 |
endif |
| 182 |
add_project_arguments(['-Wshadow', '-pedantic-errors'], language: 'c') |
| 183 |
add_project_arguments(cc.get_supported_arguments([ |
| 184 |
'-Wundef', |
| 185 |
'-Werror=vla', |
| 186 |
'-Wno-maybe-uninitialized', |
| 187 |
'-Wno-missing-field-initializers', |
| 188 |
'-Wno-unused-parameter', |
| 189 |
'-Wshorten-64-to-32', |
| 190 |
'-Wunused-parameter', |
| 191 |
'-Wmaybe-uninitialized', |
| 192 |
'-Wno-error=deprecated-declarations' |
| 193 |
]), language : 'c') |
| 194 |
if host_machine.system() != 'emscripten' |
| 195 |
threads = [ dependency('threads') ] |
| 196 |
endif |
| 197 |
if host_machine.system() != 'freebsd' and host_machine.system() != 'emscripten' |
| 198 |
add_project_arguments(cc.get_supported_arguments([ |
| 199 |
'-Watomic-implicit-seq-cst']), language: 'c') |
| 200 |
endif |
| 201 |
deps += threads |
| 202 |
endif |
| 203 |
|
| 204 |
cdata.set10('HAVE_CLOCK_GETTIME', have_clock_gettime) |
| 205 |
cdata.set10('HAVE_PTHREADS', have_pthreads) |
| 206 |
|
| 207 |
sock_un_h = cc.has_header('sys/un.h') |
| 208 |
cdata.set10('HAVE_SOCK_UN_H', sock_un_h) |
| 209 |
microhttpd = dependency('libmicrohttpd', required: false) |
| 210 |
cdata.set10('HAVE_LIBMICROHTTPD', microhttpd.found()) |
| 211 |
if microhttpd.found() |
| 212 |
code = ''' |
| 213 |
#include <microhttpd.h> |
| 214 |
static enum MHD_Result test(void) { |
| 215 |
return MHD_NO; |
| 216 |
}''' |
| 217 |
cdata.set10('MICROHTTPD_HAS_RESULT_ENUM',cc.compiles(code, dependencies: [microhttpd], name: 'libmicrohttpd has MHD_Result enum')) |
| 218 |
code = ''' |
| 219 |
#include <microhttpd.h> |
| 220 |
static void test(void) { |
| 221 |
MHD_start_daemon(MHD_USE_AUTO_INTERNAL_THREAD, 0, NULL, NULL, NULL, NULL, MHD_OPTION_END); |
| 222 |
}''' |
| 223 |
cdata.set10('MICROHTTPD_HAS_AUTO_INTERNAL_THREAD',cc.compiles(code, dependencies: [microhttpd], name: 'libmicrohttpd has MHD_USE_AUTO_INTERNAL_THREAD flag')) |
| 224 |
endif |
| 225 |
compile_prometheus = sock_un_h or microhttpd.found() |
| 226 |
cdata.set10('HAVE_PROMETHEUS_SUPPORT', compile_prometheus) |
| 227 |
|
| 228 |
if cc.has_argument('-fvisibility=hidden') |
| 229 |
add_project_arguments('-fvisibility=hidden', language: 'c') |
| 230 |
else |
| 231 |
warning('Compiler does not support -fvisibility=hidden, all symbols will be public!') |
| 232 |
endif |
| 233 |
|
| 234 |
# Header checks |
| 235 |
stdatomic_dependency = [] |
| 236 |
if not cc.check_header('stdatomic.h') |
| 237 |
if cc.get_id() == 'msvc' |
| 238 |
# we have a custom replacement for MSVC |
| 239 |
stdatomic_dependency = declare_dependency( |
| 240 |
include_directories : include_directories('compat/msvc'), |
| 241 |
) |
| 242 |
elif cc.compiles('''int main() { int v = 0; return __atomic_fetch_add(&v, 1, __ATOMIC_SEQ_CST); }''', |
| 243 |
name : 'GCC-style atomics', args : test_args) |
| 244 |
stdatomic_dependency = declare_dependency( |
| 245 |
include_directories : include_directories('compat/gcc'), |
| 246 |
) |
| 247 |
else |
| 248 |
error('Atomics not supported') |
| 249 |
endif |
| 250 |
endif |
| 251 |
|
| 252 |
#On ubuntu cjson does not come with pkgconfig files, hence the extended checking. |
| 253 |
if not builtin_cjson |
| 254 |
cjson_lib = dependency('libcjson', required: false) |
| 255 |
if not cjson_lib.found() |
| 256 |
cjson_lib = cc.find_library('cjson', required: required_library, has_headers: ['cjson/cJSON.h']) |
| 257 |
if not cjson_lib.found() |
| 258 |
builtin_cjson = true |
| 259 |
endif |
| 260 |
endif |
| 261 |
endif |
| 262 |
if builtin_cjson |
| 263 |
message('Using builtin cJSON library') |
| 264 |
cjson_lib = declare_dependency( compile_args : '-DCJSON_HIDE_SYMBOLS', |
| 265 |
sources: 'contrib/contrib_cJSON/cjson/cJSON.c', |
| 266 |
include_directories : include_directories('contrib/contrib_cJSON')) |
| 267 |
endif |
| 268 |
|
| 269 |
if not builtin_lz4 |
| 270 |
lz4_lib = dependency('liblz4', required: false) |
| 271 |
if not lz4_lib.found() |
| 272 |
lz4_lib = cc.find_library('lz4', required: required_library, has_headers: ['lz4.h']) |
| 273 |
if not lz4_lib.found() |
| 274 |
builtin_lz4 = true |
| 275 |
endif |
| 276 |
endif |
| 277 |
endif |
| 278 |
if builtin_lz4 |
| 279 |
message('Using builtin LZ4 library') |
| 280 |
lz4_lib = declare_dependency( |
| 281 |
sources: 'contrib/lz4/lz4.c', |
| 282 |
include_directories : include_directories('contrib/lz4')) |
| 283 |
endif |
| 284 |
|
| 285 |
crypto_deps = [] |
| 286 |
|
| 287 |
mbedcrypto_lib_found = false |
| 288 |
if use_mbedtls |
| 289 |
message('Building mbedtls') |
| 290 |
subdir('contrib/mbedtls') |
| 291 |
|
| 292 |
crypto_deps += mbedcrypto_lib |
| 293 |
elif use_gnutls |
| 294 |
crypto_deps = [dependency('nettle'), dependency('hogweed')] |
| 295 |
test_mini_gmp = ''' |
| 296 |
#include <nettle/bignum.h> |
| 297 |
#if !NETTLE_USE_MINI_GMP |
| 298 |
#error "Need to link gmp" |
| 299 |
#endif |
| 300 |
''' |
| 301 |
if not cc.compiles(test_mini_gmp, name: 'Nettle with mini-gmp?', dependencies: crypto_deps) |
| 302 |
crypto_deps += dependency('gmp') |
| 303 |
endif |
| 304 |
crypto_deps += dependency('gnutls')#Just for random numbers at the moment :/ |
| 305 |
endif |
| 306 |
deps += crypto_deps |
| 307 |
|
| 308 |
subdir('include') |
| 309 |
|
| 310 |
filter_obj = false |
| 311 |
objcopy = find_program('objcopy', native: true, required: false) |
| 312 |
|
| 313 |
if get_option('allow_obj_filter') and cc.get_id() == 'clang' |
| 314 |
error('allow_obj_filter doesn\'t work with clang due to it not supporting pre-linking') |
| 315 |
endif |
| 316 |
|
| 317 |
if get_option('allow_obj_filter') and get_option('default_library') != 'shared' and not get_option('b_lto') |
| 318 |
if objcopy.found() |
| 319 |
message('Using objcopy to localize symbols in static library') |
| 320 |
filter_obj = true |
| 321 |
else |
| 322 |
error('objcopy not found, unable to localize symbols in static library') |
| 323 |
endif |
| 324 |
endif |
| 325 |
|
| 326 |
if not mbedcrypto_lib_found and not use_gnutls |
| 327 |
platform_files += [ |
| 328 |
'contrib/aes.c', |
| 329 |
'contrib/sha256.c', |
| 330 |
'contrib/fastpbkdf2.c', |
| 331 |
] |
| 332 |
endif |
| 333 |
|
| 334 |
have_srp = mbedcrypto_lib_found or use_gnutls |
| 335 |
|
| 336 |
platform_files += 'src/crypto/random.c' |
| 337 |
|
| 338 |
if have_srp |
| 339 |
platform_files += 'src/proto/eap.c' |
| 340 |
platform_files += 'src/crypto/srp_constants.c' |
| 341 |
platform_files += 'src/crypto/srp.c' |
| 342 |
endif |
| 343 |
|
| 344 |
cdata.set10('HAVE_MBEDTLS', mbedcrypto_lib_found) |
| 345 |
cdata.set10('HAVE_NETTLE', use_gnutls and not mbedcrypto_lib_found) |
| 346 |
# Generate config.h |
| 347 |
config_file = configure_file(output: 'config.h', configuration: cdata) |
| 348 |
|
| 349 |
librist = library('librist', |
| 350 |
'src/crypto/crypto.c', |
| 351 |
'src/crypto/psk.c', |
| 352 |
'src/proto/gre.c', |
| 353 |
'src/proto/rtp.c', |
| 354 |
'src/proto/rist_time.c', |
| 355 |
'src/flow.c', |
| 356 |
'src/logging.c', |
| 357 |
'src/network.c', |
| 358 |
'src/adv.c', |
| 359 |
'src/adv_ctrl.c', |
| 360 |
'src/rist.c', |
| 361 |
'src/rist-common.c', |
| 362 |
'src/rist_ref.c', |
| 363 |
'src/rist-thread.c', |
| 364 |
'src/mpegts.c', |
| 365 |
'src/peer.c', |
| 366 |
'src/udp.c', |
| 367 |
'src/transport.c', |
| 368 |
'src/stats.c', |
| 369 |
'src/udpsocket.c', |
| 370 |
'src/libevsocket.c', |
| 371 |
'contrib/stdio-shim.c', |
| 372 |
'contrib/time-shim.c', |
| 373 |
'contrib/pthread-shim.c', |
| 374 |
config_file, |
| 375 |
platform_files, |
| 376 |
rev_target, |
| 377 |
include_directories: inc, |
| 378 |
dependencies: [ |
| 379 |
deps, |
| 380 |
stdatomic_dependency, |
| 381 |
cjson_lib, |
| 382 |
lz4_lib, |
| 383 |
], |
| 384 |
name_prefix : '', |
| 385 |
version: librist_version, |
| 386 |
soversion: librist_soversion, |
| 387 |
prelink: filter_obj, |
| 388 |
install: should_install) |
| 389 |
|
| 390 |
objcopy_fake_file = '' |
| 391 |
if filter_obj |
| 392 |
lib_target = librist |
| 393 |
if get_option('default_library') == 'both' |
| 394 |
lib_target = librist.get_static_lib() |
| 395 |
endif |
| 396 |
objcopy_fake_file = custom_target('librist', |
| 397 |
input: lib_target, |
| 398 |
output: 'librist.is-stripped', |
| 399 |
capture: true, |
| 400 |
command: [ |
| 401 |
objcopy, |
| 402 |
'--localize-hidden', |
| 403 |
'-w', |
| 404 |
'--localize-symbol=!rist*', |
| 405 |
'--localize-symbol=!librist*', |
| 406 |
'--localize-symbol=!udpsocket*', |
| 407 |
'--localize-symbol=!evsocket*', |
| 408 |
'--localize-symbol=*', |
| 409 |
'@INPUT@', |
| 410 |
], |
| 411 |
build_by_default: true, |
| 412 |
) |
| 413 |
endif |
| 414 |
|
| 415 |
pkg_mod = import('pkgconfig') |
| 416 |
pkg_mod.generate( |
| 417 |
libraries: librist, |
| 418 |
version: meson.project_version(), |
| 419 |
name: 'librist', |
| 420 |
description: 'Reliable Internet Stream Transport (RIST)', |
| 421 |
) |
| 422 |
|
| 423 |
if get_option('static_analyze') |
| 424 |
run_target('cppcheck', command : ['cppcheck', |
| 425 |
'--quiet', |
| 426 |
'--std=c99', |
| 427 |
'--suppressions-list=' + join_paths(librist_src_root, 'common/configs/cppcheck-suppressions.txt'), |
| 428 |
'--project=' + join_paths(meson.build_root(), |
| 429 |
'compile_commands.json')]) |
| 430 |
run_target('analyze', command: ['bash', join_paths(librist_src_root, 'common/scripts/analyze.sh')]) |
| 431 |
endif |
| 432 |
|
| 433 |
librist_dep = declare_dependency(include_directories: inc, link_with : librist, dependencies : stdatomic_dependency) |
| 434 |
|
| 435 |
if get_option('built_tools') |
| 436 |
message('Building tools') |
| 437 |
subdir('tools') |
| 438 |
endif |
| 439 |
|
| 440 |
if get_option('test') |
| 441 |
subdir('test') |
| 442 |
endif |