Change the default debug compilation options. 57/14957/4
authorRomain Forlot <romain.forlot@iot.bzh>
Wed, 4 Jul 2018 10:22:33 +0000 (12:22 +0200)
committerRomain Forlot <romain.forlot@iot.bzh>
Wed, 4 Jul 2018 13:09:23 +0000 (15:09 +0200)
Because fortify source need optimization then the most
correct optimization to chose is -0g for debugging purpose.

Also be able to specify options for Clang which could differ
slightly from GNU.

Change-Id: I166c0cb62cbf9fc171cffc29c29df993f5ccb8f5
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
cmake/cmake.d/01-build_options.cmake

index 1f7bd9c..36830f1 100644 (file)
@@ -39,13 +39,36 @@ set(CMP0048 1)
 # Default compilation options
 ############################################################################
 link_libraries(-Wl,--as-needed -Wl,--gc-sections)
-set(COMPILE_OPTIONS -Wall -Wextra -Wconversion -Wno-unused-parameter -Wno-sign-compare -Wno-sign-conversion -Werror=maybe-uninitialized -Werror=implicit-function-declaration -ffunction-sections -fdata-sections -fPIC CACHE STRING "Compilation flags")
+set(COMPILE_OPTIONS -Wall
+ -Wextra
+ -Wconversion
+ -Wno-unused-parameter
+ -Wno-sign-compare
+ -Wno-sign-conversion
+ -Werror=implicit-function-declaration
+ -ffunction-sections
+ -fdata-sections
+ -fPIC CACHE STRING "Compilation flags")
+
+set(COMPILE_OPTIONS_GNU -Werror=maybe-uninitialized CACHE STRING "GNU Compile specific options")
+set(COMPILE_OPTIONS_CLANG -Werror=uninitialized CACHE STRING "CLang compile specific options")
 
 # Compilation OPTIONS depending on language
 #########################################
 foreach(option ${COMPILE_OPTIONS})
        add_compile_options(${option})
 endforeach()
+
+if (${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
+       foreach(option ${COMPILE_OPTIONS_GNU})
+               add_compile_options(${option})
+       endforeach()
+elseif(${CMAKE_C_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
+       foreach(option ${COMPILE_OPTIONS_CLANG})
+               add_compile_options(${option})
+       endforeach()
+endif()
+
 foreach(option ${C_COMPILE_OPTIONS})
        add_compile_options($<$<COMPILE_LANGUAGE:C>:${option}>)
 endforeach()
@@ -56,9 +79,9 @@ endforeach()
 # Compilation option depending on CMAKE_BUILD_TYPE
 ##################################################
 set(PROFILING_COMPILE_OPTIONS -g -O0 -pg -Wp,-U_FORTIFY_SOURCE CACHE STRING "Compilation flags for PROFILING build type.")
-set(DEBUG_COMPILE_OPTIONS -g -ggdb -D_FORTIFY_SOURCE=2 CACHE STRING "Compilation flags for DEBUG build type.")
-set(COVERAGE_COMPILE_OPTIONS -g -O2 --coverage CACHE STRING "Compilation flags for COVERAGE build type.")
-set(RELEASE_COMPILE_OPTIONS -g -O2 -D_FORTIFY_SOURCE=2 CACHE STRING "Compilation flags for RELEASE build type.")
+set(DEBUG_COMPILE_OPTIONS -g -ggdb -Og -D_FORTIFY_SOURCE=2 CACHE STRING "Compilation flags for DEBUG build type.")
+set(COVERAGE_COMPILE_OPTIONS -g --coverage CACHE STRING "Compilation flags for COVERAGE build type.")
+set(RELEASE_COMPILE_OPTIONS -O2 -D_FORTIFY_SOURCE=2 CACHE STRING "Compilation flags for RELEASE build type.")
 foreach(option ${PROFILING_COMPILE_OPTIONS})
        add_compile_options($<$<CONFIG:PROFILING>:${option}>)
 endforeach()