@@ -85,13 +85,85 @@ target_compile_options(
8585
8686target_compile_features (
8787 "${LIB_NAME} " PUBLIC
88- "cxx_std_17 " "cxx_constexpr" "cxx_auto_type"
88+ "cxx_std_20 " "cxx_constexpr" "cxx_auto_type"
8989 "cxx_defaulted_functions" "cxx_deleted_functions"
9090 "cxx_final" "cxx_lambdas" "cxx_override" "cxx_thread_local"
9191 "cxx_variadic_templates" "cxx_attribute_deprecated"
9292 "cxx_enum_forward_declarations"
9393)
9494
95+ if (NOT DPP_NO_CORO)
96+ message ("-- Attempting to enable coroutines feature" )
97+ set (CMAKE_CXX_STANDARD 20)
98+ target_compile_features (${LIB_NAME} PUBLIC cxx_std_20)
99+ if (WIN32 AND NOT MINGW AND NOT DPP_CLANG_CL)
100+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /await:strict" ) # https://learn.microsoft.com/en-us/cpp/build/reference/await-enable-coroutine-support?view=msvc-170
101+ if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
102+ if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS_EQUAL 19.29.30158) # Taken from 2019 actions, as they seemingly fail to compile.
103+ message ("${BoldRed} Coroutines with MSVC (Visual Studio) require VS 2022 (Compiler Ver: 19.29.30158) or above. Forcing coroutines off.${ColourReset} " )
104+ set (DPP_NO_CORO ON )
105+ endif ()
106+ endif ()
107+ else ()
108+ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
109+ if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14.0.0) # clang >= 14 has native support
110+ message ("-- ${Yellow} Clang < 14 - attempting to detect if using libc++ or stdc++${ColourReset} " )
111+ check_cxx_source_compiles("
112+ #include <iostream>
113+
114+ int a =
115+ #ifdef __GLIBCXX__
116+ 1;
117+ #else
118+ fgsfds;
119+ #endif
120+
121+ int main(int argc, char* argv[])
122+ {
123+ return 0;
124+ }
125+ " IS_GLIBCXX)
126+ if (IS_GLIBCXX)
127+ if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0.0)
128+ message ("${BoldRed} Clang with stdc++ and coroutines requires version 12.0.0 or above. Forcing coroutines off.${ColourReset} " )
129+ set (DPP_NO_CORO ON )
130+ else ()
131+ message ("-- ${Yellow} Detected stdc++ - enabling mock std::experimental namespace${ColourReset} " )
132+ target_compile_definitions (${LIB_NAME} PUBLIC "STDCORO_GLIBCXX_COMPAT" "DPP_CORO" )
133+ endif ()
134+ else ()
135+ message ("-- ${Yellow} Detected libc++ - using <experimental/coroutine>${ColourReset} " )
136+ if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0.0)
137+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines-ts" )
138+ endif ()
139+ target_compile_definitions (${LIB_NAME} PUBLIC "STDCORO_GLIBCXX_COMPAT" "DPP_CORO" )
140+ endif ()
141+ message ("-- ${Yellow} Note - coroutines in clang < 14 are experimental, upgrading is recommended${ColourReset} " )
142+ endif ()
143+ elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
144+ if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0)
145+ message ("${BoldRed} Coroutines with g++ require version 10 or above. Forcing coroutines off.${ColourReset} " )
146+ set (DPP_NO_CORO ON )
147+ elseif (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.0)
148+ message ("-- ${Yellow} Note - coroutines in g++10 are experimental, upgrading to g++11 or above is recommended${ColourReset} " )
149+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines" )
150+ target_compile_definitions (${LIB_NAME} PUBLIC "STDCORO_GLIBCXX_COMPAT" "DPP_CORO" )
151+ endif ()
152+ endif ()
153+ endif ()
154+ endif ()
155+
156+ if (DPP_NO_CORO)
157+ message ("-- ${Yellow} Coroutines are disabled.${ColourReset} " )
158+ target_compile_definitions (${LIB_NAME} PUBLIC DPP_NO_CORO)
159+ else ()
160+ message ("-- ${Green} Coroutines are enabled!${ColourReset} " )
161+ endif ()
162+
163+ if (DPP_FORMATTERS)
164+ target_compile_definitions (${LIB_NAME} PUBLIC DPP_FORMATTERS)
165+ endif ()
166+
95167target_include_directories (
96168 "${LIB_NAME} " PUBLIC
97169 "$<BUILD_INTERFACE:${DPP_ROOT_PATH} /include>"
0 commit comments