coverage: build with -O0 to get more information
per the gcov man page:
You should compile your code without optimization if you plan to use
gcov because the optimization, by combining some lines of code into one
function, may not give you as much information .
Fixes #5548
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 84deadf..e5dbc3f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -67,8 +67,13 @@
zephyr_compile_definitions(
KERNEL
__ZEPHYR__=1
+)
+
+if(NOT CONFIG_COVERAGE)
+zephyr_compile_definitions(
_FORTIFY_SOURCE=2
)
+endif()
# We need to set an optimization level.
# Default to -Os
@@ -79,10 +84,13 @@
#
# Finally, the user can use Kconfig to add compiler options that will
# come after these options and override them
-set_ifndef(OPTIMIZE_FOR_SIZE_FLAG "-Os")
-set_ifndef(OPTIMIZE_FOR_DEBUG_FLAG "-Og")
+set_ifndef(OPTIMIZE_FOR_SIZE_FLAG "-Os")
+set_ifndef(OPTIMIZE_FOR_DEBUG_FLAG "-Og")
+set_ifndef(OPTIMIZE_FOR_COVERAGE_FLAG "-O0")
if(CONFIG_DEBUG)
set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_DEBUG_FLAG})
+elseif(CONFIG_COVERAGE)
+ set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_COVERAGE_FLAG})
else()
set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_SIZE_FLAG}) # Default
endif()