enable ASAN explicitly (#61)

This commit is contained in:
Gabor Kiss-Vamosi 2024-10-01 13:15:29 +02:00 committed by GitHub
parent c5fc48a2b0
commit 292fc94956
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -135,6 +135,8 @@ endif()
# Apply additional compile options if the build type is Debug # Apply additional compile options if the build type is Debug
if(CMAKE_BUILD_TYPE STREQUAL "Debug") if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Debug mode enabled")
target_compile_options(lvgl PRIVATE target_compile_options(lvgl PRIVATE
-pedantic-errors -pedantic-errors
-Wall -Wall
@ -161,36 +163,16 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
-Wstrict-aliasing -Wstrict-aliasing
) )
# Check if the compiler supports sanitizers (e.g., leak, address, undefined) if (ASAN)
include(CheckCXXCompilerFlag) message(STATUS "AddressSanitizer enabled")
check_cxx_compiler_flag("-fsanitize=leak" HAS_SANITIZE_LEAK) # Add AddressSanitizer flags
check_cxx_compiler_flag("-fsanitize=address" HAS_SANITIZE_ADDRESS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
check_cxx_compiler_flag("-fsanitize=undefined" HAS_SANITIZE_UNDEFINED) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
# Prepare the list of sanitizers set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
set(SANITIZERS "") else()
if (HAS_SANITIZE_ADDRESS) message(STATUS "AddressSanitizer disabled")
set(SANITIZERS "${SANITIZERS},address")
endif()
if (HAS_SANITIZE_UNDEFINED)
set(SANITIZERS "${SANITIZERS},undefined")
endif()
if (HAS_SANITIZE_LEAK)
set(SANITIZERS "${SANITIZERS},leak")
endif()
# Remove leading comma if there are any sanitizers
string(REGEX REPLACE "^," "" SANITIZERS "${SANITIZERS}")
# Add the sanitizers to the compile options if any are supported
if (SANITIZERS)
message(STATUS "Sanitizers enabled: ${SANITIZERS}")
target_compile_options(main PRIVATE -fsanitize=${SANITIZERS})
target_link_options(main PRIVATE -fsanitize=${SANITIZERS})
else()
message(STATUS "Sanitizers not enabled")
endif()
endif() endif()
endif()