JsonCPP: restore '1.0.0+' compatibility (#15368)

Previously, compiling on Ubuntu 20.04 would fail with the system-provided JsonCPP
version (1.7.4). Which would satisfy the documented requirement of "1.0.0+".
This commit is contained in:
SmallJoker 2024-11-03 15:10:39 +01:00 committed by GitHub
parent 3064f3ccb7
commit c884e7181f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 11 deletions

@ -277,7 +277,7 @@ endif()
# Library pack # Library pack
find_package(GMP REQUIRED) find_package(GMP REQUIRED)
find_package(Json REQUIRED) find_package(Json 1.0.0 REQUIRED)
find_package(Lua REQUIRED) find_package(Lua REQUIRED)
if(NOT USE_LUAJIT) if(NOT USE_LUAJIT)
add_subdirectory(lib/bitop) add_subdirectory(lib/bitop)

@ -13,10 +13,17 @@
#include <array> #include <array>
#include <optional> #include <optional>
#include <limits> #include <limits>
#include <memory> // unique_ptr
#include <stdexcept> #include <stdexcept>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#if JSONCPP_VERSION_HEXA < 0x01090000 /* 1.9.0 */
namespace Json {
using String = JSONCPP_STRING; // Polyfill
}
#endif
namespace tiniergltf { namespace tiniergltf {
static inline void check(bool cond) { static inline void check(bool cond) {
@ -1381,7 +1388,7 @@ static Json::Value readJson(Span<const char> span) {
Json::CharReaderBuilder builder; Json::CharReaderBuilder builder;
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
Json::Value json; Json::Value json;
JSONCPP_STRING err; Json::String err;
if (!reader->parse(span.ptr, span.end(), &json, &err)) if (!reader->parse(span.ptr, span.end(), &json, &err))
throw std::runtime_error(std::string("invalid JSON: ") + err); throw std::runtime_error(std::string("invalid JSON: ") + err);
return json; return json;

@ -2048,9 +2048,6 @@ bool read_tree_def(lua_State *L, int idx, const NodeDefManager *ndef,
} }
/******************************************************************************/ /******************************************************************************/
#if defined(JSONCPP_STRING) || !(JSONCPP_VERSION_MAJOR < 1 || JSONCPP_VERSION_MINOR < 9)
#define HAVE_JSON_STRING
#endif
// Returns depth of json value tree // Returns depth of json value tree
static int push_json_value_getdepth(const Json::Value &value) static int push_json_value_getdepth(const Json::Value &value)
@ -2079,13 +2076,8 @@ static bool push_json_value_helper(lua_State *L, const Json::Value &value,
lua_pushnumber(L, value.asDouble()); lua_pushnumber(L, value.asDouble());
break; break;
case Json::stringValue: { case Json::stringValue: {
#ifdef HAVE_JSON_STRING
const auto &str = value.asString(); const auto &str = value.asString();
lua_pushlstring(L, str.c_str(), str.size()); lua_pushlstring(L, str.c_str(), str.size());
#else
const char *str = value.asCString();
lua_pushstring(L, str ? str : "");
#endif
break; break;
} }
case Json::booleanValue: case Json::booleanValue:
@ -2101,7 +2093,7 @@ static bool push_json_value_helper(lua_State *L, const Json::Value &value,
case Json::objectValue: case Json::objectValue:
lua_createtable(L, 0, value.size()); lua_createtable(L, 0, value.size());
for (auto it = value.begin(); it != value.end(); ++it) { for (auto it = value.begin(); it != value.end(); ++it) {
#ifdef HAVE_JSON_STRING #if JSONCPP_VERSION_HEXA >= 0x01060000 /* 1.6.0 */
const auto &str = it.name(); const auto &str = it.name();
lua_pushlstring(L, str.c_str(), str.size()); lua_pushlstring(L, str.c_str(), str.size());
#else #else