X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=CMake%2FCheckDebug.cmake;h=32fbf26d1ddb1dcd7caf576d4a2fdb13a487e164;hb=8e4d46a24fcb064e30edd886e703d21895b3708a;hp=cc91da979171d09e23d5f375ecf7445808c00e13;hpb=b3a0a9fcac5ae592a4e74b734f27dc11533d3907;p=awesomized%2Flibmemcached diff --git a/CMake/CheckDebug.cmake b/CMake/CheckDebug.cmake index cc91da97..32fbf26d 100644 --- a/CMake/CheckDebug.cmake +++ b/CMake/CheckDebug.cmake @@ -1,9 +1,21 @@ 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) + check_flag(-Og -O0) + check_flag(-ggdb -g) add_definitions(-DDEBUG=1) foreach(FLAG IN ITEMS -fno-inline @@ -11,8 +23,6 @@ function(check_debug) -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) @@ -42,8 +47,10 @@ function(check_debug) check_cxx_compiler_flag(-fsanitize=address HAVE_ASAN) cmake_pop_check_state() if(HAVE_ASAN) + add_compile_definitions(HAVE_ASAN) add_compile_options(-fsanitize=address) - add_link_options(-lasan) + link_libraries(-fsanitize=address) + check_flag(-fsanitize-recover=address IGNORE) endif() endif() @@ -53,8 +60,10 @@ function(check_debug) check_cxx_compiler_flag(-fsanitize=undefined HAVE_UBSAN) cmake_pop_check_state() if(HAVE_UBSAN) + add_compile_definitions(HAVE_UBSAN) add_compile_options(-fsanitize=undefined) - add_link_options(-lubsan) + link_libraries(-fsanitize=undefined) + check_flag(-fsanitize-recover=undefined IGNORE) endif() endif() endif()