From 7dc5c9d8220f15f7f22c841d30d12f7d3741f418 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Wed, 1 Aug 2018 20:31:08 +0200 Subject: [PATCH] configure.ac: add option for gcov flags Gcov[1] is a tool to investigate test code coverage. To collect runtime statistics, certain compiler options must be set, i.e. -fprofile-arcs, -ftest-coverage, and --coverage. Currently, only the Gnu C Compiler is known to support the gcov instrumentation. This change adds the configure option --enable-gcov that checks if the compiler supports the aforementioned compiler flags and enables these. [1] https://gcc.gnu.org/onlinedocs/gcc/Gcov.html --- configure.ac | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/configure.ac b/configure.ac index fb2aa7c4..327ef2b2 100644 --- a/configure.ac +++ b/configure.ac @@ -504,6 +504,27 @@ AC_ARG_ENABLE([examples], AM_CONDITIONAL(BUILD_EXAMPLES, [test "x$build_examples" = "xyes"]) +# configure options +# __gcov__ +AC_ARG_ENABLE([gcov], + [AS_HELP_STRING([--enable-gcov], + [Enable building with gcov test coverage support [default=no]])], + [build_gcov="$enableval"], + [build_gcov="no" + AC_MSG_WARN([gcov is disabled]) + ]) + +if test "x$build_gcov" = "xyes"; then + if test "x$GCC" != "xyes"; then + AC_MSG_ERROR([Currently, gcov is assumed to work with GCC-compatible compilers only.]) + else + AX_CHECK_COMPILE_FLAG([-fprofile-arcs], [CFLAGS="$CFLAGS -fprofile-arcs"]) + AX_CHECK_COMPILE_FLAG([-ftest-coverage], [CFLAGS="$CFLAGS -ftest-coverage"]) + # FIXME: clang complains about '--coverage' + AX_CHECK_COMPILE_FLAG([--coverage], [CFLAGS="$CFLAGS --coverage -O0" LDFLAGS="$LDFLAGS --coverage"]) + fi +fi + # end configure options ####################### @@ -708,3 +729,8 @@ if test "x$build_examples" = "xyes"; then else AC_MSG_RESULT([ build examples : "no"]) fi +if test "x$build_gcov" = "xyes"; then + AC_MSG_RESULT([ build with gcov support : "yes"]) +else + AC_MSG_RESULT([ build with gcov support : "no"]) +fi