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")
17 add_definitions(-DDEBUG=1)
18 if(CMAKE_CXX_FLAGS MATCHES --coverage)
19 message("-- Coverage build detected!")
20 message("-- Skipping debug and sanitizer flag checks.")
26 -fno-omit-frame-pointer
27 -fno-eliminate-unused-debug-types
28 -funsafe-loop-optimizations
42 -Wunsafe-loop-optimizations
44 check_flag(${FLAG} IGNORE)
48 if(address IN_LIST ENABLE_SANITIZERS OR asan IN_LIST ENABLE_SANITIZERS)
49 cmake_push_check_state(RESET)
50 set(CMAKE_REQUIRED_LIBRARIES asan)
51 check_cxx_compiler_flag(-fsanitize=address HAVE_ASAN)
52 cmake_pop_check_state()
54 add_compile_definitions(HAVE_ASAN)
55 add_compile_options(-fsanitize=address)
56 link_libraries(-fsanitize=address)
57 check_flag(-fsanitize-recover=address IGNORE)
61 if(undefined IN_LIST ENABLE_SANITIZERS OR ubsan IN_LIST ENABLE_SANITIZERS)
62 cmake_push_check_state(RESET)
63 set(CMAKE_REQUIRED_LIBRARIES ubsan)
64 check_cxx_compiler_flag(-fsanitize=undefined HAVE_UBSAN)
65 cmake_pop_check_state()
67 add_compile_definitions(HAVE_UBSAN)
68 add_compile_options(-fsanitize=undefined)
69 link_libraries(-fsanitize=undefined)
70 check_flag(-fsanitize-recover=undefined IGNORE)
76 add_definitions(-DDEBUG=0)