-
Notifications
You must be signed in to change notification settings - Fork 477
/
meson.build
348 lines (302 loc) · 9.23 KB
/
meson.build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
project('libsrtp3', 'c', version: '3.0.0',
meson_version: '>= 0.52.0',
default_options: ['buildtype=debugoptimized'])
soversion = 1
cc = meson.get_compiler('c')
host_system = host_machine.system()
srtp3_deps = []
syslibs = []
if host_system == 'windows'
syslibs += [cc.find_library('ws2_32')] # for socket
endif
cdata = configuration_data()
cdata.set_quoted('PACKAGE_VERSION', meson.project_version())
cdata.set_quoted('PACKAGE_STRING', '@0@ @1@'.format(meson.project_name(), meson.project_version()))
check_headers = [
'arpa/inet.h',
'byteswap.h',
'inttypes.h',
'machine/types.h',
'netinet/in.h',
'stdint.h',
'stdlib.h',
'sys/int_types.h',
'sys/socket.h',
'sys/types.h',
'sys/uio.h',
'unistd.h',
]
if host_system == 'windows'
check_headers += ['windows.h', 'winsock2.h']
endif
foreach h : check_headers
if cc.has_header(h)
cdata.set('HAVE_' + h.to_upper().underscorify(), true)
endif
endforeach
check_functions = [
'sigaction',
'inet_aton',
'inet_pton',
'usleep',
'socket',
]
foreach f : check_functions
if cc.has_function(f, dependencies: syslibs)
cdata.set('HAVE_' + f.to_upper().underscorify(), true)
endif
endforeach
if host_machine.endian() == 'big'
cdata.set('WORDS_BIGENDIAN', true)
endif
# This follows the checks in configure.ac, but is it up-to-date ?!
if host_machine.cpu_family() in ['x86', 'x86_64']
cdata.set('CPU_CISC', true, description: 'Building for a CISC machine (e.g. Intel)')
cdata.set('HAVE_X86', true, description: 'Use x86 inlined assembly code')
else
cdata.set('CPU_RISC', true, description: 'Building for a RISC machine (assume slow byte access)')
endif
# Pretty much all supported platforms have stdint.h nowadays
assert(cc.has_header('stdint.h'), 'stdint.h not available!')
# we'll just assume these types are available via stdint.h
foreach type : ['int8_t', 'uint8_t', 'int16_t', 'uint16_t', 'int32_t', 'uint32_t', 'uint64_t']
cdata.set('HAVE_' + type.to_upper().underscorify(), true)
endforeach
size_t_prefix = '''
#ifdef _WIN32
#include <crtdefs.h>
#endif
#include <sys/types.h>
'''
if not cc.has_type('size_t', prefix: size_t_prefix)
cdata.set('size_t', 'unsigned int')
endif
# check type availability and size
foreach type : ['unsigned long', 'unsigned long long']
if cc.has_type(type)
cdata.set('HAVE_' + type.to_upper().underscorify(), true)
cdata.set('SIZEOF_' + type.to_upper().underscorify(), cc.sizeof(type))
endif
endforeach
if not cc.compiles('inline void func(); void func() { } int main() { func(); return 0; }', name: 'inline keyword check')
if cc.compiles('__inline void func(); void func() { } int main() { func(); return 0; }', name: '__inline keyword check')
cdata.set('inline', '__inline')
else
cdata.set('inline', '')
endif
endif
if get_option('log-stdout')
cdata.set('ERR_REPORTING_STDOUT', true)
endif
if get_option('log-file') != ''
cdata.set('ERR_REPORTING_FILE', get_option('log-file'))
endif
if cdata.has('ERR_REPORTING_STDOUT') and cdata.has('ERR_REPORTING_FILE')
error('The log-stdout and log-file options are mutually exclusive!')
endif
if get_option('debug-logging')
cdata.set('ENABLE_DEBUG_LOGGING', true)
endif
use_openssl = false
use_wolfssl = false
use_nss = false
use_mbedtls = false
crypto_library = get_option('crypto-library')
if crypto_library == 'openssl'
openssl_dep = dependency('openssl', version: '>= 1.1.0', required: true)
srtp3_deps += [openssl_dep]
cdata.set('GCM', true)
cdata.set('OPENSSL', true)
cdata.set('USE_EXTERNAL_CRYPTO', true)
use_openssl = true
# NOTE: This is not available in upstream OpenSSL yet. It's only in 'certain'
# forks of OpenSSL: https://github.com/cisco/libsrtp/issues/458
if (
openssl_dep.type_name() != 'internal' and
not get_option('crypto-library-kdf').disabled() and
cc.has_function('kdf_srtp', dependencies: openssl_dep)
)
cdata.set('OPENSSL_KDF', true)
elif get_option('crypto-library-kdf').enabled()
error('KDF support has been enabled, but OpenSSL does not provide it')
endif
elif crypto_library == 'wolfssl'
wolfssl_dep = dependency('wolfssl', version: '>= 5.7.0', required: true)
srtp3_deps += [wolfssl_dep]
cdata.set('GCM', true)
cdata.set('WOLFSSL', true)
cdata.set('USE_EXTERNAL_CRYPTO', true)
use_wolfssl = true
if (
wolfssl_dep.type_name() != 'internal' and
not get_option('crypto-library-kdf').disabled() and
cc.has_function('wc_SRTCP_KDF', dependencies: wolfssl_dep)
)
cdata.set('WOLFSSL_KDF', true)
elif get_option('crypto-library-kdf').enabled()
error('KDF support has been enabled, but wolfSSL does not provide it')
endif
elif crypto_library == 'nss'
nss_dep = dependency('nss', version: '>= 1.0.1', required: true)
srtp3_deps += [nss_dep]
cdata.set('GCM', true)
cdata.set('NSS', true)
cdata.set('USE_EXTERNAL_CRYPTO', true)
use_nss = true
# TODO(RLB): Use NSS for KDF
if get_option('crypto-library-kdf').enabled()
error('KDF support has not been implemented for NSS')
endif
elif crypto_library == 'mbedtls'
mbedtls_dep = dependency('mbedcrypto', required: false)
if not mbedtls_dep.found()
mbedtls_dep = cc.find_library('mbedcrypto', has_headers: ['mbedtls/aes.h'], required: true)
endif
srtp3_deps += [mbedtls_dep]
cdata.set('GCM', true)
cdata.set('MBEDTLS', true)
cdata.set('USE_EXTERNAL_CRYPTO', true)
use_mbedtls = true
# TODO(RLB): Use NSS for KDF
if get_option('crypto-library-kdf').enabled()
error('KDF support has not been implemented for mbedtls')
endif
endif
configure_file(output: 'config.h', configuration: cdata)
add_project_arguments('-DHAVE_CONFIG_H', language: 'c')
if get_option('buildtype') != 'plain'
w_args = ['-Wstrict-prototypes']
add_project_arguments(cc.get_supported_arguments(w_args), language: 'c')
endif
if get_option('optimization') not in ['0', 'g', 's']
# -fexpensive-optimizations set already by default for -O2, -O3
o_args = ['-funroll-loops']
add_project_arguments(cc.get_supported_arguments(o_args), language: 'c')
endif
sources = files(
'srtp/srtp.c',
)
ciphers_sources = files(
'crypto/cipher/cipher.c',
'crypto/cipher/cipher_test_cases.c',
'crypto/cipher/null_cipher.c',
)
if use_openssl
ciphers_sources += files(
'crypto/cipher/aes_icm_ossl.c',
'crypto/cipher/aes_gcm_ossl.c',
)
elif use_wolfssl
ciphers_sources += files(
'crypto/cipher/aes_icm_wssl.c',
'crypto/cipher/aes_gcm_wssl.c',
)
elif use_nss
ciphers_sources += files(
'crypto/cipher/aes_icm_nss.c',
'crypto/cipher/aes_gcm_nss.c',
)
elif use_mbedtls
ciphers_sources += files(
'crypto/cipher/aes_icm_mbedtls.c',
'crypto/cipher/aes_gcm_mbedtls.c',
)
else
ciphers_sources += files(
'crypto/cipher/aes.c',
'crypto/cipher/aes_icm.c',
)
endif
hashes_sources = files(
'crypto/hash/auth.c',
'crypto/hash/auth_test_cases.c',
'crypto/hash/null_auth.c',
)
if use_openssl
hashes_sources += files(
'crypto/hash/hmac_ossl.c',
)
elif use_wolfssl
hashes_sources += files(
'crypto/hash/hmac_wssl.c',
)
elif use_nss
hashes_sources += files(
'crypto/hash/hmac_nss.c',
)
elif use_mbedtls
hashes_sources += files(
'crypto/hash/hmac_mbedtls.c',
)
else
hashes_sources += files(
'crypto/hash/hmac.c',
'crypto/hash/sha1.c',
)
endif
kernel_sources = files(
'crypto/kernel/alloc.c',
'crypto/kernel/crypto_kernel.c',
'crypto/kernel/err.c',
'crypto/kernel/key.c',
)
math_sources = files(
'crypto/math/datatypes.c',
)
replay_sources = files(
'crypto/replay/rdb.c',
'crypto/replay/rdbx.c',
)
public_headers = files(
'include/srtp.h',
'crypto/include/auth.h',
'crypto/include/cipher.h',
'crypto/include/crypto_types.h',
)
install_headers(public_headers, subdir : 'srtp3')
config_incs = include_directories('.')
crypto_incs = include_directories('crypto/include')
srtp3_incs = include_directories('include')
test_incs = include_directories('test')
default_library = get_option('default_library')
libsrtp3_static = static_library('srtp3', sources, ciphers_sources, hashes_sources,
kernel_sources, math_sources, replay_sources,
dependencies: [srtp3_deps, syslibs],
include_directories: [crypto_incs, srtp3_incs],
install: default_library != 'shared')
if default_library != 'static'
libsrtp3 = shared_library('srtp3',
soversion : soversion,
vs_module_defs: 'srtp.def',
link_whole: libsrtp3_static,
install: true)
else
libsrtp3 = libsrtp3_static
endif
subdir('include/srtp3') # copies public_headers into the builddir
public_incs = include_directories('include') # sets public_incs
libsrtp3_dep = declare_dependency(link_with: libsrtp3,
include_directories: public_incs)
if not get_option('tests').disabled()
# Tests use non-public API, and when building on Windows the only symbols we
# export are those in srtp.def, so link to the static library in that case.
if host_system == 'windows'
libsrtp3_for_tests = libsrtp3_static
else
libsrtp3_for_tests = libsrtp3
endif
subdir('crypto/test')
subdir('test')
endif
if not get_option('fuzzer').disabled()
subdir('fuzzer')
endif
if not get_option('doc').disabled()
subdir('doc')
endif
pkgconfig = import('pkgconfig')
pkgconfig.generate(libsrtp3,
filebase: meson.project_name(),
name: meson.project_name(),
version: meson.project_version(),
description: 'Library for SRTP (Secure Realtime Transport Protocol)')