forked from cisco/libsrtp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
323 lines (277 loc) · 8.46 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
project('libsrtp2', '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()
srtp2_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_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)
srtp2_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 == 'nss'
nss_dep = dependency('nss', version: '>= 1.0.1', required: true)
srtp2_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('mbedtls', required: false)
if not mbedtls_dep.found()
mbedtls_dep = cc.find_library('mbedcrypto', has_headers: ['mbedtls/aes.h'], required: true)
endif
srtp2_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_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_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 : 'srtp2')
config_incs = include_directories('.')
crypto_incs = include_directories('crypto/include')
srtp2_incs = include_directories('include')
test_incs = include_directories('test')
default_library = get_option('default_library')
libsrtp2_static = static_library('srtp2', sources, ciphers_sources, hashes_sources,
kernel_sources, math_sources, replay_sources,
dependencies: [srtp2_deps, syslibs],
include_directories: [crypto_incs, srtp2_incs],
install: default_library != 'shared')
if default_library != 'static'
libsrtp2 = shared_library('srtp2',
dependencies: [srtp2_deps, syslibs],
soversion : soversion,
vs_module_defs: 'srtp.def',
link_whole: libsrtp2_static,
install: true)
else
libsrtp2 = libsrtp2_static
endif
subdir('include/srtp2') # copies public_headers into the builddir
public_incs = include_directories('include') # sets public_incs
libsrtp2_dep = declare_dependency(link_with: libsrtp2,
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'
libsrtp2_for_tests = libsrtp2_static
else
libsrtp2_for_tests = libsrtp2
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(libsrtp2,
filebase: meson.project_name(),
name: meson.project_name(),
version: meson.project_version(),
description: 'Library for SRTP (Secure Realtime Transport Protocol)')