# AddressSanitizer / UndefinedBehaviorSanitizer wiring. # Enabled per build via -DPDFENGINE_ENABLE_SANITIZERS=ON (see the *-asan presets). # Usage: pdfengine_enable_sanitizers() # # Coverage by platform: # MSVC -> ASan only (/fsanitize=address). UBSan/TSan unsupported. # GCC/Clang -> ASan + UBSan. # TSan is intentionally not wired here yet; it conflicts with ASan and is only # relevant once the engine is multithreaded (Phase 3+). 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()