From 5778fa9c36d9dcf851fa268b20eec4358ae1787a Mon Sep 17 00:00:00 2001
From: Steve Bennett <steveb@workware.net.au>
Date: Sat, 18 Apr 2020 07:32:04 +1000
Subject: build: Improve coverage support

Disable optimisation during coverage.

Set CCACHE_DISABLE=1 in the environment, just to be sure to disable ccache
Also cleanup coverage files in subdirs too

Add support for both lcov and gcovr

Signed-off-by: Steve Bennett <steveb@workware.net.au>
---
 auto.def | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

(limited to 'auto.def')

diff --git a/auto.def b/auto.def
index 7693e13..4a891de 100644
--- a/auto.def
+++ b/auto.def
@@ -103,13 +103,18 @@ if {[cctest -cflags -fno-asynchronous-unwind-tables]} {
 }
 if {[opt-bool coverage]} {
     if {[cctest -link 1 -cflags --coverage]} {
-        # Disable ccache when using coverage
+        # When using coverage, disable ccache and compiler optimisation
         define CCACHE ""
-        define-append CCOPTS --coverage
+        define-append CCOPTS --coverage -O0
         define-append LDFLAGS --coverage
         define COVERAGE 1
-        if {![cc-check-progs gcovr]} {
-            lappend warnings "Note: gcovr is not available, falling back to gcov"
+        if {[cc-check-progs gcovr]} {
+            define COVERAGE_TOOL gcovr
+        } elseif {[cc-check-progs lcov] && [cc-check-progs genhtml]} {
+            define COVERAGE_TOOL lcov
+        } else {
+            define COVERAGE_TOOL gcov
+            lappend warnings "Note: Neither lcov nor gcovr is available, falling back to gcov"
         }
     } else {
         lappend warnings "Warning: --coverage specified, but compiler does not support --coverage"
-- 
cgit v1.1

