enable ASAN explicitly (#61)
This commit is contained in:
parent
c5fc48a2b0
commit
292fc94956
@ -135,6 +135,8 @@ endif()
|
||||
|
||||
# Apply additional compile options if the build type is Debug
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
message(STATUS "Debug mode enabled")
|
||||
|
||||
target_compile_options(lvgl PRIVATE
|
||||
-pedantic-errors
|
||||
-Wall
|
||||
@ -161,36 +163,16 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
-Wstrict-aliasing
|
||||
)
|
||||
|
||||
# Check if the compiler supports sanitizers (e.g., leak, address, undefined)
|
||||
include(CheckCXXCompilerFlag)
|
||||
if (ASAN)
|
||||
message(STATUS "AddressSanitizer enabled")
|
||||
|
||||
check_cxx_compiler_flag("-fsanitize=leak" HAS_SANITIZE_LEAK)
|
||||
check_cxx_compiler_flag("-fsanitize=address" HAS_SANITIZE_ADDRESS)
|
||||
check_cxx_compiler_flag("-fsanitize=undefined" HAS_SANITIZE_UNDEFINED)
|
||||
|
||||
# Prepare the list of sanitizers
|
||||
set(SANITIZERS "")
|
||||
if (HAS_SANITIZE_ADDRESS)
|
||||
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})
|
||||
# Add AddressSanitizer flags
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
|
||||
else()
|
||||
message(STATUS "Sanitizers not enabled")
|
||||
message(STATUS "AddressSanitizer disabled")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user