From f4f22d5e235cc6f95b89e65b2f0c37cc71e2f4ea Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Thu, 6 Jun 2024 17:11:25 +0100 Subject: [PATCH] meson: add support for llvm-style code coverage Signed-off-by: Yuxuan Shui --- .gitignore | 1 + meson.build | 9 +++++++++ meson_options.txt | 7 +++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index edef7ce0f0..e870f6ef6f 100644 --- a/.gitignore +++ b/.gitignore @@ -72,6 +72,7 @@ doxygen/ *.orig /tests/log /tests/testcases/__pycache__/ +*.profraw # Subproject files subprojects/libconfig diff --git a/meson.build b/meson.build index 408900e2b7..6bdd4eda57 100644 --- a/meson.build +++ b/meson.build @@ -36,6 +36,15 @@ if get_option('sanitize') endif endif +if get_option('llvm_coverage') + if cc.get_id() != 'clang' + error('option \'llvm_coverage\' requires clang') + endif + coverage_flags = ['-fprofile-instr-generate', '-fcoverage-mapping'] + add_global_arguments(coverage_flags, language: 'c') + add_global_link_arguments(coverage_flags, language: 'c') +endif + if get_option('modularize') if not cc.has_argument('-fmodules') error('option \'modularize\' requires clang') diff --git a/meson_options.txt b/meson_options.txt index ead0e8ec03..e54a901332 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -12,6 +12,9 @@ option('compton', type: 'boolean', value: true, description: 'Install backwards option('with_docs', type: 'boolean', value: false, description: 'Build documentation and man pages') -option('modularize', type: 'boolean', value: false, description: 'Build with clang\'s module system') - option('unittest', type: 'boolean', value: false, description: 'Enable unittests in the code') + +# Experimental options + +option('modularize', type: 'boolean', value: false, description: 'Build with clang\'s module system (experimental)') +option('llvm_coverage', type: 'boolean', value: false, description: 'Use LLVM source-based code coverage, instead of --coverage. Do not use with b_coverage.')