108 lines
3.4 KiB
CMake
108 lines
3.4 KiB
CMake
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()
|