From 0ac4c8aa9bb005931335ebc9230ea41290f4a8e2 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Fri, 29 Jul 2022 15:41:27 +0200 Subject: [PATCH] Derive ABI prefix from NLOHMANN_JSON_VERSION_* --- include/nlohmann/detail/abi_macros.hpp | 32 ++++++++++++++---- include/nlohmann/json.hpp | 12 ------- single_include/nlohmann/json.hpp | 45 +++++++++++++++----------- 3 files changed, 52 insertions(+), 37 deletions(-) diff --git a/include/nlohmann/detail/abi_macros.hpp b/include/nlohmann/detail/abi_macros.hpp index e7f2dec9a..d308637a5 100644 --- a/include/nlohmann/detail/abi_macros.hpp +++ b/include/nlohmann/detail/abi_macros.hpp @@ -1,6 +1,18 @@ #pragma once -// This file contains all macro definitions affecting the ABI +// This file contains all macro definitions affecting or depending on the ABI + +#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK + #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) + #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 10 || NLOHMANN_JSON_VERSION_PATCH != 5 + #warning "Already included a different version of the library!" + #endif + #endif +#endif + +#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_MINOR 10 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_PATCH 5 // NOLINT(modernize-macro-to-enum) #ifndef JSON_DIAGNOSTICS #define JSON_DIAGNOSTICS 0 @@ -22,15 +34,23 @@ #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON #endif -#define NLOHMANN_JSON_ABI_PREFIX json_v3_10_5 +#define NLOHMANN_JSON_ABI_PREFIX_EX(major, minor, patch) \ + json_v ## major ## _ ## minor ## _ ## patch +#define NLOHMANN_JSON_ABI_PREFIX(major, minor, patch) \ + NLOHMANN_JSON_ABI_PREFIX_EX(major, minor, patch) + #define NLOHMANN_JSON_ABI_CONCAT_EX(a, b, c) a ## b ## c -#define NLOHMANN_JSON_ABI_CONCAT(a, b, c) NLOHMANN_JSON_ABI_CONCAT_EX(a, b, c) +#define NLOHMANN_JSON_ABI_CONCAT(a, b, c) \ + NLOHMANN_JSON_ABI_CONCAT_EX(a, b, c) + #define NLOHMANN_JSON_ABI_STRING \ NLOHMANN_JSON_ABI_CONCAT( \ - NLOHMANN_JSON_ABI_PREFIX, \ + NLOHMANN_JSON_ABI_PREFIX( \ + NLOHMANN_JSON_VERSION_MAJOR, \ + NLOHMANN_JSON_VERSION_MINOR, \ + NLOHMANN_JSON_VERSION_PATCH), \ NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ - NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON \ - ) + NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) #ifndef NLOHMANN_JSON_NAMESPACE #define NLOHMANN_JSON_NAMESPACE nlohmann::NLOHMANN_JSON_ABI_STRING diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 9404bd733..cdf52b36d 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -18,18 +18,6 @@ #ifndef INCLUDE_NLOHMANN_JSON_HPP_ #define INCLUDE_NLOHMANN_JSON_HPP_ -#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK - #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) - #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 10 || NLOHMANN_JSON_VERSION_PATCH != 5 - #warning "Already included a different version of the library!" - #endif - #endif -#endif - -#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) -#define NLOHMANN_JSON_VERSION_MINOR 10 // NOLINT(modernize-macro-to-enum) -#define NLOHMANN_JSON_VERSION_PATCH 5 // NOLINT(modernize-macro-to-enum) - #include // all_of, find, for_each #include // nullptr_t, ptrdiff_t, size_t #include // hash, less diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index ce4ce3bb4..bfecbd1a9 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -18,18 +18,6 @@ #ifndef INCLUDE_NLOHMANN_JSON_HPP_ #define INCLUDE_NLOHMANN_JSON_HPP_ -#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK - #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) - #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 10 || NLOHMANN_JSON_VERSION_PATCH != 5 - #warning "Already included a different version of the library!" - #endif - #endif -#endif - -#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) -#define NLOHMANN_JSON_VERSION_MINOR 10 // NOLINT(modernize-macro-to-enum) -#define NLOHMANN_JSON_VERSION_PATCH 5 // NOLINT(modernize-macro-to-enum) - #include // all_of, find, for_each #include // nullptr_t, ptrdiff_t, size_t #include // hash, less @@ -60,7 +48,19 @@ // #include -// This file contains all macro definitions affecting ABI +// This file contains all macro definitions affecting or depending on the ABI + +#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK + #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) + #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 10 || NLOHMANN_JSON_VERSION_PATCH != 5 + #warning "Already included a different version of the library!" + #endif + #endif +#endif + +#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_MINOR 10 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_PATCH 5 // NOLINT(modernize-macro-to-enum) #ifndef JSON_DIAGNOSTICS #define JSON_DIAGNOSTICS 0 @@ -82,15 +82,23 @@ #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON #endif -#define NLOHMANN_JSON_ABI_PREFIX json_v3_10_5 +#define NLOHMANN_JSON_ABI_PREFIX_EX(major, minor, patch) \ + json_v ## major ## _ ## minor ## _ ## patch +#define NLOHMANN_JSON_ABI_PREFIX(major, minor, patch) \ + NLOHMANN_JSON_ABI_PREFIX_EX(major, minor, patch) + #define NLOHMANN_JSON_ABI_CONCAT_EX(a, b, c) a ## b ## c -#define NLOHMANN_JSON_ABI_CONCAT(a, b, c) NLOHMANN_JSON_ABI_CONCAT_EX(a, b, c) +#define NLOHMANN_JSON_ABI_CONCAT(a, b, c) \ + NLOHMANN_JSON_ABI_CONCAT_EX(a, b, c) + #define NLOHMANN_JSON_ABI_STRING \ NLOHMANN_JSON_ABI_CONCAT( \ - NLOHMANN_JSON_ABI_PREFIX, \ + NLOHMANN_JSON_ABI_PREFIX( \ + NLOHMANN_JSON_VERSION_MAJOR, \ + NLOHMANN_JSON_VERSION_MINOR, \ + NLOHMANN_JSON_VERSION_PATCH), \ NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ - NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON \ - ) + NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) #ifndef NLOHMANN_JSON_NAMESPACE #define NLOHMANN_JSON_NAMESPACE nlohmann::NLOHMANN_JSON_ABI_STRING @@ -224,7 +232,6 @@ namespace detail { // https://en.cppreference.com/w/cpp/experimental/is_detected - struct nonesuch { nonesuch() = delete;