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_options(-fsanitize=address)
51 add_link_options(-lasan)
55 if(undefined IN_LIST ENABLE_SANITIZERS OR ubsan IN_LIST ENABLE_SANITIZERS)
56 cmake_push_check_state(RESET)
57 set(CMAKE_REQUIRED_LIBRARIES ubsan)
58 check_cxx_compiler_flag(-fsanitize=undefined HAVE_UBSAN)
59 cmake_pop_check_state()
61 add_compile_options(-fsanitize=undefined)
62 add_link_options(-lubsan)
67 add_definitions(-DDEBUG=0)