Lennart Grahl | 70f675c | 2019-07-05 22:05:26 +0200 | [diff] [blame] | 1 | # Project definition |
| 2 | project('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 |
| 8 | compiler = meson.get_compiler('c') |
| 9 | if 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 | ]) |
| 22 | else |
| 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 | ]) |
| 36 | endif |
| 37 | add_project_arguments(compiler_args, language: 'c') |
| 38 | |
| 39 | # Configuration |
| 40 | compile_args = [] |
| 41 | |
| 42 | # Dependency: Threads |
| 43 | thread_dep = dependency('threads', required: true) |
| 44 | |
| 45 | # Dependencies list |
| 46 | dependencies = [ |
| 47 | thread_dep, |
| 48 | ] |
| 49 | |
| 50 | # Global settings |
| 51 | add_project_arguments([ |
| 52 | '-D__Userspace__', |
| 53 | '-DSCTP_SIMPLE_ALLOCATOR', |
| 54 | '-DSCTP_PROCESS_LEVEL_LOCKS', |
| 55 | ], language: 'c') |
| 56 | |
| 57 | # OS-specific settings |
| 58 | system = host_machine.system() |
Lennart Grahl | f668bb6 | 2020-01-14 21:01:25 +0100 | [diff] [blame] | 59 | if system in ['linux', 'android'] |
Lennart Grahl | 70f675c | 2019-07-05 22:05:26 +0200 | [diff] [blame] | 60 | add_project_arguments([ |
| 61 | '-D__Userspace_os_Linux', |
| 62 | '-D_GNU_SOURCE', |
| 63 | ], language: 'c') |
| 64 | elif 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') |
Lennart Grahl | f668bb6 | 2020-01-14 21:01:25 +0100 | [diff] [blame] | 71 | elif system in ['darwin', 'ios'] |
Lennart Grahl | 70f675c | 2019-07-05 22:05:26 +0200 | [diff] [blame] | 72 | add_project_arguments([ |
| 73 | '-D__Userspace_os_Darwin', |
Lennart Grahl | 70f675c | 2019-07-05 22:05:26 +0200 | [diff] [blame] | 74 | '-D__APPLE_USE_RFC_2292', |
| 75 | ] + compiler.get_supported_arguments([ |
| 76 | '-Wno-address-of-packed-member', |
| 77 | '-Wno-deprecated-declarations', |
| 78 | ]), language: 'c') |
| 79 | elif system == 'dragonfly' |
| 80 | add_project_arguments([ |
| 81 | '-D__Userspace_os_DragonFly', |
| 82 | '-U__DragonFly__', |
| 83 | ], language: 'c') |
| 84 | elif system == 'netbsd' |
| 85 | add_project_arguments([ |
| 86 | '-D__Userspace_os_NetBSD', |
| 87 | '-U__NetBSD__', |
| 88 | ], language: 'c') |
| 89 | elif system == 'openbsd' |
| 90 | add_project_arguments([ |
| 91 | '-D__Userspace_os_OpenBSD', |
| 92 | '-U__OpenBSD__', |
| 93 | ], language: 'c') |
| 94 | elif 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 |
| 104 | else |
| 105 | error('Unknown system: @0@'.format(system)) |
| 106 | endif |
| 107 | |
| 108 | # Feature: sys/queue |
| 109 | if compiler.has_header('sys/queue.h') |
| 110 | add_project_arguments('-DHAVE_SYS_QUEUE_H', language: 'c') |
| 111 | endif |
| 112 | |
| 113 | # Feature: sys/socket, linux/ifaddr, linux/rtnetlink |
| 114 | if 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 |
| 122 | endif |
| 123 | |
| 124 | # Feature: ICMP |
| 125 | have_sys_types = compiler.has_header('sys/types.h') |
| 126 | have_netinet_in = compiler.has_header('netinet/in.h') |
| 127 | have_netinet_ip = compiler.has_header('netinet/ip.h') |
| 128 | have_netinet_ip_icmp = compiler.has_header('netinet/ip_icmp.h') |
| 129 | if 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') |
| 131 | endif |
| 132 | |
| 133 | # Feature: stdatomic |
| 134 | if compiler.has_header('stdatomic.h') |
| 135 | add_project_arguments('-DHAVE_STDATOMIC_H', language: 'c') |
| 136 | endif |
| 137 | |
| 138 | # Feature: sockaddr.sa_len |
| 139 | prefix = ''' |
| 140 | #include <sys/types.h> |
| 141 | #include <sys/socket.h> |
| 142 | ''' |
| 143 | have_sa_len = compiler.has_member('struct sockaddr', 'sa_len', prefix: prefix) |
| 144 | if have_sa_len |
| 145 | add_project_arguments('-DHAVE_SA_LEN', language: 'c') |
| 146 | endif |
| 147 | |
| 148 | # Feature: sockaddr_in.sin_len / sockaddr_in6.sin6_len / sockaddr_conn.sconn_len |
| 149 | prefix = ''' |
| 150 | #include <sys/types.h> |
| 151 | #include <netinet/in.h> |
| 152 | ''' |
| 153 | have_sin_len = compiler.has_member('struct sockaddr_in', 'sin_len', prefix: prefix) |
| 154 | if have_sin_len |
| 155 | add_project_arguments('-DHAVE_SIN_LEN', language: 'c') |
| 156 | endif |
| 157 | have_sin6_len = compiler.has_member('struct sockaddr_in6', 'sin6_len', prefix: prefix) |
| 158 | if have_sin6_len |
| 159 | add_project_arguments('-DHAVE_SIN6_LEN', language: 'c') |
| 160 | endif |
Alex Băluț | 49dea54 | 2020-01-09 14:17:05 +0000 | [diff] [blame] | 161 | have_sconn_len = compiler.has_member('struct sockaddr_conn', 'sconn_len', prefix: '#include "usrsctp.h"', include_directories: include_directories('usrsctplib')) |
Lennart Grahl | 70f675c | 2019-07-05 22:05:26 +0200 | [diff] [blame] | 162 | if have_sconn_len |
| 163 | add_project_arguments('-DHAVE_SCONN_LEN', language: 'c') |
| 164 | endif |
| 165 | |
| 166 | # Options |
| 167 | if get_option('sctp_invariants') |
| 168 | add_project_arguments('-DINVARIANTS', language: 'c') |
| 169 | endif |
| 170 | if get_option('sctp_debug') |
| 171 | add_project_arguments('-DSCTP_DEBUG', language: 'c') |
| 172 | compile_args += '-DSCTP_DEBUG' |
| 173 | endif |
| 174 | if get_option('sctp_inet') |
| 175 | add_project_arguments('-DINET', language: 'c') |
| 176 | endif |
| 177 | if get_option('sctp_inet6') |
| 178 | add_project_arguments('-DINET6', language: 'c') |
| 179 | endif |
| 180 | |
| 181 | # Library |
| 182 | subdir('usrsctplib') |
| 183 | |
| 184 | # Build library |
Jakub Adam | 47d338c | 2019-07-26 18:49:49 +0200 | [diff] [blame] | 185 | if 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, |
Nirbheek Chauhan | 913de35 | 2019-11-08 23:42:34 +0530 | [diff] [blame] | 201 | dependencies: dependencies, |
Jakub Adam | 47d338c | 2019-07-26 18:49:49 +0200 | [diff] [blame] | 202 | vs_module_defs: usrsctp_def, |
| 203 | install: true, |
| 204 | version: meson.project_version()) |
| 205 | else |
| 206 | usrsctp = library('usrsctp', sources, |
| 207 | dependencies: dependencies, |
| 208 | include_directories: include_dirs, |
| 209 | install: true, |
Alex Băluț | 49dea54 | 2020-01-09 14:17:05 +0000 | [diff] [blame] | 210 | version: meson.project_version(), |
| 211 | c_args: '-U__APPLE__') |
Jakub Adam | 47d338c | 2019-07-26 18:49:49 +0200 | [diff] [blame] | 212 | endif |
Lennart Grahl | 70f675c | 2019-07-05 22:05:26 +0200 | [diff] [blame] | 213 | |
| 214 | # Declare dependency |
| 215 | usrsctp_dep = declare_dependency( |
| 216 | compile_args: compile_args, |
| 217 | include_directories: include_dirs, |
| 218 | link_with: usrsctp) |
| 219 | |
| 220 | # Generate pkg-config file |
| 221 | pkg = import('pkgconfig') |
| 222 | pkg.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) |
| 229 | if 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 |
| 241 | endif |