[host] cmake: add ubsan and asan to CMake (needs clang64 on windows)

Note that this still is a pain to make work as you require the MS
runtime DLLs, and to build with clang64.
This commit is contained in:
Geoffrey McRae 2022-01-09 17:47:55 +11:00
parent a391e271c3
commit c05282c38c

View File

@ -29,6 +29,12 @@ include(UninstallTarget)
option(ENABLE_BACKTRACE "Enable backtrace support on crash" ON)
add_feature_info(ENABLE_BACKTRACE ENABLE_BACKTRACE "Backtrace support.")
option(ENABLE_ASAN "Build with AddressSanitizer" OFF)
add_feature_info(ENABLE_ASAN ENABLE_ASAN "AddressSanitizer support.")
option(ENABLE_UBSAN "Build with UndefinedBehaviorSanitizer" OFF)
add_feature_info(ENABLE_UBSAN ENABLE_UBSAN "UndefinedBehaviorSanitizer support.")
add_compile_options(
"-Wall"
"-Werror"
@ -44,6 +50,16 @@ if(WIN32)
add_compile_options("-fdebug-prefix-map=${PROJECT_TOP}/=")
endif()
if(ENABLE_ASAN)
add_compile_options("-fno-omit-frame-pointer" "-fsanitize=address")
set(EXE_FLAGS "${EXE_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
endif()
if(ENABLE_UBSAN)
add_compile_options("-fsanitize=undefined")
set(EXE_FLAGS "${EXE_FLAGS} -fsanitize=undefined")
endif()
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/version.c
${CMAKE_BINARY_DIR}/include/version.h
@ -60,6 +76,12 @@ include_directories(
#link_libraries(
#)
if (ENABLE_ASAN OR ENABLE_UBSAN)
link_directories("c:/msys64/clang64/lib/clang/12.0.0/lib/windows")
link_libraries(clang_rt.asan_dynamic-x86_64 clang_rt.asan_dynamic_runtime_thunk-x86_64)
endif()
set(SOURCES
${CMAKE_BINARY_DIR}/version.c
src/app.c