From 93fd55249b8f097e283f14420d55f23adbd2836b Mon Sep 17 00:00:00 2001 From: hubslave <29800872+hubslave@users.noreply.github.com> Date: Fri, 2 Mar 2018 18:15:45 +0200 Subject: [PATCH] Fix build on platforms without std::string_view json.hpp wants it, but it isn't always available. Rather than patch json.hpp directly to remove the dependency, provide a json.h wrapper header that subs in std::experimental::string_view using preprocessor magic. All the consumers of json.hpp are in src/web_service, so the wrapper header is placed there as well. --- src/web_service/announce_room_json.cpp | 2 +- src/web_service/json.h | 18 ++++++++++++++++++ src/web_service/telemetry_json.h | 2 +- src/web_service/verify_login.cpp | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/web_service/json.h diff --git a/src/web_service/announce_room_json.cpp b/src/web_service/announce_room_json.cpp index d2b79cbae..87f9327bb 100644 --- a/src/web_service/announce_room_json.cpp +++ b/src/web_service/announce_room_json.cpp @@ -3,9 +3,9 @@ // Refer to the license.txt file included. #include -#include #include "common/logging/log.h" #include "web_service/announce_room_json.h" +#include "web_service/json.h" #include "web_service/web_backend.h" namespace AnnounceMultiplayerRoom { diff --git a/src/web_service/json.h b/src/web_service/json.h new file mode 100644 index 000000000..88b31501e --- /dev/null +++ b/src/web_service/json.h @@ -0,0 +1,18 @@ +// Copyright 2018 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +// This hack is needed to support json.hpp on platforms where the C++17 stdlib +// lacks std::string_view. See https://github.com/nlohmann/json/issues/735. +// clang-format off +#if !__has_include() && __has_include() +# include +# define string_view experimental::string_view +# include +# undef string_view +#else +# include +#endif +// clang-format on diff --git a/src/web_service/telemetry_json.h b/src/web_service/telemetry_json.h index ae4a6f3c7..27f71b6ba 100644 --- a/src/web_service/telemetry_json.h +++ b/src/web_service/telemetry_json.h @@ -7,9 +7,9 @@ #include #include #include -#include #include "common/announce_multiplayer_room.h" #include "common/telemetry.h" +#include "web_service/json.h" namespace WebService { diff --git a/src/web_service/verify_login.cpp b/src/web_service/verify_login.cpp index 1bc3b5afe..05082a309 100644 --- a/src/web_service/verify_login.cpp +++ b/src/web_service/verify_login.cpp @@ -2,7 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include +#include "web_service/json.h" #include "web_service/verify_login.h" #include "web_service/web_backend.h"