tests: Add code coverage

We want to be able to measure code coverage for our test cases. This
patch adds initial support for measuring the coverage of all of the
files in the repo when running the test cases.

Simply run:
    `make check-code-coverage`
and an lcov report will be generated

NOTE: This doesn't yet add any filtering to throw out the results for
system headers and tests cases, but the list of results isn't long so it
is easy to see the relevant coverage results and we don't want to add
any false negatives.

Tested:
    Sdbuplus plus still builds fine without the code coverage utilities
    by default. sdbusplus now builds with `./configure
    --enable-code-coverage` and corrects the libs and cflags accordingly
    to enable coverage. Make then succeeds to generate a report when run
    with `make check-code-coverage`

Change-Id: I7f640b82e771bc9043abf381d14393be54c3e672
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/configure.ac b/configure.ac
index 217e200..a959d31 100644
--- a/configure.ac
+++ b/configure.ac
@@ -7,6 +7,18 @@
 AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror foreign dist-xz])
 AM_SILENT_RULES([yes])
 
+# Make sure the default CFLAGS of `-O2 -g` don't override CODE_COVERAGE_CFLAGS
+# It is important that this comes before AC_PROG_C{C,XX}, as we are attempting
+# to stop them from populating default CFLAGS and CXXFLAGS.
+AS_IF([test "x$enable_code_coverage" != "xno"], [
+    AS_IF([test "x${CXXFLAGS+set}" != "xset"], [
+        AC_SUBST(CXXFLAGS, [""])
+    ])
+    AS_IF([test "x${CFLAGS+set}" != "xset"], [
+        AC_SUBST(CFLAGS, [""])
+    ])
+])
+
 # Checks for programs.
 AC_PROG_CXX
 AC_PROG_CC
@@ -115,6 +127,10 @@
     AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
 ])
 
+# Code coverage
+AX_CODE_COVERAGE
+AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage])
+
 AC_ARG_ENABLE([oe-sdk],
     AS_HELP_STRING([--enable-oe-sdk], [Link testcases absolutely against OE SDK so they can be ran within it.])
 )