if(NOT EVO_SANITIZER MATCHES "^(none|address|thread)$") message(FATAL_ERROR "Unsupported EVO_SANITIZER=${EVO_SANITIZER}") endif() if(EVO_ENABLE_TIDY) if(NOT CMAKE_GENERATOR MATCHES "Ninja|Makefiles") message(FATAL_ERROR "Use Ninja or Makefiles for clang-tidy compilation") endif() find_program(EVO_CLANG_TIDY NAMES clang-tidy-19 clang-tidy REQUIRED) execute_process(COMMAND "${EVO_CLANG_TIDY}" --version OUTPUT_VARIABLE tidy_version) if(NOT tidy_version MATCHES "version 19\\.") message(FATAL_ERROR "Analysis baseline requires clang-tidy major 19") endif() endif() if(MSVC AND EVO_SANITIZER STREQUAL "address") # MSVC runtime checks are incompatible with AddressSanitizer. string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") endif() if(MSVC AND EVO_SANITIZER STREQUAL "thread") message(FATAL_ERROR "MSVC does not provide TSan; use the dedicated Linux preset/job") endif() function(evo_owned_target target) if(MSVC) target_compile_options(${target} PRIVATE /W4 /permissive- /Zc:__cplusplus /utf-8 /fp:strict) if(EVO_WARNINGS_AS_ERRORS) target_compile_options(${target} PRIVATE /WX) endif() if(EVO_SANITIZER STREQUAL "address") target_compile_options(${target} PRIVATE /fsanitize=address) target_link_options(${target} PRIVATE /INCREMENTAL:NO) endif() elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic -Wconversion -Wshadow -fno-fast-math) if(EVO_WARNINGS_AS_ERRORS) target_compile_options(${target} PRIVATE -Werror) endif() if(EVO_SANITIZER STREQUAL "address") target_compile_options(${target} PRIVATE -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize-recover=all) target_link_options(${target} PRIVATE -fsanitize=address,undefined -fno-sanitize-recover=all) elseif(EVO_SANITIZER STREQUAL "thread") target_compile_options(${target} PRIVATE -fsanitize=thread -fno-omit-frame-pointer) target_link_options(${target} PRIVATE -fsanitize=thread) endif() else() message(FATAL_ERROR "Unsupported compiler; add a documented/tested toolchain") endif() if(EVO_ENABLE_TIDY) set(tidy_command "${EVO_CLANG_TIDY};--warnings-as-errors=*") if(MSVC) list(APPEND tidy_command "--extra-arg=/EHsc") endif() set_property(TARGET ${target} PROPERTY CXX_CLANG_TIDY "${tidy_command}") endif() endfunction()