meson: Simplify check for _FORTIFY_SOURCE
Use the compiler.get_define() function to get the value of _FORTIFY_SOURCE instead of iterating over the cpp_args. This simplies the code, but also guarantees to return the actual value of _FORTIFY_SOURCE, even if defined through other means than through the meson cpp_args. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: George Burgess IV <gbiv@google.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
This commit is contained in:
parent
dbe4e0e945
commit
1d61614142
1 changed files with 3 additions and 11 deletions
14
meson.build
14
meson.build
|
@ -104,17 +104,9 @@ if cc.get_id() == 'clang'
|
||||||
# result in macro redefinition errors if the user already has a setting for
|
# result in macro redefinition errors if the user already has a setting for
|
||||||
# `-D_FORTIFY_SOURCE`. Do not enable FORTIFY in either of those cases.
|
# `-D_FORTIFY_SOURCE`. Do not enable FORTIFY in either of those cases.
|
||||||
if get_option('optimization') != '0'
|
if get_option('optimization') != '0'
|
||||||
has_fortify_define = false
|
fortify = cc.get_define('_FORTIFY_SOURCE')
|
||||||
# Assume that if the user requests a FORTIFY level in cpp_args, they
|
if fortify == ''
|
||||||
# do the same for c_args.
|
message('Adding _FORTIFY_SOURCE')
|
||||||
foreach flag : get_option('cpp_args')
|
|
||||||
if flag == '-U_FORTIFY_SOURCE'
|
|
||||||
has_fortify_define = false
|
|
||||||
elif flag.startswith('-D_FORTIFY_SOURCE=')
|
|
||||||
has_fortify_define = true
|
|
||||||
endif
|
|
||||||
endforeach
|
|
||||||
if not has_fortify_define
|
|
||||||
common_arguments += [
|
common_arguments += [
|
||||||
'-D_FORTIFY_SOURCE=2',
|
'-D_FORTIFY_SOURCE=2',
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue