Skip to content

Commit

Permalink
cmake: apply sanitizer flags only for debug
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Nov 23, 2023
1 parent 282df39 commit 6a07e40
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cmake/ToywasmConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ cmake_dependent_option(TOYWASM_ENABLE_DYLD_DLFCN
option(TOYWASM_BUILD_UNITTEST "Build toywasm-test" ON)

if(NOT DEFINED USE_LSAN)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(USE_LSAN ON)
else()
set(USE_LSAN OFF)
endif()
endif()
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
if(NOT BREW_CLANG)
Expand Down Expand Up @@ -284,7 +288,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wthread-safety")
endif()

if(NOT DEFINED USE_UBSAN)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND CMAKE_BUILD_TYPE MATCHES "Debug")
set(USE_UBSAN ON)
else()
set(USE_UBSAN OFF)
Expand All @@ -308,7 +312,11 @@ list(APPEND SANITIZER_FLAGS "-fno-sanitize=pointer-overflow")
endif()

if(NOT DEFINED USE_ASAN)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(USE_ASAN ON)
else()
set(USE_ASAN OFF)
endif()
endif()
if(USE_ASAN)
list(APPEND SANITIZER_FLAGS "-fsanitize=address")
Expand All @@ -322,7 +330,7 @@ set(ASAN_DETECT_LEAKS 0)
endif()

list(JOIN SANITIZER_FLAGS " " SANITIZER_FLAGS_STR)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${SANITIZER_FLAGS_STR}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_FLAGS_STR}")

if(NOT DEFINED USE_IPO)
check_ipo_supported(RESULT HAVE_IPO)
Expand Down

0 comments on commit 6a07e40

Please sign in to comment.