blob: 7921db59c645b8c8e3f530ab7699bcc46ceff2d8 [file] [log] [blame]
Vasil Velichkov499510b2019-04-03 02:32:37 +03001AC_DEFUN([OSMO_AC_CODE_COVERAGE],[
2 dnl Check for --enable-code-coverage
3 AC_REQUIRE([OSMO_AX_CODE_COVERAGE])
4 AC_REQUIRE([AX_CHECK_COMPILE_FLAG])
5
6 AS_IF([ test "x$enable_code_coverage" = "xyes" ], [
7 # Check whether --coverage flags is supported and add it to CFLAGS
8 # When it is not supported add CODE_COVERAGE_CFLAGS to CFLAGS instead
9 AX_CHECK_COMPILE_FLAG([--coverage],
10 [CFLAGS="$CFLAGS -O0 -g --coverage"],
11 [CFLAGS="$CFLAGS $CODE_COVERAGE_CFLAGS"])
12
13 # Add both the absolute source and build directories to the coverage directories.
14 CODE_COVERAGE_DIRECTORY='$(abspath $(abs_top_srcdir)) $(abspath $(abs_top_builddir))'
15 AC_SUBST(CODE_COVERAGE_DIRECTORY)
16
17 # Enable branch coverage by default
18 CODE_COVERAGE_BRANCH_COVERAGE='1'
19 AC_SUBST(CODE_COVERAGE_BRANCH_COVERAGE)
20
21 # Exclude external files by default
22 CODE_COVERAGE_LCOV_OPTIONS='$(CODE_COVERAGE_LCOV_OPTIONS_DEFAULT) --no-external'
23 AC_SUBST(CODE_COVERAGE_LCOV_OPTIONS)
24
25 # Exclude tests sources from the coverage report
26 CODE_COVERAGE_IGNORE_PATTERN='"$(abspath $(abs_top_srcdir))/tests/*"'
27 AC_SUBST(CODE_COVERAGE_IGNORE_PATTERN)
28
29 # lcov_cobertura is needed only when you want to export the coverage report in
30 # the Cobertura's XML format supported by Jenkin's Cobertura plugin
31 AC_CHECK_PROG([LCOV_COBERTURA], [lcov_cobertura], [lcov_cobertura])
32 AS_IF([test "x$LCOV_COBERTURA" != "xno"], [m4_pattern_allow([AM_V_GEN]) CODE_COVERAGE_RULES+='
33coverage-cobertura.xml: $(CODE_COVERAGE_OUTPUT_FILE)
34 $(AM_V_GEN)$(LCOV_COBERTURA) -b $(top_srcdir) -o $$@@ $(CODE_COVERAGE_OUTPUT_FILE)
35
36.PHONY: code-coverage-cobertura
37code-coverage-cobertura: code-coverage-capture coverage-cobertura.xml
38'
39 ], [CODE_COVERAGE_RULES+='
40.PHONY: code-coverage-cobertura
41code-coverage-cobertura:
42 @echo "Need to install lcov_cobertura"
43'
44 ])
45 ], [CODE_COVERAGE_RULES+='
46.PHONY: code-coverage-cobertura
47code-coverage-cobertura:
48 @echo "Need to and reconfigure with --enable-code-coverage"
49'
50 ])
51])