build: add compiler, reflection, and sanitizer capability probes (X-BASE-04)

This commit is contained in:
faumaray committed 2026-11-24 02:34:11 +03:00
1 parent cd6fc7e5f5
commit c64fa93373
3 files changed
+120

No files matched your search

+4
View File
@@ -11,6 +11,7 @@ option(VOID_ENABLE_TESTING "Build the test suite" ON)
option(VOID_WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF)
option(VOID_ENABLE_ASAN "Enable AddressSanitizer (Clang/GCC)" OFF)
option(VOID_ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (Clang/GCC)" OFF)
option(VOID_ENABLE_TSAN "Enable ThreadSanitizer (Clang/GCC)" OFF)
option(VOID_ENABLE_COVERAGE "Enable code coverage instrumentation" OFF)
set(CMAKE_CXX_STANDARD 26)
@@ -28,6 +29,8 @@ include(CMakePackageConfigHelpers)
set(EXPORT_SET_NAME ${PROJECT_NAME}Targets)
include(cmake/Capabilities.cmake)
void_probe_capabilities()
include(cmake/Module.cmake)
# Modules to configure, with the modules they need (INTERNAL_DEPS, followed
@@ -80,6 +83,7 @@ foreach(module_path ${children})
endif()
endforeach()
void_finalize_modules()
void_report_capabilities()
if(VOID_ENABLE_TESTING)
enable_testing()
+107
View File
@@ -0,0 +1,107 @@
include(CheckCXXSourceCompiles)
include(CMakePushCheckState)
function(_void_probe_sanitizer option_name compile_flags link_flag cache_var)
if(NOT ${option_name})
return()
endif()
if(MSVC)
message(FATAL_ERROR
"[Void] ${option_name}=ON is not supported with MSVC via this probe")
endif()
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_FLAGS "${compile_flags}")
set(CMAKE_REQUIRED_LINK_OPTIONS "${link_flag}")
check_cxx_source_compiles(
"int main() { int x = 0; return x; }\n"
${cache_var}
)
cmake_pop_check_state()
if(NOT ${cache_var})
message(FATAL_ERROR
"[Void] ${option_name}=ON requested, but ${CMAKE_CXX_COMPILER_ID} "
"${CMAKE_CXX_COMPILER_VERSION} failed to compile/link with '${link_flag}'.")
endif()
endfunction()
function(void_probe_capabilities)
if(VOID_ENABLE_ASAN AND VOID_ENABLE_TSAN)
message(FATAL_ERROR
"[Void] VOID_ENABLE_ASAN and VOID_ENABLE_TSAN are mutually exclusive")
endif()
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_FLAGS "-std=c++26")
check_cxx_source_compiles(
"#include <expected>\nint main() { std::expected<int, int> e{0}; return *e; }\n"
VOID_HAS_STD_EXPECTED
)
cmake_pop_check_state()
if(NOT VOID_HAS_STD_EXPECTED)
message(FATAL_ERROR
"[Void] Compiler/stdlib lacks C++23/26 <expected> support required by Void")
endif()
cmake_push_check_state(RESET)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16)
set(CMAKE_REQUIRED_FLAGS "-std=c++26 -freflection")
else()
set(CMAKE_REQUIRED_FLAGS "-std=c++26")
endif()
check_cxx_source_compiles(
"#include <meta>\nconsteval bool probe() { constexpr auto r = ^^int; return std::meta::is_type(r); }\nstatic_assert(probe());\nint main() { return 0; }\n"
VOID_HAS_CXX26_REFLECTION
)
cmake_pop_check_state()
_void_probe_sanitizer(VOID_ENABLE_ASAN
"-fsanitize=address -fno-omit-frame-pointer" "-fsanitize=address"
VOID_COMPILER_SUPPORTS_ASAN)
_void_probe_sanitizer(VOID_ENABLE_UBSAN
"-fsanitize=undefined" "-fsanitize=undefined"
VOID_COMPILER_SUPPORTS_UBSAN)
_void_probe_sanitizer(VOID_ENABLE_TSAN
"-fsanitize=thread" "-fsanitize=thread"
VOID_COMPILER_SUPPORTS_TSAN)
endfunction()
function(void_report_capabilities)
get_property(_mods GLOBAL PROPERTY VOID_MODULES)
list(LENGTH _mods _mod_count)
if(VOID_HAS_CXX26_REFLECTION)
set(_refl "yes")
else()
set(_refl "no")
endif()
if(VOID_HAS_STD_EXPECTED)
set(_exp "yes")
else()
set(_exp "no")
endif()
set(_sans "")
if(VOID_ENABLE_ASAN)
list(APPEND _sans "ASan")
endif()
if(VOID_ENABLE_UBSAN)
list(APPEND _sans "UBSan")
endif()
if(VOID_ENABLE_TSAN)
list(APPEND _sans "TSan")
endif()
if(NOT _sans)
set(_sans_str "none")
else()
string(REPLACE ";" "+" _sans_str "${_sans}")
endif()
message(STATUS
"[Void] Capabilities: compiler=${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}, "
"reflection=${_refl}, expected=${_exp}, shared=${BUILD_SHARED_LIBS}, "
"werror=${VOID_WARNINGS_AS_ERRORS}, sanitizers=${_sans_str}, modules=${_mod_count}")
endfunction()
+9
View File
@@ -192,6 +192,15 @@ function(void_add_module MODULE_NAME)
)
endif()
if(VOID_ENABLE_TSAN)
target_compile_options(${TGT} PUBLIC
"$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-fsanitize=thread>"
)
target_link_options(${TGT} PUBLIC
"$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-fsanitize=thread>"
)
endif()
if(VOID_ENABLE_COVERAGE)
target_compile_options(${TGT} PUBLIC
"$<$<CXX_COMPILER_ID:GNU>:--coverage;-fprofile-update=atomic>"