Enable code coverage for intel-ipmi-oem.

A code coverage report was generated successfully.

   Directory Sort by name Line Coverage Sort by line coverage Functions Sort by function coverage
   include
   20.6% 20.6%
   20.6 % 83 / 403 9.6 % 5 / 52
   src
   0.0%
   0.0 % 0 / 6332 0.0 % 0 / 329
   tests
   98.0% 98.0%
   98.0 % 243 / 248 100.0 % 8 / 8

Change-Id: I56ce4697fd129ce75b0efceb80c4552c4fa924a5
Signed-off-by: Rui Zhang <ruizhan@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6a7f843..12ad5bc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -134,3 +134,20 @@
     $<$<BOOL:${USING_ENTITY_MANAGER_DECORATORS}>:
     -DUSING_ENTITY_MANAGER_DECORATORS>
 )
+
+# Code Coverage
+if (NOT YOCTO)
+    # non-Debug build may generate misleading code coverage results.
+    set(CMAKE_BUILD_TYPE Debug)
+    message(WARNING "Using Debug build type!")
+    include(CodeCoverage)
+    APPEND_COVERAGE_COMPILER_FLAGS()
+    # check-code-coverage is a required name by
+    # openbmc-build-scripts/scripts/unit-test.py#L487.
+    SETUP_TARGET_FOR_COVERAGE_LCOV(
+        NAME check-code-coverage
+        EXECUTABLE runSensorTests
+        DEPENDENCIES runSensorTests
+        EXCLUDE "/usr/include/*" "/usr/local/include/*" "prefix/*"
+    )
+endif ()