From 31aea2572884a9faed9eea443233261c1130c74f Mon Sep 17 00:00:00 2001 From: Ankush Singh <11595119+thewisebro@users.noreply.github.com> Date: Thu, 11 Jun 2020 12:51:27 +0530 Subject: [PATCH] [json-schema-validator] Add new port (#11599) * [json-schema-validator] Add new port * [json-schema-validator] Fix string ambiguous assignment error * [json-schema-validator] Remove redundant part from patch's path * [json-schema-validator] Forward find_package() for nlohmann_json * [json-schema-validator] comment out lines from source's CMakeLists.txt * [json-schema-validator] Improve portfile.cmake and regenerate patch Co-authored-by: JackBoosY --- ports/json-schema-validator/CONTROL | 5 +++ .../cmake-find-package.patch | 36 +++++++++++++++++++ .../fix-ambiguous-assignment.patch | 13 +++++++ .../forward-find-package.patch | 14 ++++++++ ports/json-schema-validator/portfile.cmake | 30 ++++++++++++++++ ports/json-schema-validator/usage | 4 +++ 6 files changed, 102 insertions(+) create mode 100644 ports/json-schema-validator/CONTROL create mode 100644 ports/json-schema-validator/cmake-find-package.patch create mode 100644 ports/json-schema-validator/fix-ambiguous-assignment.patch create mode 100644 ports/json-schema-validator/forward-find-package.patch create mode 100644 ports/json-schema-validator/portfile.cmake create mode 100644 ports/json-schema-validator/usage diff --git a/ports/json-schema-validator/CONTROL b/ports/json-schema-validator/CONTROL new file mode 100644 index 000000000..a602b1dec --- /dev/null +++ b/ports/json-schema-validator/CONTROL @@ -0,0 +1,5 @@ +Source: json-schema-validator +Version: 2.1.0 +Homepage: https://github.com/pboettch/json-schema-validator +Description: This is a C++ library for validating JSON documents based on a JSON Schema. This validator is based on nlohmann json library. +Build-Depends: nlohmann-json[core] diff --git a/ports/json-schema-validator/cmake-find-package.patch b/ports/json-schema-validator/cmake-find-package.patch new file mode 100644 index 000000000..995ae06b0 --- /dev/null +++ b/ports/json-schema-validator/cmake-find-package.patch @@ -0,0 +1,36 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c4cc218..ff2b706 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -8,6 +8,8 @@ cmake_minimum_required(VERSION 3.2) + option(BUILD_TESTS "Build tests" ON) + option(BUILD_EXAMPLES "Build examples" ON) + ++find_package(nlohmann_json CONFIG REQUIRED) ++ + # the library + add_library(nlohmann_json_schema_validator + src/json-schema-draft7.json.cpp +@@ -34,6 +36,13 @@ set_target_properties(nlohmann_json_schema_validator + # because of the dependency to nlohmann_json. + set(JSON_VALIDATOR_INSTALL ON) + ++target_link_libraries( ++ nlohmann_json_schema_validator ++ PUBLIC ++ nlohmann_json ++ nlohmann_json::nlohmann_json) ++ ++if(0) + # here we decice how nlohmann::json is found and used to build this project + + # first, check whether a nlohmann_json::nlohmann_json target exists already +@@ -92,7 +101,7 @@ else() + set(nlohmann_json_DIR ${JSON_HPP}) + endif() + endif() +- ++endif() + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR + "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + target_compile_options(nlohmann_json_schema_validator diff --git a/ports/json-schema-validator/fix-ambiguous-assignment.patch b/ports/json-schema-validator/fix-ambiguous-assignment.patch new file mode 100644 index 000000000..3e655b485 --- /dev/null +++ b/ports/json-schema-validator/fix-ambiguous-assignment.patch @@ -0,0 +1,13 @@ +diff --git a/src/json-validator.cpp b/src/json-validator.cpp +index f16f3ef..1f7b615 100644 +--- a/src/json-validator.cpp ++++ b/src/json-validator.cpp +@@ -663,7 +663,7 @@ public: + #ifndef NO_STD_REGEX + attr = sch.find("pattern"); + if (attr != sch.end()) { +- patternString_ = attr.value(); ++ patternString_ = attr.value().get(); + pattern_ = {true, REGEX_NAMESPACE::regex(attr.value().get(), + REGEX_NAMESPACE::regex::ECMAScript)}; + sch.erase(attr); diff --git a/ports/json-schema-validator/forward-find-package.patch b/ports/json-schema-validator/forward-find-package.patch new file mode 100644 index 000000000..e5ddde525 --- /dev/null +++ b/ports/json-schema-validator/forward-find-package.patch @@ -0,0 +1,14 @@ +diff --git a/nlohmann_json_schema_validatorConfig.cmake.in b/nlohmann_json_schema_validatorConfig.cmake.in +index 6ee0df2..e0315fa 100644 +--- a/nlohmann_json_schema_validatorConfig.cmake.in ++++ b/nlohmann_json_schema_validatorConfig.cmake.in +@@ -7,6 +7,9 @@ + get_filename_component(NLOHMANN_JSON_SCHEMA_VALIDATOR_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + set(NLOHMANN_JSON_SCHEMA_VALIDATOR_INCLUDE_DIRS @CONF_INCLUDE_DIRS@) + ++include(CMakeFindDependencyMacro) ++find_dependency(nlohmann_json) ++ + # Our library dependencies (contains definitions for IMPORTED targets) + if(NOT TARGET json-schema-validator) + include("${NLOHMANN_JSON_SCHEMA_VALIDATOR_CMAKE_DIR}/nlohmann_json_schema_validatorTargets.cmake") diff --git a/ports/json-schema-validator/portfile.cmake b/ports/json-schema-validator/portfile.cmake new file mode 100644 index 000000000..941ec5372 --- /dev/null +++ b/ports/json-schema-validator/portfile.cmake @@ -0,0 +1,30 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO pboettch/json-schema-validator + REF 27fc1d094503623dfe39365ba82581507524545c + SHA512 4fd05087743f43871586a53d119acd1a19d0bdec8a5620f62b6eee7a926d285842e8439127eec52eeb11069c92b8d9af28558897d48e2422ecafca39d9f23cdb + HEAD_REF master + PATCHES + fix-ambiguous-assignment.patch + cmake-find-package.patch + forward-find-package.patch +) + +vcpkg_configure_cmake( + SOURCE_PATH ${SOURCE_PATH} + PREFER_NINJA + OPTIONS + -DBUILD_TESTS=OFF + -DBUILD_EXAMPLES=OFF +) + +vcpkg_install_cmake() + +set(PKG_NAME "nlohmann_json_schema_validator") +vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake/${PKG_NAME} TARGET_PATH share/${PKG_NAME}) + +file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) + +file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) +file(INSTALL ${CMAKE_CURRENT_LIST_DIR}/usage DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT}) + diff --git a/ports/json-schema-validator/usage b/ports/json-schema-validator/usage new file mode 100644 index 000000000..3493d3808 --- /dev/null +++ b/ports/json-schema-validator/usage @@ -0,0 +1,4 @@ +The package json-schema-validator provides CMake integration: + + find_package(nlohmann_json_schema_validator REQUIRED) + target_link_libraries(main PRIVATE nlohmann_json_schema_validator)