1# Project definition 2project('usrsctplib', 'c', 3 version: '1.0.0', 4 default_options: ['c_std=c99'], 5 meson_version: '>=0.49.0') 6 7# Set compiler warning flags 8compiler = meson.get_compiler('c') 9if compiler.get_argument_syntax() == 'msvc' 10 compiler_args = compiler.get_supported_arguments([ 11 '/wd4100', # 'identifier' : unreferenced formal parameter 12 '/wd4127', # conditional expression is constant 13 '/wd4200', # nonstandard extension used : zero-sized array in struct/union 14 '/wd4214', # bit field types other than int 15 '/wd4706', # assignment within conditional expression 16 '/wd4245', # 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch 17 '/wd4389', # 'operator' : signed/unsigned mismatch 18 '/wd4702', # unreachable code 19 '/wd4701', # Potentially uninitialized local variable 'name' used 20 '/wd4244', # 'conversion' conversion from 'type1' to 'type2', possible loss of data 21 ]) 22else 23 compiler_args = compiler.get_supported_arguments([ 24 '-pedantic', 25 '-Wall', 26 '-Wextra', 27 '-Wfloat-equal', 28 '-Wshadow', 29 '-Wpointer-arith', 30 '-Winit-self', 31 '-Wno-unused-function', 32 '-Wno-unused-parameter', 33 '-Wno-unreachable-code', 34 '-Wstrict-prototypes', 35 ]) 36endif 37add_project_arguments(compiler_args, language: 'c') 38 39# Configuration 40compile_args = [] 41 42# Dependency: Threads 43thread_dep = dependency('threads', required: true) 44 45# Dependencies list 46dependencies = [ 47 thread_dep, 48] 49 50# Global settings 51add_project_arguments([ 52 '-D__Userspace__', 53 '-DSCTP_SIMPLE_ALLOCATOR', 54 '-DSCTP_PROCESS_LEVEL_LOCKS', 55], language: 'c') 56 57# OS-specific settings 58system = host_machine.system() 59if system in ['linux', 'android'] 60 add_project_arguments([ 61 '-D__Userspace_os_Linux', 62 '-D_GNU_SOURCE', 63 ], language: 'c') 64elif system == 'freebsd' 65 add_project_arguments([ 66 '-D__Userspace_os_FreeBSD', 67 '-U__FreeBSD__', 68 ] + compiler.get_supported_arguments([ 69 '-Wno-address-of-packed-member', 70 ]), language: 'c') 71elif system in ['darwin', 'ios'] 72 add_project_arguments([ 73 '-D__Userspace_os_Darwin', 74 '-D__APPLE_USE_RFC_2292', 75 ] + compiler.get_supported_arguments([ 76 '-Wno-address-of-packed-member', 77 '-Wno-deprecated-declarations', 78 ]), language: 'c') 79elif system == 'dragonfly' 80 add_project_arguments([ 81 '-D__Userspace_os_DragonFly', 82 '-U__DragonFly__', 83 ], language: 'c') 84elif system == 'netbsd' 85 add_project_arguments([ 86 '-D__Userspace_os_NetBSD', 87 '-U__NetBSD__', 88 ], language: 'c') 89elif system == 'openbsd' 90 add_project_arguments([ 91 '-D__Userspace_os_OpenBSD', 92 '-U__OpenBSD__', 93 ], language: 'c') 94elif system == 'windows' 95 add_project_arguments('-D__Userspace_os_Windows', language: 'c') 96 dependencies += compiler.find_library('ws2_32', required: true) 97 dependencies += compiler.find_library('iphlpapi', required: true) 98 if compiler.get_id() == 'gcc' 99 add_project_arguments(compiler.get_supported_arguments([ 100 '-Wno-format', 101 '-D_WIN32_WINNT=0x601', # Enables inet_ntop and friends 102 ]), language: 'c') 103 endif 104else 105 error('Unknown system: @0@'.format(system)) 106endif 107 108# Feature: sys/queue 109if compiler.has_header('sys/queue.h') 110 add_project_arguments('-DHAVE_SYS_QUEUE_H', language: 'c') 111endif 112 113# Feature: sys/socket, linux/ifaddr, linux/rtnetlink 114if compiler.has_header('sys/socket.h') 115 if compiler.has_header('linux/if_addr.h') 116 add_project_arguments('-DHAVE_LINUX_IF_ADDR_H', language: 'c') 117 endif 118 119 if compiler.has_header('linux/rtnetlink.h') 120 add_project_arguments('-DHAVE_LINUX_RTNETLINK_H', language: 'c') 121 endif 122endif 123 124# Feature: ICMP 125have_sys_types = compiler.has_header('sys/types.h') 126have_netinet_in = compiler.has_header('netinet/in.h') 127have_netinet_ip = compiler.has_header('netinet/ip.h') 128have_netinet_ip_icmp = compiler.has_header('netinet/ip_icmp.h') 129if have_sys_types and have_netinet_in and have_netinet_ip and have_netinet_ip_icmp 130 add_project_arguments('-DHAVE_NETINET_IP_ICMP_H', language: 'c') 131endif 132 133# Feature: stdatomic 134if compiler.has_header('stdatomic.h') 135 add_project_arguments('-DHAVE_STDATOMIC_H', language: 'c') 136endif 137 138# Feature: sockaddr.sa_len 139prefix = ''' 140#include <sys/types.h> 141#include <sys/socket.h> 142''' 143have_sa_len = compiler.has_member('struct sockaddr', 'sa_len', prefix: prefix) 144if have_sa_len 145 add_project_arguments('-DHAVE_SA_LEN', language: 'c') 146endif 147 148# Feature: sockaddr_in.sin_len / sockaddr_in6.sin6_len / sockaddr_conn.sconn_len 149prefix = ''' 150#include <sys/types.h> 151#include <netinet/in.h> 152''' 153have_sin_len = compiler.has_member('struct sockaddr_in', 'sin_len', prefix: prefix) 154if have_sin_len 155 add_project_arguments('-DHAVE_SIN_LEN', language: 'c') 156endif 157have_sin6_len = compiler.has_member('struct sockaddr_in6', 'sin6_len', prefix: prefix) 158if have_sin6_len 159 add_project_arguments('-DHAVE_SIN6_LEN', language: 'c') 160endif 161have_sconn_len = compiler.has_member('struct sockaddr_conn', 'sconn_len', prefix: '#include "usrsctp.h"', include_directories: include_directories('usrsctplib')) 162if have_sconn_len 163 add_project_arguments('-DHAVE_SCONN_LEN', language: 'c') 164endif 165 166# Options 167if get_option('sctp_invariants') 168 add_project_arguments('-DINVARIANTS', language: 'c') 169endif 170if get_option('sctp_debug') 171 add_project_arguments('-DSCTP_DEBUG', language: 'c') 172 compile_args += '-DSCTP_DEBUG' 173endif 174if get_option('sctp_inet') 175 add_project_arguments('-DINET', language: 'c') 176endif 177if get_option('sctp_inet6') 178 add_project_arguments('-DINET6', language: 'c') 179endif 180 181# Library 182subdir('usrsctplib') 183 184# Build library 185if compiler.get_id() == 'msvc' and get_option('default_library') == 'shared' 186 # Needed by usrsctp_def 187 find_program('dumpbin') 188 189 usrsctp_static = static_library('usrsctp-static', sources, 190 dependencies: dependencies, 191 include_directories: include_dirs) 192 193 usrsctp_def = custom_target('usrsctp.def', 194 command: [find_program('gen-def.py'), '@INPUT@'], 195 input: usrsctp_static, 196 output: 'usrsctp.def', 197 capture: true) 198 199 usrsctp = shared_library('usrsctp', 200 link_whole: usrsctp_static, 201 dependencies: dependencies, 202 vs_module_defs: usrsctp_def, 203 install: true, 204 version: meson.project_version()) 205else 206 usrsctp = library('usrsctp', sources, 207 dependencies: dependencies, 208 include_directories: include_dirs, 209 install: true, 210 version: meson.project_version(), 211 c_args: '-U__APPLE__') 212endif 213 214# Declare dependency 215usrsctp_dep = declare_dependency( 216 compile_args: compile_args, 217 include_directories: include_dirs, 218 link_with: usrsctp) 219 220# Generate pkg-config file 221pkg = import('pkgconfig') 222pkg.generate(usrsctp, 223 name: 'usrsctp', 224 description: 'A portable SCTP userland stack', 225 url: 'https://github.com/sctplab/usrsctp', 226 extra_cflags: compile_args) 227 228# Programs (optional) 229if get_option('sctp_build_programs') 230 subdir('programs') 231 232 # Build executables 233 foreach name, sources : programs 234 executable( 235 name, 236 programs_helper_sources + sources, 237 dependencies: dependencies, 238 link_with: usrsctp, 239 include_directories: include_dirs) 240 endforeach 241endif 242