diff options
Diffstat (limited to 'vcpkg/ports/nlohmann-json')
| -rw-r--r-- | vcpkg/ports/nlohmann-json/fix-4742_std_optional.patch | 108 | ||||
| -rw-r--r-- | vcpkg/ports/nlohmann-json/portfile.cmake | 51 | ||||
| -rw-r--r-- | vcpkg/ports/nlohmann-json/usage | 12 | ||||
| -rw-r--r-- | vcpkg/ports/nlohmann-json/vcpkg.json | 23 |
4 files changed, 194 insertions, 0 deletions
diff --git a/vcpkg/ports/nlohmann-json/fix-4742_std_optional.patch b/vcpkg/ports/nlohmann-json/fix-4742_std_optional.patch new file mode 100644 index 0000000..9f0edb4 --- /dev/null +++ b/vcpkg/ports/nlohmann-json/fix-4742_std_optional.patch @@ -0,0 +1,108 @@ +diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp +index d647d742..797f714d 100644 +--- a/include/nlohmann/detail/conversions/from_json.hpp ++++ b/include/nlohmann/detail/conversions/from_json.hpp +@@ -13,9 +13,6 @@ + #include <forward_list> // forward_list + #include <iterator> // inserter, front_inserter, end + #include <map> // map +-#ifdef JSON_HAS_CPP_17 +- #include <optional> // optional +-#endif + #include <string> // string + #include <tuple> // tuple, make_tuple + #include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_convertible +@@ -32,6 +29,11 @@ + #include <nlohmann/detail/string_concat.hpp> + #include <nlohmann/detail/value_t.hpp> + ++// include after macro_scope.hpp ++#ifdef JSON_HAS_CPP_17 ++ #include <optional> // optional ++#endif ++ + NLOHMANN_JSON_NAMESPACE_BEGIN + namespace detail + { +@@ -47,7 +49,6 @@ inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n) + } + + #ifdef JSON_HAS_CPP_17 +-#ifndef JSON_USE_IMPLICIT_CONVERSIONS + template<typename BasicJsonType, typename T> + void from_json(const BasicJsonType& j, std::optional<T>& opt) + { +@@ -60,8 +61,6 @@ void from_json(const BasicJsonType& j, std::optional<T>& opt) + opt.emplace(j.template get<T>()); + } + } +- +-#endif // JSON_USE_IMPLICIT_CONVERSIONS + #endif // JSON_HAS_CPP_17 + + // overloads for basic_json template parameters +diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp +index ead45665..f8413850 100644 +--- a/include/nlohmann/detail/conversions/to_json.hpp ++++ b/include/nlohmann/detail/conversions/to_json.hpp +@@ -267,7 +267,7 @@ struct external_constructor<value_t::object> + #ifdef JSON_HAS_CPP_17 + template<typename BasicJsonType, typename T, + enable_if_t<std::is_constructible<BasicJsonType, T>::value, int> = 0> +-void to_json(BasicJsonType& j, const std::optional<T>& opt) ++void to_json(BasicJsonType& j, const std::optional<T>& opt) noexcept + { + if (opt.has_value()) + { +diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp +index 82d69f7c..53a9ea70 100644 +--- a/single_include/nlohmann/json.hpp ++++ b/single_include/nlohmann/json.hpp +@@ -173,9 +173,6 @@ + #include <forward_list> // forward_list + #include <iterator> // inserter, front_inserter, end + #include <map> // map +-#ifdef JSON_HAS_CPP_17 +- #include <optional> // optional +-#endif + #include <string> // string + #include <tuple> // tuple, make_tuple + #include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_convertible +@@ -4817,6 +4814,11 @@ NLOHMANN_JSON_NAMESPACE_END + // #include <nlohmann/detail/value_t.hpp> + + ++// include after macro_scope.hpp ++#ifdef JSON_HAS_CPP_17 ++ #include <optional> // optional ++#endif ++ + NLOHMANN_JSON_NAMESPACE_BEGIN + namespace detail + { +@@ -4832,7 +4834,6 @@ inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n) + } + + #ifdef JSON_HAS_CPP_17 +-#ifndef JSON_USE_IMPLICIT_CONVERSIONS + template<typename BasicJsonType, typename T> + void from_json(const BasicJsonType& j, std::optional<T>& opt) + { +@@ -4845,8 +4846,6 @@ void from_json(const BasicJsonType& j, std::optional<T>& opt) + opt.emplace(j.template get<T>()); + } + } +- +-#endif // JSON_USE_IMPLICIT_CONVERSIONS + #endif // JSON_HAS_CPP_17 + + // overloads for basic_json template parameters +@@ -5914,7 +5913,7 @@ struct external_constructor<value_t::object> + #ifdef JSON_HAS_CPP_17 + template<typename BasicJsonType, typename T, + enable_if_t<std::is_constructible<BasicJsonType, T>::value, int> = 0> +-void to_json(BasicJsonType& j, const std::optional<T>& opt) ++void to_json(BasicJsonType& j, const std::optional<T>& opt) noexcept + { + if (opt.has_value()) + { diff --git a/vcpkg/ports/nlohmann-json/portfile.cmake b/vcpkg/ports/nlohmann-json/portfile.cmake new file mode 100644 index 0000000..f4ef121 --- /dev/null +++ b/vcpkg/ports/nlohmann-json/portfile.cmake @@ -0,0 +1,51 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO nlohmann/json + REF "v${VERSION}" + SHA512 6cc1e86261f8fac21cc17a33da3b6b3c3cd5c116755651642af3c9e99bb3538fd42c1bd50397a77c8fb6821bc62d90e6b91bcdde77a78f58f2416c62fc53b97d + HEAD_REF master + PATCHES + fix-4742_std_optional.patch +) + +if(NOT DEFINED nlohmann-json_IMPLICIT_CONVERSIONS) + set(nlohmann-json_IMPLICIT_CONVERSIONS ON) +endif() + +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS +FEATURES + "diagnostics" JSON_Diagnostics +) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS ${FEATURE_OPTIONS} + -DJSON_Install=ON + -DJSON_MultipleHeaders=ON + -DJSON_BuildTests=OFF + -DJSON_ImplicitConversions=${nlohmann-json_IMPLICIT_CONVERSIONS} +) +vcpkg_cmake_install() +vcpkg_cmake_config_fixup(PACKAGE_NAME "nlohmann_json" CONFIG_PATH "share/cmake/nlohmann_json") +vcpkg_fixup_pkgconfig() + +vcpkg_replace_string( + "${CURRENT_PACKAGES_DIR}/share/nlohmann_json/nlohmann_jsonTargets.cmake" + "{_IMPORT_PREFIX}/nlohmann_json.natvis" + "{_IMPORT_PREFIX}/share/nlohmann_json/nlohmann_json.natvis" + IGNORE_UNCHANGED +) +if(EXISTS "${CURRENT_PACKAGES_DIR}/nlohmann_json.natvis") + file(RENAME + "${CURRENT_PACKAGES_DIR}/nlohmann_json.natvis" + "${CURRENT_PACKAGES_DIR}/share/nlohmann_json/nlohmann_json.natvis" + ) +endif() + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug") + +# Handle copyright +file(INSTALL "${SOURCE_PATH}/LICENSE.MIT" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) + +# Handle usage +file(COPY "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") diff --git a/vcpkg/ports/nlohmann-json/usage b/vcpkg/ports/nlohmann-json/usage new file mode 100644 index 0000000..19c76d5 --- /dev/null +++ b/vcpkg/ports/nlohmann-json/usage @@ -0,0 +1,12 @@ +The package nlohmann-json provides CMake targets:
+
+ find_package(nlohmann_json CONFIG REQUIRED)
+ target_link_libraries(main PRIVATE nlohmann_json::nlohmann_json)
+
+The package nlohmann-json can be configured to not provide implicit conversions via a custom triplet file:
+
+ set(nlohmann-json_IMPLICIT_CONVERSIONS OFF)
+
+For more information, see the docs here:
+
+ https://json.nlohmann.me/api/macros/json_use_implicit_conversions/
diff --git a/vcpkg/ports/nlohmann-json/vcpkg.json b/vcpkg/ports/nlohmann-json/vcpkg.json new file mode 100644 index 0000000..48ef875 --- /dev/null +++ b/vcpkg/ports/nlohmann-json/vcpkg.json @@ -0,0 +1,23 @@ +{ + "name": "nlohmann-json", + "version-semver": "3.12.0", + "port-version": 1, + "description": "JSON for Modern C++", + "homepage": "https://github.com/nlohmann/json", + "license": "MIT", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ], + "features": { + "diagnostics": { + "description": "Build json_diagnostics" + } + } +} |