summaryrefslogtreecommitdiff
path: root/meson.build
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-08-18 04:35:04 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-08-22 11:10:43 +0300
commit965c5bf7fbf5b5140fdfa3b39efb8e484d72fddb (patch)
tree86f34e1511c528656cdc77f5082cf9bb3564995e /meson.build
parentaf4304e497837963388e8ac4253c49cd6bd3ef54 (diff)
meson: Define _FORTIFY_SOURCE for optimised builds
_FORTIFY_SOURCE adds useful checks during compilation. The option is enabled by default by gcc on all non-optimised builds (as it requires -O1 or higher). Enable it explicitly for clang. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'meson.build')
-rw-r--r--meson.build22
1 files changed, 16 insertions, 6 deletions
diff --git a/meson.build b/meson.build
index 13d0605f..5201a2f5 100644
--- a/meson.build
+++ b/meson.build
@@ -38,12 +38,22 @@ common_arguments = [
c_arguments = common_arguments
cpp_arguments = common_arguments
-# Use libc++ by default if available instead of libstdc++ when compiling with
-# clang.
-if cc.get_id() == 'clang' and cc.find_library('libc++', required: false).found()
- cpp_arguments += [
- '-stdlib=libc++',
- ]
+if cc.get_id() == 'clang'
+ # Turn _FORTIFY_SOURCE by default on optimised builds (as it requires -O1
+ # or higher). This is needed on clang only as gcc enables it by default.
+ if get_option('optimization') != '0'
+ common_arguments += [
+ '-D_FORTIFY_SOURCE=2',
+ ]
+ endif
+
+ # Use libc++ by default if available instead of libstdc++ when compiling
+ # with clang.
+ if cc.find_library('libc++', required: false).found()
+ cpp_arguments += [
+ '-stdlib=libc++',
+ ]
+ endif
endif
add_project_arguments(c_arguments, language : 'c')