@@ -53,6 +53,70 @@ endif()
5353option (USE_RECOMMENDED_CXX_STANDARD "Use recommended C++ standard" ON )
5454mark_as_advanced (USE_RECOMMENDED_CXX_STANDARD)
5555
56+ option (USE_CPP23 "Use C++23 standard where possible" OFF )
57+
58+ # Required for <stacktrace> on Clang/GCC
59+ if (USE_CPP23)
60+ if (DAEMON_CXX_COMPILER_Clang_COMPATIBILITY OR DAEMON_CXX_COMPILER_GCC_COMPATIBILITY)
61+ if ((DAEMON_CXX_COMPILER_Clang_VERSION VERSION_GREATER_EQUAL 19.1.0) OR (DAEMON_CXX_COMPILER_GCC_VERSION VERSION_GREATER_EQUAL 13.3))
62+ set (CPP23SupportLibraryTryExp TRUE )
63+ endif ()
64+
65+ if ((DAEMON_CXX_COMPILER_Clang_VERSION VERSION_GREATER_EQUAL 17.0.1) OR (DAEMON_CXX_COMPILER_GCC_VERSION VERSION_GREATER_EQUAL 12.1))
66+ set (CPP23SupportLibraryTryBacktrace TRUE )
67+ endif ()
68+
69+ if (CPP23SupportLibraryTryExp)
70+ set (CPP23SupportLibrary "-lstdc++exp" )
71+ set (CPP23SupportLibraryCompatibleCompiler TRUE )
72+
73+ find_library (HAVE_CPP23SupportLibrary "libstdc++exp" )
74+ endif ()
75+
76+ if (CPP23SupportLibraryTryBacktrace AND (HAVE_CPP23SupportLibrary-NOTFOUND OR NOT CPP23SupportLibraryTryExp))
77+ if (CPP23SupportLibraryCompatibleCompiler)
78+ set (CPP23SupportLibraryOldLibrary TRUE )
79+ endif ()
80+
81+ set (CPP23SupportLibrary "-lstdc++_libbacktrace" )
82+ set (CPP23SupportLibraryCompatibleCompiler TRUE )
83+
84+ find_library (HAVE_CPP23SupportLibrary "libstdc++_libbacktrace" )
85+ endif ()
86+
87+ if (HAVE_CPP23SupportLibrary-NOTFOUND )
88+ if (NOT CPP23SupportLibraryCompatibleCompiler)
89+ message (WARNING "Not using <stacktrace>: the compiler is too old (requires clang >= 17.0.1 or GCC >= 12.1)" )
90+ else ()
91+ message (WARNING "Not using <stacktrace>: libstdc++exp or libstdc++_backtrace is required, but wasn't found in system paths" )
92+ endif ()
93+
94+ set (CPP23SupportLibrary "" )
95+ elseif (CXX_FLAGS MATCHES ".*\\ -stdlib\\ =libc\\ +\\ +*" )
96+ message (WARNING "Not using <stacktrace>: only -stdlib=libstdc++ is supported" )
97+
98+ set (CPP23SupportLibrary "" )
99+ else ()
100+ add_definitions (-DDAEMON_CPP23_SUPPORT_LIBRARY_ENABLED=1)
101+ # FIXME: Doesn't work?
102+ add_compile_options ("-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR} /src=." )
103+
104+ if (CPP23SupportLibraryOldLibrary)
105+ message (STATUS "Using <stacktrace>: found ${CPP23SupportLibrary} (recommended to use libc++exp on this compiler version instead, but it wasn't found)" )
106+ else ()
107+ message (STATUS "Using <stacktrace>: found ${CPP23SupportLibrary} " )
108+ endif ()
109+ endif ()
110+ elseif (MSVC )
111+ # FIXME: Doesn't work in sgame/cgame?
112+ string (REPLACE "/" "\\ " backslashed_dir ${CMAKE_CURRENT_SOURCE_DIR} /src)
113+ add_compile_options ("/d1trimfile:${backslashed_dir} " )
114+
115+ string (REPLACE "/" "\\ " backslashed_dir ${CMAKE_CURRENT_SOURCE_DIR} /daemon/src)
116+ add_compile_options ("/d1trimfile:${backslashed_dir} " )
117+ endif ()
118+ endif ()
119+
56120# Set flag without checking, optional argument specifies build type
57121macro (set_c_flag FLAG)
58122 if (${ARGC} GREATER 1)
@@ -255,7 +319,19 @@ else()
255319 endif ()
256320 endif ()
257321
258- if (USE_RECOMMENDED_CXX_STANDARD)
322+ if (USE_CPP23)
323+ if (MSVC )
324+ add_compile_options ("/std:c++23preview" )
325+ else ()
326+ try_cxx_flag(GNUXX23 "-std=gnu++23" )
327+
328+ if (NOT FLAG_GNUXX23)
329+ message (WARNING "Requested C++23 is not supported, falling back to C++14" )
330+ endif ()
331+ endif ()
332+ endif ()
333+
334+ if (NOT USE_CPP23 AND (NOT FLAG_GNUXX23 OR USE_RECOMMENDED_CXX_STANDARD))
259335 # PNaCl only defines isascii if __STRICT_ANSI__ is not defined,
260336 # always prefer GNU dialect.
261337 try_cxx_flag(GNUXX14 "-std=gnu++14" )
0 commit comments