Files
repo-lens/cmake/sanitizers.cmake
T
wilmc 70c43b6a68
CI / build (debug, map[compiler:appleclang os:macos-latest]) (push) Canceled after 0s
CI / build (debug, map[compiler:clang os:ubuntu-latest]) (push) Canceled after 0s
CI / build (debug, map[compiler:gcc os:ubuntu-latest]) (push) Canceled after 0s
CI / build (debug, map[compiler:msvc os:windows-latest]) (push) Canceled after 0s
CI / build (release, map[compiler:appleclang os:macos-latest]) (push) Canceled after 0s
CI / build (release, map[compiler:clang os:ubuntu-latest]) (push) Canceled after 0s
CI / build (release, map[compiler:gcc os:ubuntu-latest]) (push) Canceled after 0s
CI / build (release, map[compiler:msvc os:windows-latest]) (push) Canceled after 0s
CI / build (sanitizers, map[compiler:appleclang os:macos-latest]) (push) Canceled after 0s
CI / build (sanitizers, map[compiler:clang os:ubuntu-latest]) (push) Canceled after 0s
CI / build (sanitizers, map[compiler:gcc os:ubuntu-latest]) (push) Canceled after 0s
CI / build (sanitizers, map[compiler:msvc os:windows-latest]) (push) Canceled after 0s
build: modernize repo-lens skeleton and cross-platform configuration
Replace CPM with FetchContent and update GoogleTest to v1.18.0.
Add compiler toolchains and Debug, Release, and sanitizer presets.
Require CMake 4.0, use target properties for compiler settings,
and enable compilation database export.

Fix skeleton compilation errors and adopt trailing return types,
nodiscard execute methods, and noexcept signatures. Update CI
and project documentation without implementing any TODOs.

Validated Windows builds and tests in all three configurations.
2026-10-09 12:36:31 +02:00

35 lines
1.6 KiB
CMake

include_guard()
include(CheckCXXSourceCompiles)
include(CMakePushCheckState)
function(target_enable_sanitizers _target)
if(MSVC)
set(_compile_options /fsanitize=address)
set(_link_options /INCREMENTAL:NO)
# Use the same settings for this target and the capability check.
set_property(TARGET ${_target} PROPERTY MSVC_RUNTIME_CHECKS "")
set_property(TARGET ${_target} PROPERTY MSVC_DEBUG_INFORMATION_FORMAT ProgramDatabase)
set(CMAKE_MSVC_RUNTIME_CHECKS "")
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT ProgramDatabase)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$")
set(_compile_options -fsanitize=address,undefined -fno-sanitize-recover=undefined -fno-omit-frame-pointer)
set(_link_options -fsanitize=address,undefined)
else()
message(FATAL_ERROR "Sanitizers are not configured for ${CMAKE_CXX_COMPILER_ID}")
endif()
cmake_push_check_state(RESET)
string(JOIN " " CMAKE_REQUIRED_FLAGS ${_compile_options})
set(CMAKE_REQUIRED_LINK_OPTIONS ${_link_options})
set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE)
check_cxx_source_compiles("int main() { return 0; }" REPO_LENS_SANITIZERS_SUPPORTED)
cmake_pop_check_state()
if(NOT REPO_LENS_SANITIZERS_SUPPORTED)
message(FATAL_ERROR "The requested sanitizer configuration cannot compile and link. Check compiler/runtime installation or configure with ENABLE_SANITIZERS=OFF.")
endif()
target_compile_options(${_target} PRIVATE ${_compile_options})
target_link_options(${_target} PRIVATE ${_link_options})
endfunction()