Skip to content

Commit

Permalink
[C++] Only build DTOs with compilers that support C++ 17.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachBray committed Nov 3, 2023
1 parent 1a9385d commit 488e490
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,8 @@ private static CharSequence generateDtoFileHeader(
String.join("_", namespaces).toUpperCase(),
className.toUpperCase()));

sb.append("#if __cplusplus < 201703L\n")
sb.append("#if (defined(_MSVC_LANG) && _MSVC_LANG < 201703L) || ")
.append("(!defined(_MSVC_LANG) && defined(__cplusplus) && __cplusplus < 201703L)\n")
.append("#error DTO code requires at least C++17.\n")
.append("#endif\n\n");

Expand All @@ -1790,7 +1791,8 @@ private static CharSequence generateDtoFileHeader(
.append("#include <sstream>\n")
.append("#include <string>\n")
.append("#include <vector>\n")
.append("#include <tuple>\n");
.append("#include <tuple>\n")
.append("#include <optional>\n");

if (typesToInclude != null && !typesToInclude.isEmpty())
{
Expand Down
26 changes: 24 additions & 2 deletions sbe-tool/src/test/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,27 @@ sbe_test(Rc3OtfFullIrTest codecs)
sbe_test(CompositeElementsTest codecs)
sbe_test(Issue835Test codecs)
sbe_test(Issue889Test codecs)
sbe_test(DtoTest codecs)
target_compile_features(DtoTest PRIVATE cxx_std_17)

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Check if the GCC version supports C++17
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0")
sbe_test(DtoTest codecs)
target_compile_features(DtoTest PRIVATE cxx_std_17)
endif()
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "CLang")
# Check if CLang version supports C++17
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "4.0")
sbe_test(DtoTest codecs)
target_compile_features(DtoTest PRIVATE cxx_std_17)
endif()
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Check if CLang version supports C++17
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "19.14")
sbe_test(DtoTest codecs)
target_compile_options(DtoTest PRIVATE /std:c++17)
endif()
endif()

0 comments on commit 488e490

Please sign in to comment.