Files
pdf/cmake/Sanitizers.cmake
T
Furqan-14 de4868ff49
CI / lint (push) Waiting to run
CI / build (macos-latest, macos-debug) (push) Blocked by required conditions
CI / build (ubuntu-latest, linux-debug) (push) Blocked by required conditions
CI / build (windows-latest, windows-debug) (push) Blocked by required conditions
Revert "Merge pull request 'saqib' (#5) from saqib into main"
This reverts commit a1e6b5910c, reversing
changes made to 43eba01201.
2026-05-21 11:52:27 +05:30

29 lines
1.3 KiB
CMake

# AddressSanitizer / UndefinedBehaviorSanitizer wiring.
# Enabled per build via -DPDFENGINE_ENABLE_SANITIZERS=ON (see the *-asan presets).
# Usage: pdfengine_enable_sanitizers(<target>)
#
# 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()