1 include(CMakePushCheckState)
2 include(CheckCXXCompilerFlag)
4 function(check_flag FLAG DEFAULT)
6 string(MAKE_C_IDENTIFIER CXX${FLAG} FLAG_CONSTANT)
7 check_cxx_compiler_flag(${FLAG} ${FLAG_CONSTANT})
9 add_compile_options(${FLAG})
11 add_compile_options(${DEFAULT})
16 if(CMAKE_BUILD_TYPE STREQUAL "Debug")
19 add_definitions(-DDEBUG=1)
22 -fno-omit-frame-pointer
23 -fno-eliminate-unused-debug-types
24 -funsafe-loop-optimizations
38 -Wunsafe-loop-optimizations
40 check_flag(${FLAG} IGNORE)
44 if(address IN_LIST ENABLE_SANITIZERS OR asan IN_LIST ENABLE_SANITIZERS)
45 cmake_push_check_state(RESET)
46 set(CMAKE_REQUIRED_LIBRARIES asan)
47 check_cxx_compiler_flag(-fsanitize=address HAVE_ASAN)
48 cmake_pop_check_state()
50 add_compile_definitions(HAVE_ASAN)
51 add_compile_options(-fsanitize=address)
52 add_link_options(-lasan)
53 check_flag(-fsanitize-recover=address IGNORE)
57 if(undefined IN_LIST ENABLE_SANITIZERS OR ubsan IN_LIST ENABLE_SANITIZERS)
58 cmake_push_check_state(RESET)
59 set(CMAKE_REQUIRED_LIBRARIES ubsan)
60 check_cxx_compiler_flag(-fsanitize=undefined HAVE_UBSAN)
61 cmake_pop_check_state()
63 add_compile_definitions(HAVE_UBSAN)
64 add_compile_options(-fsanitize=undefined)
65 add_link_options(-lubsan)
66 check_flag(-fsanitize-recover=undefined IGNORE)
71 add_definitions(-DDEBUG=0)