aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/cmake.d/01-build_options.cmake
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-07-04 12:22:33 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-07-04 15:09:23 +0200
commit291aa4ef053ba7564759d3a0ba3c027e1ede0eff (patch)
treee18bd4db06acb5e5834afa03ccaa25bb9592e467 /cmake/cmake.d/01-build_options.cmake
parent22a2cbfd2e36653c9de3b8a7a63e5f50f223419c (diff)
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 <romain.forlot@iot.bzh>
Diffstat (limited to 'cmake/cmake.d/01-build_options.cmake')
-rw-r--r--cmake/cmake.d/01-build_options.cmake31
1 files changed, 27 insertions, 4 deletions
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($<$<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()