Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@ option(ENABLE_UBSAN "Enable Undefined Behaviour Sanitizer" OFF)
option(ENABLE_TSAN "Enable Thread Sanitizer" OFF)
option(ENABLE_MSAN "Enable Memory Sanitizer" OFF)

option(
XYZ_PROTOCOL_BUILD_REFLECTION_IMPLEMENTATION
"Also build and test the C++26-reflection-based implementation of protocol, \
which requires a compiler with C++26 P2996 reflection support \
(GCC 16+ with -freflection)."
OFF)

if(XYZ_PROTOCOL_BUILD_REFLECTION_IMPLEMENTATION)
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_FLAGS "-std=c++26 -freflection")
check_cxx_source_compiles(
"
#include <meta>
constexpr std::meta::info reflection_of_int = ^^int;
int main() {}
"
XYZ_PROTOCOL_REFLECTION_SUPPORTED)
unset(CMAKE_REQUIRED_FLAGS)
if(NOT XYZ_PROTOCOL_REFLECTION_SUPPORTED)
message(
FATAL_ERROR
"XYZ_PROTOCOL_BUILD_REFLECTION_IMPLEMENTATION is ON but the compiler "
"(${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}) does not "
"accept '-std=c++26 -freflection'. C++26 reflection currently "
"requires GCC 16 or newer; configure with e.g. "
"CXX=g++-16 CC=gcc-16 and a separate build directory (-B).")
endif()
endif()

if(ENABLE_ASAN OR ENABLE_UBSAN OR ENABLE_TSAN OR ENABLE_MSAN)
set(ENABLE_SANITIZERS ON)
endif()
Expand Down Expand Up @@ -171,6 +200,10 @@ if(XYZ_PROTOCOL_IS_NOT_SUBPROJECT)
--flags=-I${CMAKE_CURRENT_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()

if(XYZ_PROTOCOL_BUILD_REFLECTION_IMPLEMENTATION)
add_subdirectory(reflection)
endif()
endif(${BUILD_TESTING})

endif()
2 changes: 1 addition & 1 deletion cmake/xyz_add_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function(xyz_add_test)
if(NOT XYZ_VERSION)
set(XYZ_VERSION 20)
else()
set(VALID_TARGET_VERSIONS 11 14 17 20 23)
set(VALID_TARGET_VERSIONS 11 14 17 20 23 26)
list(FIND VALID_TARGET_VERSIONS ${XYZ_VERSION} index)
if(index EQUAL -1)
message(FATAL_ERROR "TYPE must be one of <${VALID_TARGET_VERSIONS}>")
Expand Down
17 changes: 17 additions & 0 deletions reflection/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
xyz_add_library(
NAME reflection_protocol
ALIAS xyz_protocol::reflection_protocol)
target_sources(
reflection_protocol INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/protocol.h>)

xyz_add_test(
NAME
reflection_protocol_test
VERSION
26
LINK_LIBRARIES
xyz_protocol::reflection_protocol
FILES
protocol_test.cc)
target_compile_options(reflection_protocol_test PRIVATE -freflection)
Loading
Loading