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