CMake: Add ASAN and UBSAN (#116)

This commit is contained in:
Gleb Mazovetskiy 2023-10-31 10:17:06 +00:00 committed by GitHub
parent c138d7fb9d
commit f33143d0db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,12 +20,24 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
option(ASAN "Enable address sanitizer" OFF)
option(UBSAN "Enable undefined behaviour sanitizer" OFF)
if (ANDROID)
add_library(${EXECUTABLE_NAME} SHARED)
else()
add_executable(${EXECUTABLE_NAME} WIN32 MACOSX_BUNDLE)
endif()
if(ASAN)
target_compile_options(${EXECUTABLE_NAME} PUBLIC "-fsanitize=address;-fsanitize-recover=address")
target_link_options(${EXECUTABLE_NAME} PUBLIC "-fsanitize=address;-fsanitize-recover=address")
endif()
if(UBSAN)
target_compile_options(${EXECUTABLE_NAME} PUBLIC "-fsanitize=undefined")
target_link_options(${EXECUTABLE_NAME} PUBLIC "-fsanitize=undefined")
endif()
target_include_directories(${EXECUTABLE_NAME} PUBLIC src)
target_sources(${EXECUTABLE_NAME} PUBLIC