diff --git a/cmake/modules/AddCompilerFlags.cmake b/cmake/modules/AddCompilerFlags.cmake --- a/cmake/modules/AddCompilerFlags.cmake +++ b/cmake/modules/AddCompilerFlags.cmake @@ -83,30 +83,28 @@ remove_cxx_compiler_flags(${ARGN}) endmacro() -function(add_cxx_compiler_flag_with_fallback TARGET_VAR FLAG FALLBACK) - # Remove the fallback flag if it exists, so that the main flag will override - # it if it was previously added. - remove_cxx_compiler_flags(${FALLBACK}) - - set(FLAG_CANDIDATE ${FLAG}) - check_compiler_flag(FLAG_IS_SUPPORTED CXX ${FLAG_CANDIDATE}) - if(NOT ${FLAG_IS_SUPPORTED}) - set(FLAG_CANDIDATE ${FALLBACK}) - endif() - - add_compiler_flags_to_var(${TARGET_VAR} CXX ${FLAG_CANDIDATE}) - set(${TARGET_VAR} ${${TARGET_VAR}} PARENT_SCOPE) -endfunction() - -function(add_compile_options_to_configuration CONFIGURATION) +function(add_compile_options_to_configuration_for_language CONFIGURATION LANGUAGE) foreach(f ${ARGN}) - check_compiler_flag(FLAG_IS_SUPPORTED CXX ${f}) + check_compiler_flag(FLAG_IS_SUPPORTED ${LANGUAGE} ${f}) if(${FLAG_IS_SUPPORTED}) - add_compile_options($<$:${f}>) + add_compile_options($<$,$>:${f}>) endif() endforeach() endfunction() +macro(add_c_compile_options_to_configuration CONFIGURATION) + add_compile_options_to_configuration_for_language(${CONFIGURATION} C ${ARGN}) +endmacro() + +macro(add_cxx_compile_options_to_configuration CONFIGURATION) + add_compile_options_to_configuration_for_language(${CONFIGURATION} CXX ${ARGN}) +endmacro() + +macro(add_compile_options_to_configuration CONFIGURATION) + add_c_compile_options_to_configuration(${CONFIGURATION} ${ARGN}) + add_cxx_compile_options_to_configuration(${CONFIGURATION} ${ARGN}) +endmacro() + function(add_compile_definitions_to_configuration CONFIGURATION) foreach(f ${ARGN}) add_compile_definitions($<$:${f}>) diff --git a/cmake/modules/OverrideInitFlags.cmake b/cmake/modules/OverrideInitFlags.cmake --- a/cmake/modules/OverrideInitFlags.cmake +++ b/cmake/modules/OverrideInitFlags.cmake @@ -4,7 +4,7 @@ # This mimics the autotools behavior by setting the CFLAGS to '-g -O2`, which # are not well suited for debugging. # FIXME: update CFLAGS with better debug oriented optimization flags -set(CMAKE_C_FLAGS_DEBUG_INIT "-g -O2") +set(CMAKE_C_FLAGS_DEBUG_INIT "-O2") set(CMAKE_C_FLAGS_MINSIZEREL_INIT "-Os") set(CMAKE_C_FLAGS_RELEASE_INIT "-O3") set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-g -O2") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,8 +42,16 @@ endif() include(AddCompilerFlags) + # Prefer -g3, defaults to -g if unavailable -add_cxx_compiler_flag_with_fallback(CMAKE_CXX_FLAGS_DEBUG -g3 -g) +foreach(LANGUAGE C CXX) + set(COMPILER_DEBUG_LEVEL -g) + check_compiler_flag(G3_IS_SUPPORTED ${LANGUAGE} -g3) + if(${G3_IS_SUPPORTED}) + set(COMPILER_DEBUG_LEVEL -g3) + endif() + add_compile_options_to_configuration_for_language(Debug ${LANGUAGE} ${COMPILER_DEBUG_LEVEL}) +endforeach() # Define the debugging symbols DEBUG and DEBUG_LOCKORDER when the Debug build # type is selected.