From 291aa4ef053ba7564759d3a0ba3c027e1ede0eff Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Wed, 4 Jul 2018 12:22:33 +0200 Subject: Change the default debug compilation options. 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 --- cmake/cmake.d/01-build_options.cmake | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'cmake') diff --git a/cmake/cmake.d/01-build_options.cmake b/cmake/cmake.d/01-build_options.cmake index 1f7bd9c..36830f1 100644 --- a/cmake/cmake.d/01-build_options.cmake +++ b/cmake/cmake.d/01-build_options.cmake @@ -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($<$:${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($<$:${option}>) endforeach() -- cgit 1.2.3-korg