sctp: hook up internal copy of libusrsctp to build
[platform/upstream/gstreamer.git] / ext / sctp / usrsctp / meson.build
1 # Set compiler warning flags
2 compiler = meson.get_compiler('c')
3 if compiler.get_argument_syntax() == 'msvc'
4     compiler_args = compiler.get_supported_arguments([
5         '/wd4100', # 'identifier' : unreferenced formal parameter
6         '/wd4127', # conditional expression is constant
7         '/wd4200', # nonstandard extension used : zero-sized array in struct/union
8         '/wd4214', # bit field types other than int
9         '/wd4706', # assignment within conditional expression
10         '/wd4245', # 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch
11         '/wd4389', # 'operator' : signed/unsigned mismatch
12         '/wd4702', # unreachable code
13         '/wd4701', # Potentially uninitialized local variable 'name' used
14         '/wd4244', # 'conversion' conversion from 'type1' to 'type2', possible loss of data
15     ])
16 else
17     compiler_args = compiler.get_supported_arguments([
18         '-Wfloat-equal',
19         '-Wshadow',
20         '-Wpointer-arith',
21         '-Winit-self',
22         '-Wno-unused-function',
23         '-Wno-unused-parameter',
24         '-Wno-unreachable-code',
25         '-Wstrict-prototypes',
26         # fix GStreamer build with -Werror
27         '-Wno-missing-prototypes',
28         '-Wno-incompatible-pointer-types-discards-qualifiers',
29         '-Wno-address-of-packed-member',
30         '-Wno-discarded-qualifiers',
31         '-Wno-missing-declarations',
32         '-Wno-old-style-definition',
33         '-Wno-redundant-decls',
34         '-Wno-error',
35     ])
36 endif
37
38 # Configuration
39
40 compile_args = [compiler_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 compile_args += [
52     '-D__Userspace__',
53     '-DSCTP_SIMPLE_ALLOCATOR',
54     '-DSCTP_PROCESS_LEVEL_LOCKS',
55 ]
56
57 # OS-specific settings
58 system = host_machine.system()
59 if system in ['linux', 'android']
60     compile_args += [
61         '-D_GNU_SOURCE',
62     ]
63 elif system == 'freebsd'
64     compile_args += [compiler.get_supported_arguments([
65             '-Wno-address-of-packed-member',
66         ])]
67 elif system in ['darwin', 'ios']
68     compile_args += [[
69             '-D__APPLE_USE_RFC_2292',
70         ] + compiler.get_supported_arguments([
71             '-Wno-address-of-packed-member',
72             '-Wno-deprecated-declarations',
73         ])]
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         compile_args += [compiler.get_supported_arguments([
79             '-Wno-format',
80             '-D_WIN32_WINNT=0x601',  # Enables inet_ntop and friends
81         ])]
82     endif
83 else
84     warning('Unknown system: @0@'.format(system))
85     usrsctp_dep = dependency('', required: false)
86     subdir_done()
87 endif
88
89 # Feature: sys/queue
90 if compiler.has_header('sys/queue.h')
91     compile_args += ['-DHAVE_SYS_QUEUE_H']
92 endif
93
94 # Feature: sys/socket, linux/ifaddr, linux/rtnetlink
95 if compiler.has_header('sys/socket.h')
96     if compiler.has_header('linux/if_addr.h')
97         compile_args += ['-DHAVE_LINUX_IF_ADDR_H']
98     endif
99
100     if compiler.has_header('linux/rtnetlink.h')
101         compile_args += ['-DHAVE_LINUX_RTNETLINK_H']
102     endif
103 endif
104
105 # Feature: ICMP
106 have_sys_types = compiler.has_header('sys/types.h')
107 have_netinet_in = compiler.has_header('netinet/in.h')
108 have_netinet_ip = compiler.has_header('netinet/ip.h')
109 have_netinet_ip_icmp = compiler.has_header('netinet/ip_icmp.h')
110 if have_sys_types and have_netinet_in and have_netinet_ip and have_netinet_ip_icmp
111     compile_args += ['-DHAVE_NETINET_IP_ICMP_H']
112 endif
113
114 # Feature: stdatomic
115 if compiler.has_header('stdatomic.h')
116     compile_args += ['-DHAVE_STDATOMIC_H']
117 endif
118
119 # Feature: sockaddr.sa_len
120 prefix = '''
121 #include <sys/types.h>
122 #include <sys/socket.h>
123 '''
124 have_sa_len = compiler.has_member('struct sockaddr', 'sa_len', prefix: prefix)
125 if have_sa_len
126     compile_args += ['-DHAVE_SA_LEN']
127 endif
128
129 # Feature: sockaddr_in.sin_len / sockaddr_in6.sin6_len / sockaddr_conn.sconn_len
130 prefix = '''
131 #include <sys/types.h>
132 #include <netinet/in.h>
133 '''
134 have_sin_len = compiler.has_member('struct sockaddr_in', 'sin_len', prefix: prefix)
135 if have_sin_len
136     compile_args += ['-DHAVE_SIN_LEN']
137 endif
138 have_sin6_len = compiler.has_member('struct sockaddr_in6', 'sin6_len', prefix: prefix)
139 if have_sin6_len
140     compile_args += ['-DHAVE_SIN6_LEN']
141 endif
142 have_sconn_len = compiler.has_member('struct sockaddr_conn', 'sconn_len', prefix: '#include "usrsctp.h"', include_directories: include_directories('usrsctplib'))
143 if have_sconn_len
144     compile_args += ['-DHAVE_SCONN_LEN']
145 endif
146
147 # Options
148 if false
149     compile_args += ['-DINVARIANTS']
150 endif
151 if not gst_debug_disabled
152     compile_args += ['-DSCTP_DEBUG']
153 endif
154 # We do not need the socket API in GStreamer since we will wrap inside a
155 # DTLS packet anyway, because we use SCTP for WebRTC data channels.
156 if false
157     compile_args += ['-DINET']
158 endif
159 if false
160     compile_args += ['-DINET6']
161 endif
162
163 compile_args += ['-DSCTP_STDINT_INCLUDE=<stdint.h>']
164
165 # Library
166 subdir('usrsctplib')
167
168 # Build library
169 usrsctp_static = static_library('usrsctp-static', sources,
170     c_args: compile_args,
171     dependencies: dependencies,
172     include_directories: include_dirs,
173     install: false)
174
175 # Declare dependency
176 usrsctp_dep = declare_dependency(
177     include_directories: include_dirs,
178     link_with: usrsctp_static)