[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 <yuzaiyang@beyondsoft.com>
This commit is contained in:
Ankush Singh 2020-06-11 12:51:27 +05:30 committed by GitHub
parent 9c0893e04d
commit 31aea25728
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 102 additions and 0 deletions

View File

@ -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]

View File

@ -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

View File

@ -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<std::string>();
pattern_ = {true, REGEX_NAMESPACE::regex(attr.value().get<std::string>(),
REGEX_NAMESPACE::regex::ECMAScript)};
sch.erase(attr);

View File

@ -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")

View File

@ -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})

View File

@ -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)