forked from NickNick/wubwubcmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory_sanitizer.cmake
19 lines (16 loc) · 951 Bytes
/
memory_sanitizer.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
include(${CMAKE_CURRENT_LIST_DIR}/flag_compiles.cmake)
option(USE_MSAN "Enable Memory Sanitizer, if your compiler supports it" OFF)
set(USE_MSAN_TRACK_ORIGINS 2 CACHE STRING "0 for no tracking, 1 for displaying origins and 2 for displaying origins and intermediate stores")
if(USE_MSAN)
set(flags "-fsanitize=memory -fsanitize-memory-track-origins=${USE_MSAN_TRACK_ORIGINS} -fno-omit-frame-pointer")
flag_compiles(FLAGS ${flags} WORKING_FLAG flag)
if(flag)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${flag}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${flag}")
else()
message(WARNING "Memory Sanitizer requested, but your compiler doesn't support it (could be other compilation flags, such as the address sanitizer)")
endif()
endif()