Skip to content

Commit 2455845

Browse files
authored
improv: detect c++17 to define DPP_NO_CORO at the point of usage (#1378)
1 parent 93587d2 commit 2455845

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ buildtools/composer.phar
1212
src/build
1313
cmake-build-*
1414
docpages/example_code/build
15+
mlspp/include/namespace.h
1516

1617
# tests
1718
test

include/dpp/coro/coro.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
************************************************************************************/
2121

2222
#pragma once
23+
24+
#include <dpp/export.h>
25+
2326
#ifndef DPP_NO_CORO
2427

2528
#if (defined(_LIBCPP_VERSION) and !defined(__cpp_impl_coroutine)) // if libc++ experimental implementation (LLVM < 14)

include/dpp/export.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333
#error "D++ Requires a C++17 compatible C++ compiler. Please ensure that you have enabled C++17 in your compiler flags."
3434
#endif
3535

36+
/* If not using c++20, define DPP_CPP17_COMPAT and DPP_NO_CORO.
37+
*/
38+
#if !(defined(__cplusplus) && __cplusplus >= 202002L) && !(defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
39+
# define DPP_CPP17_COMPAT
40+
# if !defined(DPP_CORO) || !DPP_CORO // Allow overriding this because why not
41+
# define DPP_NO_CORO
42+
# endif
43+
#endif
44+
3645
#ifndef DPP_STATIC
3746
/* Dynamic linked build as shared object or dll */
3847
#ifdef DPP_BUILD

library/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,16 @@ if(NOT DPP_NO_CORO)
403403
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0.0)
404404
message("${BoldRed}Clang with stdc++ and coroutines requires version 12.0.0 or above. Forcing coroutines off.${ColourReset}")
405405
set(DPP_NO_CORO ON)
406+
else()
407+
message("-- ${Yellow}Detected stdc++ - enabling mock std::experimental namespace${ColourReset}")
408+
target_compile_definitions(dpp PUBLIC "STDCORO_GLIBCXX_COMPAT" "DPP_CORO")
406409
endif()
407-
message("-- ${Yellow}Detected stdc++ - enabling mock std::experimental namespace${ColourReset}")
408-
target_compile_definitions(dpp PUBLIC "STDCORO_GLIBCXX_COMPAT")
409410
else()
410411
message("-- ${Yellow}Detected libc++ - using <experimental/coroutine>${ColourReset}")
411412
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0.0)
412413
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines-ts")
413414
endif()
415+
target_compile_definitions(dpp PUBLIC "STDCORO_GLIBCXX_COMPAT" "DPP_CORO")
414416
endif()
415417
message("-- ${Yellow}Note - coroutines in clang < 14 are experimental, upgrading is recommended${ColourReset}")
416418
endif()
@@ -421,6 +423,7 @@ if(NOT DPP_NO_CORO)
421423
elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.0)
422424
message("-- ${Yellow}Note - coroutines in g++10 are experimental, upgrading to g++11 or above is recommended${ColourReset}")
423425
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines")
426+
target_compile_definitions(dpp PUBLIC "STDCORO_GLIBCXX_COMPAT" "DPP_CORO")
424427
endif()
425428
endif()
426429
endif()

mlspp/include/namespace.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
2-
3-
// Configurable top-level MLS namespace
4-
#define MLS_NAMESPACE ../include/dpp/mlspp/mls
1+
#pragma once
2+
3+
// Configurable top-level MLS namespace
4+
#define MLS_NAMESPACE mls

0 commit comments

Comments
 (0)