diff --git a/cmake/ToywasmConfig.cmake b/cmake/ToywasmConfig.cmake index bb0f09b2..399fe077 100644 --- a/cmake/ToywasmConfig.cmake +++ b/cmake/ToywasmConfig.cmake @@ -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) @@ -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) @@ -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") @@ -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)