-
Notifications
You must be signed in to change notification settings - Fork 211
/
Copy pathmeson.build
390 lines (360 loc) · 9.21 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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
project(
'openssl',
'c',
version: '3.0.8',
license : 'Apache-2.0',
meson_version: '>= 0.55',
default_options: [
'warning_level=1',
],
)
# Make sure to generate configs in case they are not already
fs = import('fs')
if not fs.exists('generated-config')
message('Generating OpenSSL configs...')
if host_machine.system() != 'linux'
error('Generator only works on Linux, other platforms are not supported')
endif
bash = find_program('bash')
run_command(
bash,
'generator.sh',
check: true,
env: ['OPENSSL_VERSION=' + meson.project_version()],
)
endif
include_directories = [
'include',
'crypto',
'crypto/modes',
'crypto/ec/curve448',
'crypto/ec/curve448/arch_32',
'providers/common/include',
'providers/implementations/include',
]
compiler = meson.get_compiler('c')
dependencies = [
# TODO: Make this optionally added once we have threading configurable via options
dependency('threads'),
]
defines = [
# Compile out hardware engines. Most are stubs that dynamically load
# the real driver but that poses a security liability when an attacker
# is able to create a malicious DLL in one of the default search paths.
'OPENSSL_NO_HW',
]
c_args = []
asm_opt = get_option('asm')
if asm_opt.disabled()
gas_or_nasm = false
else
gas_or_nasm = (
find_program('as', required: false).found() or
find_program('nasm', required: false).found()
)
endif
is_bsd = host_machine.system() in ['dragonfly', 'freebsd', 'netbsd', 'openbsd']
is_darwin = host_machine.system() == 'darwin'
is_linux = host_machine.system() in ['linux', 'android']
is_sunos = host_machine.system() == 'sunos'
is_windows = host_machine.system() == 'windows'
is_x86 = host_machine.cpu_family() == 'x86'
is_x86_64 = host_machine.cpu_family() == 'x86_64'
is_aarch64 = host_machine.cpu_family() == 'aarch64'
is_mips64 = host_machine.cpu_family() == 'mips64'
is_s390x = host_machine.cpu_family() == 's390x'
is_arm = host_machine.cpu_family() == 'arm'
is_ppc64 = host_machine.cpu_family() == 'ppc64'
is_riskv64 = host_machine.cpu_family() == 'riscv64'
if gas_or_nasm
asm = 'asm'
if is_bsd
if is_x86
arch_subdir = 'BSD-x86'
elif is_x86_64
arch_subdir = 'BSD-x86_64'
else
asm = 'no-asm'
endif
elif is_darwin
if is_aarch64
arch_subdir = 'darwin64-arm64-cc'
elif is_x86_64
arch_subdir = 'darwin64-x86_64-cc'
elif is_x86
arch_subdir = 'darwin-i386-cc'
else
asm = 'no-asm'
endif
elif is_linux
if is_mips64
arch_subdir = 'linux64-mips64'
elif is_s390x
arch_subdir = 'linux64-s390x'
elif is_aarch64
arch_subdir = 'linux-aarch64'
elif is_arm
arch_subdir = 'linux-armv4'
elif is_ppc64
arch_subdir = 'linux-ppc64le'
elif is_x86
arch_subdir = 'linux-elf'
elif is_x86_64
arch_subdir = 'linux-x86_64'
else
asm = 'no-asm'
endif
elif is_sunos
if is_x86_64
arch_subdir = 'solaris64-x86_64-gcc'
elif is_x86
arch_subdir = 'solaris-x86-gcc'
else
asm = 'no-asm'
endif
elif is_windows
if is_x86
warning('x86 + windows combo does not support ASM yet, please contribute')
asm = 'no-asm'
# TODO: Port this for Windows and uncomment
# arch_subdir = 'VC-WIN32'
# asm = 'asm'
#'rules': [
# {
# 'rule_name': 'Assemble',
# 'extension': 'asm',
# 'inputs': [],
# 'outputs': [
# '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).obj',
# ],
# 'action': [
# 'nasm.exe',
# '-f win32',
# '-o', '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).obj',
# '<(RULE_INPUT_PATH)',
# ],
# }
#],
elif is_x86_64
warning('x86_64 + windows combo does not support ASM yet, please contribute')
asm = 'no-asm'
# TODO: Port this for Windows and uncomment
# arch_subdir = 'VC-WIN64A'
# asm = 'asm'
#'rules': [
# {
# 'rule_name': 'Assemble',
# 'extension': 'asm',
# 'inputs': [],
# 'outputs': [
# '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).obj',
# ],
# 'action': [
# 'nasm.exe',
# '-f win64',
# '-DNEAR',
# '-Ox',
# '-g',
# '-o', '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).obj',
# '<(RULE_INPUT_PATH)',
# ],
# }
#],
else
asm = 'no-asm'
endif
else
asm = 'no-asm'
endif
elif asm_opt.enabled()
error('Neither GNU Assembler nor Netwide Assembler were found, cannot use use "asm=enabled" option')
else
asm = 'no-asm'
endif
if asm == 'no-asm'
defines += ['OPENSSL_NO_ASM']
error_message = 'Unsupported arch+OS combo: ' + host_machine.cpu_family() + ' + ' + host_machine.system()
if is_bsd
if is_x86
arch_subdir = 'BSD-x86'
elif is_x86_64
arch_subdir = 'BSD-x86_64'
else
error(error_message)
endif
elif is_darwin
if is_aarch64
arch_subdir = 'darwin64-arm64-cc'
elif is_x86_64
arch_subdir = 'darwin64-x86_64-cc'
elif is_x86
arch_subdir = 'darwin-i386-cc'
else
error(error_message)
endif
elif is_linux
if is_mips64
arch_subdir = 'linux64-mips64'
elif is_riskv64
arch_subdir = 'linux64-riscv64'
elif is_s390x
arch_subdir = 'linux64-s390x'
elif is_aarch64
arch_subdir = 'linux-aarch64'
elif is_arm
arch_subdir = 'linux-armv4'
elif is_ppc64
arch_subdir = 'linux-ppc64le'
elif is_x86
arch_subdir = 'linux-elf'
elif is_x86_64
arch_subdir = 'linux-x86_64'
else
error(error_message)
endif
elif is_sunos
if is_x86_64
arch_subdir = 'solaris64-x86_64-gcc'
elif is_x86
arch_subdir = 'solaris-x86-gcc'
else
error(error_message)
endif
elif is_windows
if is_x86
arch_subdir = 'VC-WIN32'
elif is_aarch64
arch_subdir = 'VC-WIN64-ARM'
elif is_x86_64
arch_subdir = 'VC-WIN64A'
else
error(error_message)
endif
else
error(error_message)
endif
message('OpenSSL is configured without ASM support')
else
message('OpenSSL is configured with ASM support')
endif
subdir('generated-config/archs' / arch_subdir / asm)
# Build options specific to OS, engines are disabled on purpose for the same reasons as `OPENSSL_NO_HW` above
if is_windows
defines += [
## default of Win. See INSTALL in openssl repo.
'OPENSSLDIR="C:\\Program Files\\Common Files\\SSL"',
'ENGINESDIR="NUL"',
'MODULESDIR="NUL"',
'OPENSSL_SYS_WIN32', 'WIN32_LEAN_AND_MEAN', 'L_ENDIAN',
'_CRT_SECURE_NO_DEPRECATE', 'UNICODE', '_UNICODE',
]
if compiler.get_id() == 'msvc'
c_args += [
'-wd4090', '-Gs0', '-GF', '-Gy', '-nologo',
]
endif
elif is_darwin
defines += [
'OPENSSLDIR="/System/Library/OpenSSL/"',
'ENGINESDIR="/dev/null"',
'MODULESDIR="/dev/null"',
]
c_args += [
'-Wno-missing-field-initializers',
]
elif is_sunos
defines += [
'OPENSSLDIR="/etc/ssl"',
'ENGINESDIR="/dev/null"',
'MODULESDIR="/dev/null"',
'__EXTENSIONS__'
]
else
# Linux and others
defines += [
'OPENSSLDIR="/etc/ssl"',
'ENGINESDIR="/dev/null"',
'MODULESDIR="/dev/null"',
]
c_args += [
'-Wno-missing-field-initializers',
]
if compiler.get_id() != 'clang'
c_args += [
'-Wno-old-style-declaration',
]
endif
endif
foreach library: openssl_libraries
# MSVC fails with "ERROR: C static library 'ws2_32' not found" when `static` is specified at all
if compiler.get_id() == 'msvc'
dependencies += [
compiler.find_library(library),
]
else
dependencies += [
compiler.find_library(
library,
static: get_option('default_library') == 'static',
),
]
endif
endforeach
# We may need to add some defines for static builds
if get_option('default_library') == 'static'
defines += [
'OSSL_CRYPTO_DSO_CONF_H',
'DSO_NONE',
'DSO_EXTENSION=".so"',
'OPENSSL_NO_DSO',
]
endif
foreach define : defines + openssl_defines
c_args += ['-D' + define]
endforeach
c_args += openssl_cflags
include_directories += openssl_include_directories
libcrypto_lib = library(
'crypto',
dependencies: dependencies,
sources: libcrypto_sources,
include_directories: include_directories,
c_args: c_args,
vs_module_defs: 'crypto.def',
install: true,
)
libcrypto_dep = declare_dependency(
include_directories: include_directories,
dependencies: dependencies,
link_with: libcrypto_lib,
)
libssl_lib = library(
'ssl',
dependencies: dependencies + [libcrypto_dep],
sources: libssl_sources,
include_directories: include_directories,
c_args: c_args,
vs_module_defs: 'ssl.def',
install: true,
)
libssl_dep = declare_dependency(
include_directories: include_directories,
dependencies: dependencies + [libcrypto_dep],
link_with: libssl_lib,
)
openssl_dep = declare_dependency(
dependencies: [libcrypto_dep, libssl_dep],
)
openssl_cli_directories = include_directories + [
'apps/include'
]
cli_opt = get_option('build_cli')
openssl_cli = executable(
'openssl',
build_by_default: cli_opt,
dependencies: dependencies + [openssl_dep],
sources: openssl_cli_sources,
include_directories: openssl_cli_directories,
c_args: c_args,
install: cli_opt,
)