From 9c8205a6bb366d3944e49379365b4848f56fc963 Mon Sep 17 00:00:00 2001 From: Fred Morcos Date: Tue, 8 Aug 2023 15:04:39 +0200 Subject: [PATCH] Meson: Use builtin feature to handle coverage --- meson.build | 3 +-- meson/code-coverage/meson.build | 21 +++++++++------------ meson_options.txt | 2 -- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/meson.build b/meson.build index e03adcbcde..31a8b09165 100644 --- a/meson.build +++ b/meson.build @@ -66,8 +66,7 @@ subdir('meson/gss-tsig') # GSS-TSIG subdir('meson/auth-tools') # Tools subdir('meson/ixfrdist') # Ixfrdist subdir('meson/systemd') # Systemd and unit file handling -# TODO Use meson's -Db_coverage option? -# subdir('meson/code-coverage') # Code coverage +subdir('meson/code-coverage') # Code coverage subdir('meson/auto-var-init') # Automatic Variable Initialization # TODO Use meson's -Db_sanitize option? # subdir('meson/sanitizers') # Sanitizers diff --git a/meson/code-coverage/meson.build b/meson/code-coverage/meson.build index bdfbe842fb..acbcb509b7 100644 --- a/meson/code-coverage/meson.build +++ b/meson/code-coverage/meson.build @@ -1,18 +1,15 @@ # Code coverage -code_coverage = get_option('code-coverage') +coverage = get_option('b_coverage') -if code_coverage - args = ['-U_FORTIFY_SOURCE', '-g', '-O0', '-fprofile-arcs', '-ftest-coverage'] +if coverage + if get_option('buildtype') != 'debug' + warning('Coverage is enabled, using `builtype=debug` would produce better reports') + endif - foreach arg: args - if not cxx.has_argument(arg) - error('Compiler does not support ' + arg + ', which is needed for code coverage') - break - endif - endforeach - - add_global_arguments(args, language: ['cpp']) + if cxx.has_argument('-U_FORTIFY_SOURCE') + add_global_arguments('-U_FORTIFY_SOURCE', language: ['c', 'cpp']) + endif endif -summary('Code Coverage', code_coverage, bool_yn: true, section: 'Configuration') +summary('Code Coverage', coverage, bool_yn: true, section: 'Configuration') diff --git a/meson_options.txt b/meson_options.txt index 09e295c45d..63de43de53 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -46,8 +46,6 @@ option('tools-ixfrdist', type: 'boolean', value: false, description: 'Build ixfr option('lua-records', type: 'boolean', value: true, description: 'Support Lua records') option('systemd-service-user', type: 'string', value: 'pdns', description: 'Systemd service user (setuid and unit file; user is not created)') option('systemd-service-group', type: 'string', value: 'pdns', description: 'Systemd service group (setgid and unit file; group is not created)') -# TODO Use meson's -Db_coverage option? -# option('code-coverage', type: 'boolean', value: false, description: 'Enable code coverage') option('auto-var-init', type: 'combo', value: 'disabled', choices: ['zero', 'pattern', 'disabled'], description: 'Enable initialization of automatic variables') # TODO Use meson's -Db_sanitize option? # option('sanitizer-address', type: 'boolean', value: false, description: 'Enable the Address Sanitizer') -- 2.47.2