CMake: Remove duplicate sanitizer configuration

Root had identical copy of what was being done in Meta/Lagom
so now we ensure this is still included globally but is
isolated to its own cmake module to make sanitizer
config easier to discover
This commit is contained in:
ayeteadoe 2025-05-13 01:14:36 -07:00 committed by Andrew Kaster
commit 0061c64ee6
Notes: github-actions[bot] 2025-05-14 08:06:12 +00:00
4 changed files with 26 additions and 50 deletions

View file

@ -39,31 +39,6 @@ include(UI/cmake/EnableLagom.cmake)
include(lagom_options NO_POLICY_SCOPE) include(lagom_options NO_POLICY_SCOPE)
include(lagom_compile_options) include(lagom_compile_options)
if (ENABLE_ADDRESS_SANITIZER)
add_cxx_compile_options(-fsanitize=address -fno-omit-frame-pointer)
add_cxx_link_options(-fsanitize=address)
add_swift_compile_options(-sanitize=address)
add_swift_link_options(-sanitize=address)
endif()
if (ENABLE_MEMORY_SANITIZER)
add_cxx_compile_options(-fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer)
add_cxx_link_options(-fsanitize=memory -fsanitize-memory-track-origins)
endif()
if (ENABLE_UNDEFINED_SANITIZER AND (APPLE OR NOT ENABLE_SWIFT))
add_cxx_compile_options(-fsanitize=undefined -fno-omit-frame-pointer)
if (UNDEFINED_BEHAVIOR_IS_FATAL)
add_cxx_compile_options(-fno-sanitize-recover=undefined)
endif()
if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "17")
add_cxx_compile_options(-fno-sanitize=function)
endif()
add_cxx_link_options(-fsanitize=undefined)
add_swift_compile_options(-sanitize=undefined)
add_swift_link_options(-sanitize=undefined)
endif()
if (HAIKU) if (HAIKU)
# Haiku needs some extra compile definitions to make important stuff in its headers available. # Haiku needs some extra compile definitions to make important stuff in its headers available.
add_compile_definitions(_DEFAULT_SOURCE) add_compile_definitions(_DEFAULT_SOURCE)

View file

@ -140,3 +140,5 @@ endif()
if (NOT MSVC) if (NOT MSVC)
add_cxx_compile_options(-fstrict-flex-arrays=2) add_cxx_compile_options(-fstrict-flex-arrays=2)
endif() endif()
include(${CMAKE_CURRENT_LIST_DIR}/sanitizers.cmake)

View file

@ -0,0 +1,24 @@
if (ENABLE_ADDRESS_SANITIZER)
add_cxx_compile_options(-fsanitize=address -fno-omit-frame-pointer)
add_cxx_link_options(-fsanitize=address)
add_swift_compile_options(-sanitize=address)
add_swift_link_options(-sanitize=address)
endif()
if (ENABLE_MEMORY_SANITIZER)
add_cxx_compile_options(-fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer)
add_cxx_link_options(-fsanitize=memory -fsanitize-memory-track-origins)
endif()
if (ENABLE_UNDEFINED_SANITIZER AND (APPLE OR NOT ENABLE_SWIFT))
add_cxx_compile_options(-fsanitize=undefined -fno-omit-frame-pointer)
if (UNDEFINED_BEHAVIOR_IS_FATAL)
add_cxx_compile_options(-fno-sanitize-recover=undefined)
endif()
if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "17")
add_cxx_compile_options(-fno-sanitize=function)
endif()
add_cxx_link_options(-fsanitize=undefined)
add_swift_compile_options(-sanitize=undefined)
add_swift_link_options(-sanitize=undefined)
endif()

View file

@ -89,31 +89,6 @@ if (EMSCRIPTEN)
add_cxx_link_options(--emrun "SHELL:-s ALLOW_MEMORY_GROWTH") add_cxx_link_options(--emrun "SHELL:-s ALLOW_MEMORY_GROWTH")
endif() endif()
if (ENABLE_ADDRESS_SANITIZER)
add_cxx_compile_options(-fsanitize=address -fno-omit-frame-pointer)
add_cxx_link_options(-fsanitize=address)
add_swift_compile_options(-sanitize=address)
add_swift_link_options(-sanitize=address)
endif()
if (ENABLE_MEMORY_SANITIZER)
add_cxx_compile_options(-fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer)
add_cxx_link_options(-fsanitize=memory -fsanitize-memory-track-origins)
endif()
if (ENABLE_UNDEFINED_SANITIZER AND (APPLE OR NOT ENABLE_SWIFT))
add_cxx_compile_options(-fsanitize=undefined -fno-omit-frame-pointer)
if (UNDEFINED_BEHAVIOR_IS_FATAL)
add_cxx_compile_options(-fno-sanitize-recover=undefined)
endif()
if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "17")
add_cxx_compile_options(-fno-sanitize=function)
endif()
add_cxx_link_options(-fsanitize=undefined)
add_swift_compile_options(-sanitize=undefined)
add_swift_link_options(-sanitize=undefined)
endif()
if (ENABLE_COMPILETIME_FORMAT_CHECK) if (ENABLE_COMPILETIME_FORMAT_CHECK)
add_compile_definitions(ENABLE_COMPILETIME_FORMAT_CHECK) add_compile_definitions(ENABLE_COMPILETIME_FORMAT_CHECK)
endif() endif()