From 2b672289e17c18e140ba4f9b79cc5c873d3d5093 Mon Sep 17 00:00:00 2001 From: Jmgr Date: Sun, 25 Apr 2021 20:30:56 +0100 Subject: [PATCH] Fix optional being in experimental/ with some compilers --- CMakeLists.txt | 1 + Source/utils/paths.cpp | 4 +++- Source/utils/stdcompat/optional.hpp | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Source/utils/stdcompat/optional.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c0602ea6f..b7ba28bb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -706,6 +706,7 @@ endif() if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") target_compile_options(${BIN_TARGET} PRIVATE "/W0") + target_compile_options(${BIN_TARGET} PRIVATE "/Zc:__cplusplus") endif() if(APPLE) diff --git a/Source/utils/paths.cpp b/Source/utils/paths.cpp index f8a1031f7..22f2196e3 100644 --- a/Source/utils/paths.cpp +++ b/Source/utils/paths.cpp @@ -1,8 +1,10 @@ #include "utils/paths.h" -#include "utils/log.hpp" #include +#include "utils/stdcompat/optional.hpp" +#include "utils/log.hpp" + #ifdef USE_SDL1 #include "utils/sdl2_to_1_2_backports.h" #endif diff --git a/Source/utils/stdcompat/optional.hpp b/Source/utils/stdcompat/optional.hpp new file mode 100644 index 000000000..cde1efc04 --- /dev/null +++ b/Source/utils/stdcompat/optional.hpp @@ -0,0 +1,14 @@ +#pragma once + +#ifdef __has_include +#if defined(__cplusplus) && __cplusplus >= 201606L && __has_include() +#include // IWYU pragma: export +#elif __has_include() +#include // IWYU pragma: export +#define optional experimental::optional +#else +#error "Missing support for or " +#endif +#else +#error "__has_include unavailable" +#endif