blob: 51a4a435e4e539cd1532ae34be7057d008cdd6fd [file] [log] [blame]
Lennart Grahl70f675c2019-07-05 22:05:26 +02001# Project definition
2project('usrsctplib', 'c',
Vitaly Zaitsev07f871b2021-01-13 15:37:19 +01003 version: '0.9.5.0',
Nazar Mokrynskyi1d204412021-07-30 16:04:47 +03004 default_options: [
5 'c_std=c99',
6 'warning_level=2',
7 ],
Lennart Grahl70f675c2019-07-05 22:05:26 +02008 meson_version: '>=0.49.0')
9
Vitaly Zaitsev07f871b2021-01-13 15:37:19 +010010# Shared library API and ABI versions
11# Notice: shared library version must be in X.Y.Z format only
12soversion_full = '2.0.0'
13soversion_short = '2'
14
Lennart Grahl70f675c2019-07-05 22:05:26 +020015# Set compiler warning flags
16compiler = meson.get_compiler('c')
17if 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 ])
30else
31 compiler_args = compiler.get_supported_arguments([
32 '-pedantic',
Lennart Grahl70f675c2019-07-05 22:05:26 +020033 '-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 ])
42endif
43add_project_arguments(compiler_args, language: 'c')
44
45# Configuration
46compile_args = []
47
48# Dependency: Threads
49thread_dep = dependency('threads', required: true)
50
51# Dependencies list
52dependencies = [
53 thread_dep,
54]
55
56# Global settings
57add_project_arguments([
58 '-D__Userspace__',
59 '-DSCTP_SIMPLE_ALLOCATOR',
60 '-DSCTP_PROCESS_LEVEL_LOCKS',
61], language: 'c')
62
63# OS-specific settings
64system = host_machine.system()
Lennart Grahlf668bb62020-01-14 21:01:25 +010065if system in ['linux', 'android']
Lennart Grahl70f675c2019-07-05 22:05:26 +020066 add_project_arguments([
Lennart Grahl70f675c2019-07-05 22:05:26 +020067 '-D_GNU_SOURCE',
68 ], language: 'c')
69elif system == 'freebsd'
Lennart Grahladf61512020-06-26 10:49:07 +020070 add_project_arguments(compiler.get_supported_arguments([
71 '-Wno-address-of-packed-member',
72 ]), language: 'c')
Lennart Grahlf668bb62020-01-14 21:01:25 +010073elif system in ['darwin', 'ios']
Lennart Grahl70f675c2019-07-05 22:05:26 +020074 add_project_arguments([
Lennart Grahl70f675c2019-07-05 22:05:26 +020075 '-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ås74fb47a2022-03-29 02:15:11 +020080elif system == 'qnx'
81 add_project_arguments([
82 '-D_QNX_SOURCE',
83 ], language: 'c')
Lennart Grahl70f675c2019-07-05 22:05:26 +020084elif system == 'windows'
Lennart Grahl70f675c2019-07-05 22:05:26 +020085 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
93else
94 error('Unknown system: @0@'.format(system))
95endif
96
97# Feature: sys/queue
Ole André Vadla Ravnås74fb47a2022-03-29 02:15:11 +020098if system != 'qnx' and compiler.has_header('sys/queue.h')
Lennart Grahl70f675c2019-07-05 22:05:26 +020099 add_project_arguments('-DHAVE_SYS_QUEUE_H', language: 'c')
100endif
101
102# Feature: sys/socket, linux/ifaddr, linux/rtnetlink
103if 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
111endif
112
113# Feature: ICMP
114have_sys_types = compiler.has_header('sys/types.h')
115have_netinet_in = compiler.has_header('netinet/in.h')
116have_netinet_ip = compiler.has_header('netinet/ip.h')
117have_netinet_ip_icmp = compiler.has_header('netinet/ip_icmp.h')
118if 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')
120endif
121
Ole André Vadla Ravnåse984d7f2021-05-17 22:25:23 +0200122# Feature: net/route
123if compiler.has_header('net/route.h')
124 add_project_arguments('-DHAVE_NET_ROUTE_H', language: 'c')
125endif
126
Lennart Grahl70f675c2019-07-05 22:05:26 +0200127# Feature: stdatomic
128if compiler.has_header('stdatomic.h')
129 add_project_arguments('-DHAVE_STDATOMIC_H', language: 'c')
130endif
131
132# Feature: sockaddr.sa_len
133prefix = '''
134#include <sys/types.h>
135#include <sys/socket.h>
136'''
137have_sa_len = compiler.has_member('struct sockaddr', 'sa_len', prefix: prefix)
138if have_sa_len
139 add_project_arguments('-DHAVE_SA_LEN', language: 'c')
140endif
141
142# Feature: sockaddr_in.sin_len / sockaddr_in6.sin6_len / sockaddr_conn.sconn_len
143prefix = '''
144#include <sys/types.h>
145#include <netinet/in.h>
146'''
147have_sin_len = compiler.has_member('struct sockaddr_in', 'sin_len', prefix: prefix)
148if have_sin_len
149 add_project_arguments('-DHAVE_SIN_LEN', language: 'c')
150endif
151have_sin6_len = compiler.has_member('struct sockaddr_in6', 'sin6_len', prefix: prefix)
152if have_sin6_len
153 add_project_arguments('-DHAVE_SIN6_LEN', language: 'c')
154endif
Alex Băluț49dea542020-01-09 14:17:05 +0000155have_sconn_len = compiler.has_member('struct sockaddr_conn', 'sconn_len', prefix: '#include "usrsctp.h"', include_directories: include_directories('usrsctplib'))
Lennart Grahl70f675c2019-07-05 22:05:26 +0200156if have_sconn_len
157 add_project_arguments('-DHAVE_SCONN_LEN', language: 'c')
158endif
159
160# Options
161if get_option('sctp_invariants')
162 add_project_arguments('-DINVARIANTS', language: 'c')
163endif
164if get_option('sctp_debug')
165 add_project_arguments('-DSCTP_DEBUG', language: 'c')
166 compile_args += '-DSCTP_DEBUG'
167endif
168if get_option('sctp_inet')
169 add_project_arguments('-DINET', language: 'c')
170endif
171if get_option('sctp_inet6')
172 add_project_arguments('-DINET6', language: 'c')
173endif
174
175# Library
176subdir('usrsctplib')
177
178# Build library
Jakub Adam47d338c2019-07-26 18:49:49 +0200179if 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 Chauhan913de352019-11-08 23:42:34 +0530195 dependencies: dependencies,
Jakub Adam47d338c2019-07-26 18:49:49 +0200196 vs_module_defs: usrsctp_def,
197 install: true,
198 version: meson.project_version())
199else
200 usrsctp = library('usrsctp', sources,
201 dependencies: dependencies,
202 include_directories: include_dirs,
203 install: true,
Vitaly Zaitsev07f871b2021-01-13 15:37:19 +0100204 version: soversion_full,
205 soversion: soversion_short)
Jakub Adam47d338c2019-07-26 18:49:49 +0200206endif
Lennart Grahl70f675c2019-07-05 22:05:26 +0200207
208# Declare dependency
209usrsctp_dep = declare_dependency(
210 compile_args: compile_args,
211 include_directories: include_dirs,
212 link_with: usrsctp)
213
214# Generate pkg-config file
215pkg = import('pkgconfig')
216pkg.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)
223if 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
235endif