Debian Codegraph @

CMakeSanitize

raw
1 set(BUILD_NAME "Sanitize")
2 string(TOUPPER "${BUILD_NAME}" BUILD_NAME_U)
3
4 set(BASE_BUILD_NAME "RelWithDebInfo")
5 string(TOUPPER "${BASE_BUILD_NAME}" BASE_BUILD_NAME_U)
6
7 if(CMAKE_CONFIGURATION_TYPES)
8 list(APPEND CMAKE_CONFIGURATION_TYPES "${BUILD_NAME}")
9 list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
10 set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
11 "Add the configurations that we need"
12 FORCE)
13 endif()
14
15 set("CMAKE_CXX_FLAGS_${BUILD_NAME_U}" "${CMAKE_CXX_FLAGS_${BASE_BUILD_NAME_U}} ${COMPILER_FLAGS}" CACHE STRING
16 "Flags used by the C++ compiler during ${BUILD_NAME} builds."
17 FORCE)
18 set("CMAKE_C_FLAGS_${BUILD_NAME_U}" "${CMAKE_C_FLAGS_${BASE_BUILD_NAME_U}} ${COMPILER_FLAGS}" CACHE STRING
19 "Flags used by the C compiler during ${BUILD_NAME} builds."
20 FORCE)
21 set("CMAKE_EXE_LINKER_FLAGS_${BUILD_NAME_U}" "${CMAKE_EXE_LINKER_FLAGS_${BASE_BUILD_NAME_U}} ${LINKER_FLAGS}" CACHE STRING
22 "Flags used for linking binaries during ${BUILD_NAME} builds."
23 FORCE)
24 set("CMAKE_SHARED_LINKER_FLAGS_${BUILD_NAME_U}" "${CMAKE_SHARED_LINKER_FLAGS_${BASE_BUILD_NAME_U}} ${LINKER_FLAGS}" CACHE STRING
25 "Flags used by the shared libraries linker during ${BUILD_NAME} builds."
26 FORCE)
27
28 mark_as_advanced(
29 "${CMAKE_CXX_FLAGS_${BUILD_NAME_U}}"
30 "${CMAKE_C_FLAGS_${BUILD_NAME_U}}"
31 "${CMAKE_EXE_LINKER_FLAGS_${BUILD_NAME_U}}"
32 "${CMAKE_SHARED_LINKER_FLAGS_${BUILD_NAME_U}}")
33
34 # Update the documentation string of CMAKE_BUILD_TYPE for GUIs
35 set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
36 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel ${BUILD_NAME}."
37 FORCE)
38
39 if (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
40 target_compile_options(libdivide INTERFACE "$<$<CONFIG:${BUILD_NAME}>:/fsanitize=address;/MTd>")
41 target_link_options(libdivide INTERFACE "$<$<CONFIG:${BUILD_NAME}>:/INCREMENTAL:NO>")
42 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
43 if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") # clang-cl
44 target_compile_options(libdivide INTERFACE "$<$<CONFIG:${BUILD_NAME}>:/fsanitize=address>")
45 target_link_libraries(libdivide INTERFACE "$<$<CONFIG:${BUILD_NAME}>:clang_rt.asan_dynamic-x86_64.lib;clang_rt.asan_dynamic_runtime_thunk-x86_64.lib>")
46 else() # clang native
47 target_compile_options(libdivide INTERFACE "$<$<CONFIG:${BUILD_NAME}>:-fsanitize=address;-fsanitize=undefined;-fno-sanitize-recover=all;-fno-omit-frame-pointer;-U_DLL;-U_MT;-DDEBUG;-O1;-g>")
48 target_link_options(libdivide INTERFACE "$<$<CONFIG:${BUILD_NAME}>:-fsanitize=address>")
49 endif()
50 elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
51 target_compile_options(libdivide INTERFACE "$<$<CONFIG:${BUILD_NAME}>:-fsanitize=address;-fsanitize=undefined;-fno-sanitize-recover=all;-fno-omit-frame-pointer;-DDEBUG;-O1;-g>")
52 target_link_options(libdivide INTERFACE "$<$<CONFIG:${BUILD_NAME}>:-fsanitize=address;-fsanitize=undefined>")
53 endif()