2026-05-15 10:39:16 +05:30
|
|
|
# AddressSanitizer / UndefinedBehaviorSanitizer wiring.
|
2026-05-16 11:01:20 +05:30
|
|
|
# Enabled per build via -DPDFENGINE_ENABLE_SANITIZERS=ON
|
2026-05-15 10:39:16 +05:30
|
|
|
# Usage: pdfengine_enable_sanitizers(<target>)
|
|
|
|
|
|
|
|
|
|
function(pdfengine_enable_sanitizers target)
|
|
|
|
|
if(NOT PDFENGINE_ENABLE_SANITIZERS)
|
|
|
|
|
return()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(MSVC)
|
|
|
|
|
message(STATUS "Sanitizers: AddressSanitizer enabled for '${target}' (MSVC)")
|
|
|
|
|
target_compile_options(${target} PRIVATE /fsanitize=address)
|
|
|
|
|
# ASan on MSVC is incompatible with the /RTC runtime checks and incremental link.
|
|
|
|
|
target_compile_options(${target} PRIVATE /Zi)
|
|
|
|
|
target_link_options(${target} PRIVATE /INCREMENTAL:NO)
|
|
|
|
|
else()
|
|
|
|
|
message(STATUS "Sanitizers: Address + UndefinedBehavior enabled for '${target}'")
|
|
|
|
|
set(_flags -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize-recover=all)
|
|
|
|
|
target_compile_options(${target} PRIVATE ${_flags} -g)
|
|
|
|
|
target_link_options(${target} PRIVATE ${_flags})
|
|
|
|
|
endif()
|
|
|
|
|
endfunction()
|