Debian Codegraph @

meson/hardening/fortify-source/meson.build

raw
1 fortify_source_opt = get_option('hardening-fortify-source')
2 fortify_source = fortify_source_opt != 'disabled'
3 fortify_source_level = 0
4
5 if fortify_source and get_option('buildtype') == 'debug'
6 error('Source fortification was requested but it requires compiling with optimization. ' +
7 'A debug buildtype was requested, try setting buildtype=debugoptimized instead')
8 endif
9
10 if fortify_source
11 fortify_source_level = 2
12 if fortify_source_opt == 'auto'
13 fortify_source_level = 3
14 else
15 fortify_source_level = fortify_source_opt.to_int()
16 endif
17
18 variants = [3, 2, 1]
19 foreach variant: variants
20 variant_str = variant.to_string()
21 if fortify_source_level == variant
22 if cxx.has_argument('-D_FORTIFY_SOURCE=' + variant_str)
23 add_project_arguments('-U_FORTIFY_SOURCE', '-D_FORTIFY_SOURCE=' + variant_str, language: ['c', 'cpp'])
24 break
25 else
26 fortify_source_level = fortify_source_level - 1
27 endif
28 endif
29 endforeach
30 endif
31
32 fortify_source = fortify_source and fortify_source_level != 0
33 summary('Source Fortification', fortify_source, bool_yn: true, section: 'Hardening')
34
35 if fortify_source
36 summary('Source Fortification Level', fortify_source_level, section: 'Hardening')
37 endif