X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=CMake%2FCheckDebug.cmake;h=2701bdfd0ab3107c5cdf4b11364acb5b4eb93bff;hb=785f671d065aa12941a98fca384248ac5cd6e527;hp=749e188b975d638f4c9a252e6d3113178587cf4a;hpb=cbec7a4b9613b8ae3807539fae3a29ed8aff4984;p=m6w6%2Flibmemcached diff --git a/CMake/CheckDebug.cmake b/CMake/CheckDebug.cmake index 749e188b..2701bdfd 100644 --- a/CMake/CheckDebug.cmake +++ b/CMake/CheckDebug.cmake @@ -1,18 +1,28 @@ include(CMakePushCheckState) include(CheckCXXCompilerFlag) +function(check_flag FLAG DEFAULT) + unset(FLAG_CONSTANT) + string(MAKE_C_IDENTIFIER CXX${FLAG} FLAG_CONSTANT) + check_cxx_compiler_flag(${FLAG} ${FLAG_CONSTANT}) + if(${FLAG_CONSTANT}) + add_compile_options(${FLAG}) + elseif(DEFAULT) + add_compile_options(${DEFAULT}) + endif() +endfunction() + function(check_debug) if(CMAKE_BUILD_TYPE STREQUAL "Debug") - add_compile_options(-O1) - add_compile_definitions(DEBUG=1) + check_flag(-Og -O0) + check_flag(-ggdb -g) + add_definitions(-DDEBUG=1) foreach(FLAG IN ITEMS -fno-inline -fno-omit-frame-pointer -fno-eliminate-unused-debug-types -funsafe-loop-optimizations - -g3 - -Wall -Wextra @@ -27,12 +37,7 @@ function(check_debug) -Wunknown-pragmas -Wunsafe-loop-optimizations ) - unset(FLAG_CONSTANT) - string(MAKE_C_IDENTIFIER CXX${FLAG} FLAG_CONSTANT) - check_cxx_compiler_flag(${FLAG} ${FLAG_CONSTANT}) - if(${FLAG_CONSTANT}) - add_compile_options(${FLAG}) - endif() + check_flag(${FLAG} IGNORE) endforeach() if(ENABLE_SANITIZERS) @@ -59,6 +64,6 @@ function(check_debug) endif() endif() else() - add_compile_definitions(DEBUG=0) + add_definitions(-DDEBUG=0) endif() endfunction()