X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=CMake%2FCheckDebug.cmake;h=e3e046bf8c7be78accb56c79c458c294f4d84bbf;hb=9c59f89a7fc736cd26a2d271ac56afd37c42237b;hp=cc91da979171d09e23d5f375ecf7445808c00e13;hpb=911c5ad81ebd8ff9a72cfbb5bc1e2a7b49ee3f92;p=awesomized%2Flibmemcached diff --git a/CMake/CheckDebug.cmake b/CMake/CheckDebug.cmake index cc91da97..e3e046bf 100644 --- a/CMake/CheckDebug.cmake +++ b/CMake/CheckDebug.cmake @@ -1,60 +1,74 @@ 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_definitions(-DDEBUG=1) - foreach(FLAG IN ITEMS - -fno-inline - -fno-omit-frame-pointer - -fno-eliminate-unused-debug-types - -funsafe-loop-optimizations + if(CMAKE_CXX_FLAGS MATCHES --coverage) + message("-- Coverage build detected!") + message("-- Skipping debug and sanitizer flag checks.") + else() + check_flag(-Og -O0) + check_flag(-ggdb -g) + foreach(FLAG IN ITEMS + -fno-inline + -fno-omit-frame-pointer + -fno-eliminate-unused-debug-types + -funsafe-loop-optimizations - -g3 + -Wall + -Wextra - -Wall - -Wextra + -Wdouble-promotion + -Wduplicated-cond + -Wduplicated-branches + -Wformat=2 + -Wlogical-op + -Wnull-dereference + -Wrestrict + -Wshadow + -Wunknown-pragmas + -Wunsafe-loop-optimizations + ) + check_flag(${FLAG} IGNORE) + endforeach() - -Wdouble-promotion - -Wduplicated-cond - -Wduplicated-branches - -Wformat=2 - -Wlogical-op - -Wnull-dereference - -Wrestrict - -Wshadow - -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() - endforeach() - - if(ENABLE_SANITIZERS) - if(address IN_LIST ENABLE_SANITIZERS OR asan IN_LIST ENABLE_SANITIZERS) - cmake_push_check_state(RESET) - set(CMAKE_REQUIRED_LIBRARIES asan) - check_cxx_compiler_flag(-fsanitize=address HAVE_ASAN) - cmake_pop_check_state() - if(HAVE_ASAN) - add_compile_options(-fsanitize=address) - add_link_options(-lasan) + if(ENABLE_SANITIZERS) + if(address IN_LIST ENABLE_SANITIZERS OR asan IN_LIST ENABLE_SANITIZERS) + cmake_push_check_state(RESET) + set(CMAKE_REQUIRED_LIBRARIES asan) + 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) + link_libraries(-fsanitize=address) + check_flag(-fsanitize-recover=address IGNORE) + endif() endif() - endif() - if(undefined IN_LIST ENABLE_SANITIZERS OR ubsan IN_LIST ENABLE_SANITIZERS) - cmake_push_check_state(RESET) - set(CMAKE_REQUIRED_LIBRARIES ubsan) - check_cxx_compiler_flag(-fsanitize=undefined HAVE_UBSAN) - cmake_pop_check_state() - if(HAVE_UBSAN) - add_compile_options(-fsanitize=undefined) - add_link_options(-lubsan) + if(undefined IN_LIST ENABLE_SANITIZERS OR ubsan IN_LIST ENABLE_SANITIZERS) + cmake_push_check_state(RESET) + set(CMAKE_REQUIRED_LIBRARIES ubsan) + 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) + link_libraries(-fsanitize=undefined) + check_flag(-fsanitize-recover=undefined IGNORE) + endif() endif() endif() endif()