Build: Add macro for enabling code coverage flag

Add TFM_CODE_COVERAGE for GNU compiler to output more symbol info
by the parameter "-g".

The code coverage will be disabled by default.
Define TFM_CODE_COVERAGE=True to enable the code coverage flag when
build.

This is a preparation for code coverage analysis after the binary run.
And the code coverage report will rely on the symbol info for
calculating.

Change-Id: I4d5c8ebd7fd0777c49ab06cbdf1b9e2e2efb3d1e
Signed-off-by: Karl Zhang <karl.zhang@arm.com>
diff --git a/config/config_default.cmake b/config/config_default.cmake
index db8e70d..f7e633b 100644
--- a/config/config_default.cmake
+++ b/config/config_default.cmake
@@ -33,6 +33,8 @@
 
 set(TFM_INSTALL_PATH                    ${CMAKE_BINARY_DIR}/install CACHE PATH "Path to which to install TF-M files")
 
+set(TFM_CODE_COVERAGE                   OFF         CACHE BOOL      "Whether to build the binary for lcov tools by adding -g")
+
 ########################## BL2 #################################################
 
 set(MCUBOOT_IMAGE_NUMBER                2           CACHE STRING    "Whether to combine S and NS into either 1 image, or sign each seperately")
diff --git a/toolchain_GNUARM.cmake b/toolchain_GNUARM.cmake
index 716a2cc..92acbf9 100644
--- a/toolchain_GNUARM.cmake
+++ b/toolchain_GNUARM.cmake
@@ -43,6 +43,7 @@
         -mthumb
         -nostdlib
         -std=c99
+        $<$<BOOL:${TFM_CODE_COVERAGE}>:-g>
         $<$<NOT:$<BOOL:${TFM_SYSTEM_FP}>>:-msoft-float>
     )
 endmacro()