3 # Add code coverage support with gcov/lcov.
9 # Provides a --enable-coverage option which checks for available
10 # gcov/lcov binaries and provides ENABLE_CODE_COVERAGE conditional.
14 # $Id: coverage.m4 40881 2013-08-20 17:54:39Z damon $
18 # Copyright (c) 2012 Roy H. Stogner <roystgnr@ices.utexas.edu>
19 # Copyright (c) 2010 Karl W. Schulz <karl@ices.utexas.edu>
21 # Copying and distribution of this file, with or without modification, are
22 # permitted in any medium without royalty provided the copyright notice
23 # and this notice are preserved.
25 AC_DEFUN([AX_CODE_COVERAGE],
28 AC_ARG_ENABLE(coverage, AC_HELP_STRING([--enable-coverage],[configure code coverage analysis tools]))
34 if test "x$enable_coverage" = "xyes"; then
36 # ----------------------------
37 # Check for gcov/lcov binaries
38 # ----------------------------
40 AC_ARG_VAR([GCOV], [Coverage testing command])
41 if test "x$GCOV" = "x"; then
42 AC_PATH_PROG(GCOV, gcov, no)
44 AC_PATH_PROG(GCOV, $GCOV, no)
47 AC_PATH_PROG(LCOV, lcov, no)
48 AC_PATH_PROG(GENHTML, genhtml)
50 # ----------------------------------
51 # include coverage compiler options
52 # ----------------------------------
53 AC_MSG_CHECKING([for clang])
56 [AC_LANG_PROGRAM([], [[
61 [CLANG=yes], [CLANG=no])
63 AC_MSG_RESULT([$CLANG])
65 COVERAGE_CFLAGS="-fprofile-arcs -ftest-coverage"
66 COVERAGE_LDFLAGS="--coverage -fprofile-arcs -ftest-coverage"
67 COVERAGE_OPTFLAGS="-O0"
70 CFLAGS="${GCOV_FLAGS} ${CFLAGS}"
71 CXXFLAGS="${GCOV_FLAGS} ${CXXFLAGS}"
72 if test "x$GCC" = "xyes" -a "x$CLANG" = "xno"; then
73 COVERAGE_LIBS="-lgcov"
82 AC_SUBST([GENHTML_OPTIONS])
83 AC_SUBST([COVERAGE_CFLAGS])
84 AC_SUBST([COVERAGE_OPTFLAGS])
85 AC_SUBST([COVERAGE_LDFLAGS])
86 AC_SUBST([COVERAGE_LIBS])
87 AM_CONDITIONAL(CODE_COVERAGE_ENABLED,test x$HAVE_GCOV_TOOLS = x1)