2 project('usrsctplib', 'c',
4 default_options: ['c_std=c99'],
5 meson_version: '>=0.49.0')
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
23 compiler_args = compiler.get_supported_arguments([
31 '-Wno-unused-function',
32 '-Wno-unused-parameter',
33 '-Wno-unreachable-code',
34 '-Wstrict-prototypes',
37 add_project_arguments(compiler_args, language: 'c')
43 thread_dep = dependency('threads', required: true)
51 add_project_arguments([
53 '-DSCTP_SIMPLE_ALLOCATOR',
54 '-DSCTP_PROCESS_LEVEL_LOCKS',
57 # OS-specific settings
58 system = host_machine.system()
59 if system in ['linux', 'android']
60 add_project_arguments([
63 elif system == 'freebsd'
64 add_project_arguments(compiler.get_supported_arguments([
65 '-Wno-address-of-packed-member',
67 elif system in ['darwin', 'ios']
68 add_project_arguments([
69 '-D__APPLE_USE_RFC_2292',
70 ] + compiler.get_supported_arguments([
71 '-Wno-address-of-packed-member',
72 '-Wno-deprecated-declarations',
74 elif system == 'windows'
75 dependencies += compiler.find_library('ws2_32', required: true)
76 dependencies += compiler.find_library('iphlpapi', required: true)
77 if compiler.get_id() == 'gcc'
78 add_project_arguments(compiler.get_supported_arguments([
80 '-D_WIN32_WINNT=0x601', # Enables inet_ntop and friends
84 error('Unknown system: @0@'.format(system))
88 if compiler.has_header('sys/queue.h')
89 add_project_arguments('-DHAVE_SYS_QUEUE_H', language: 'c')
92 # Feature: sys/socket, linux/ifaddr, linux/rtnetlink
93 if compiler.has_header('sys/socket.h')
94 if compiler.has_header('linux/if_addr.h')
95 add_project_arguments('-DHAVE_LINUX_IF_ADDR_H', language: 'c')
98 if compiler.has_header('linux/rtnetlink.h')
99 add_project_arguments('-DHAVE_LINUX_RTNETLINK_H', language: 'c')
104 have_sys_types = compiler.has_header('sys/types.h')
105 have_netinet_in = compiler.has_header('netinet/in.h')
106 have_netinet_ip = compiler.has_header('netinet/ip.h')
107 have_netinet_ip_icmp = compiler.has_header('netinet/ip_icmp.h')
108 if have_sys_types and have_netinet_in and have_netinet_ip and have_netinet_ip_icmp
109 add_project_arguments('-DHAVE_NETINET_IP_ICMP_H', language: 'c')
113 if compiler.has_header('stdatomic.h')
114 add_project_arguments('-DHAVE_STDATOMIC_H', language: 'c')
117 # Feature: sockaddr.sa_len
119 #include <sys/types.h>
120 #include <sys/socket.h>
122 have_sa_len = compiler.has_member('struct sockaddr', 'sa_len', prefix: prefix)
124 add_project_arguments('-DHAVE_SA_LEN', language: 'c')
127 # Feature: sockaddr_in.sin_len / sockaddr_in6.sin6_len / sockaddr_conn.sconn_len
129 #include <sys/types.h>
130 #include <netinet/in.h>
132 have_sin_len = compiler.has_member('struct sockaddr_in', 'sin_len', prefix: prefix)
134 add_project_arguments('-DHAVE_SIN_LEN', language: 'c')
136 have_sin6_len = compiler.has_member('struct sockaddr_in6', 'sin6_len', prefix: prefix)
138 add_project_arguments('-DHAVE_SIN6_LEN', language: 'c')
140 have_sconn_len = compiler.has_member('struct sockaddr_conn', 'sconn_len', prefix: '#include "usrsctp.h"', include_directories: include_directories('usrsctplib'))
142 add_project_arguments('-DHAVE_SCONN_LEN', language: 'c')
146 if get_option('sctp_invariants')
147 add_project_arguments('-DINVARIANTS', language: 'c')
149 if get_option('sctp_debug')
150 add_project_arguments('-DSCTP_DEBUG', language: 'c')
151 compile_args += '-DSCTP_DEBUG'
153 if get_option('sctp_inet')
154 add_project_arguments('-DINET', language: 'c')
156 if get_option('sctp_inet6')
157 add_project_arguments('-DINET6', language: 'c')
164 if compiler.get_id() == 'msvc' and get_option('default_library') == 'shared'
165 # Needed by usrsctp_def
166 find_program('dumpbin')
168 usrsctp_static = static_library('usrsctp-static', sources,
169 dependencies: dependencies,
170 include_directories: include_dirs)
172 usrsctp_def = custom_target('usrsctp.def',
173 command: [find_program('gen-def.py'), '@INPUT@'],
174 input: usrsctp_static,
175 output: 'usrsctp.def',
178 usrsctp = shared_library('usrsctp',
179 link_whole: usrsctp_static,
180 dependencies: dependencies,
181 vs_module_defs: usrsctp_def,
183 version: meson.project_version())
185 usrsctp = library('usrsctp', sources,
186 dependencies: dependencies,
187 include_directories: include_dirs,
189 version: meson.project_version(),
190 c_args: '-U__APPLE__')
194 usrsctp_dep = declare_dependency(
195 compile_args: compile_args,
196 include_directories: include_dirs,
199 # Generate pkg-config file
200 pkg = import('pkgconfig')
201 pkg.generate(usrsctp,
203 description: 'A portable SCTP userland stack',
204 url: 'https://github.com/sctplab/usrsctp',
205 extra_cflags: compile_args)
207 # Programs (optional)
208 if get_option('sctp_build_programs')
212 foreach name, sources : programs
215 programs_helper_sources + sources,
216 dependencies: dependencies,
218 include_directories: include_dirs)