meson: Use -D_FORTIFY_SOURCE=2 on optimized builds

Some distribution enable _FORTIFY_SOURCE implicitly if user sets of -O1
greater in the CFLAGS, which may cause surprise compile failures.

Let's fortify explicitly and for everyone with default build, since the
checks provided are good.

Cc: Eero Tamminen <eero.t.tamminen@intel.com>
Signed-off-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Reviewed-by: Petri Latvala <petri.latvala@intel.com>
diff --git a/meson.build b/meson.build
index 503180e..a05e912 100644
--- a/meson.build
+++ b/meson.build
@@ -256,6 +256,13 @@
 add_project_arguments('-D_GNU_SOURCE', language : 'c')
 add_project_arguments('-include', 'config.h', language : 'c')
 
+# FEATURE_TEST_MACROS(7)
+# performs lightweight overflow checks on quite a few libc functions
+# requires -O optimizations
+if  ['debugoptimized', 'release', 'minsize'].contains(get_option('buildtype'))
+	add_project_arguments('-D_FORTIFY_SOURCE=2', language : 'c')
+endif
+
 config.set('PACKAGE_NAME', meson.project_name())
 config.set_quoted('PACKAGE_VERSION', meson.project_version())
 config.set_quoted('PACKAGE', meson.project_name())