-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd56a47
commit 486f71d
Showing
2 changed files
with
12 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,31 @@ | ||
function(add_sanitizer_flags) | ||
if(NOT ENABLE_SANITIZE_ADDR AND NOT ENABLE_SANITIZE_UNDEF) | ||
function(add_sanitizer_flags enable_sanitize_addr enable_sanitize_undef) | ||
if (NOT enable_sanitize_addr AND NOT enable_sanitize_undef) | ||
message(STATUS "Sanitizers deactivated.") | ||
return() | ||
endif() | ||
|
||
if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU") | ||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") | ||
add_compile_options("-fno-omit-frame-pointer") | ||
add_link_options("-fno-omit-frame-pointer") | ||
|
||
if(ENABLE_SANITIZE_ADDR) | ||
if(enable_sanitize_addr) | ||
add_compile_options("-fsanitize=address") | ||
add_link_options("-fsanitize=address") | ||
endif() | ||
|
||
if(ENABLE_SANITIZE_UNDEF) | ||
if(enable_sanitize_undef) | ||
add_compile_options("-fsanitize=undefined") | ||
add_link_options("-fsanitize=undefined") | ||
endif() | ||
|
||
if(ENABLE_SANITIZE_LEAK) | ||
add_compile_options("-fsanitize=leak") | ||
add_link_options("-fsanitize=leak") | ||
endif() | ||
|
||
if(ENABLE_SANITIZE_THREAD) | ||
if(ENABLE_SANITIZE_ADDR OR ENABLE_SANITIZE_LEAK) | ||
message(WARNING "thread does not work with: address and leak") | ||
endif() | ||
add_compile_options("-fsanitize=thread") | ||
add_link_options("-fsanitize=thread") | ||
endif() | ||
elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC") | ||
if(ENABLE_SANITIZE_ADDR) | ||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") | ||
if(enable_sanitize_addr) | ||
add_compile_options("/fsanitize=address") | ||
endif() | ||
|
||
if(ENABLE_SANITIZE_UNDEF) | ||
message(STATUS "sanitize=undefined not avail. for MSVC") | ||
endif() | ||
|
||
if(ENABLE_SANITIZE_LEAK) | ||
message(STATUS "sanitize=leak not avail. for MSVC") | ||
endif() | ||
|
||
if(ENABLE_SANITIZE_THREAD) | ||
message(STATUS "sanitize=thread not avail. for MSVC") | ||
if(enable_sanitize_undef) | ||
message(STATUS "Undefined sanitizer not impl. for MSVC!") | ||
endif() | ||
else() | ||
message(WARNING "This sanitizer not supported in this environment") | ||
return() | ||
message(STATUS "Sanitizer not supported in this environment!") | ||
endif() | ||
endfunction(add_sanitizer_flags) |