Adapt CMake project name to be coherent with nlohmann::json's naming

Now when json-schema-validator is installed CMake config files are installed in the lib/cmake/json-schema-validator directory.
The install json-schema-validatorTargets.cmake file properly imports the json-hpp and json-schema-validator libraries.
The install json-schema-validatorConfig.cmake file is used by CMake find_package function to include the json-schema-validatorTargets.cmake file and to set the variable JSON_SCHEMA_VALIDATOR_INCLUDE_DIRS to the install include directory.
To use find_package to find the json-schema-validator simply include.
A new test (test_cmake_install) has been added.

When NLohmann's JSON is install with CMake, it follows a certain
naming convention.

As we learned to do proper CMake-install thanks to @lkersting's work
this project now adapts to the way NLohmann is doing it. Namely:

- json-schema.hpp is now located (and installed)
  in a nlohmann/-subdirectory
- the CMake library and project's name is now
  nlohmann_json_schema_validator

Instead of doing non-standard acrobatics to find the json.hpp
now find_package is used in order to find NLohmann's package

Co-Authored-By: Patrick Boettcher <p@yai.se>
This commit is contained in:
Luke Kersting 2019-10-17 15:47:57 -06:00 committed by Patrick Boettcher
parent 5b6a6d0331
commit 8a7d1d3fde
22 changed files with 359 additions and 121 deletions

View File

@ -64,6 +64,6 @@ script:
# compile and execute unit tests
- mkdir -p build && cd build
- cmake .. -DNLOHMANN_JSON_DIR=.. ${CMAKE_OPTIONS} -GNinja && cmake --build . --config Release
- cmake .. -Dnlohmann_json_DIR=.. ${CMAKE_OPTIONS} -GNinja && cmake --build . --config Release
- ctest -C Release -V -j
- cd ..

View File

@ -1,78 +1,98 @@
project(json-schema-validator
project(nlohmann_json_schema_validator
LANGUAGES CXX)
set(PROJECT_VERSION 2.0.0)
set(PROJECT_VERSION 2.1.0)
cmake_minimum_required(VERSION 3.2)
option(BUILD_TESTS "Build tests" ON)
option(BUILD_EXAMPLES "Build examples" ON)
# if used as a subdirectory just define a json-hpp-target as add_library(json-hpp INTERFACE)
# and associate the path to json.hpp via target_include_directories()
if(NOT TARGET json-hpp)
set(NLOHMANN_JSON_DIR "" CACHE STRING "path to json.hpp")
# find nlohmann's json.hpp
find_path(JSON_HPP nlohmann/json.hpp
PATHS
${NLOHMANN_JSON_DIR}
${CMAKE_BINARY_DIR}/${NLOHMANN_JSON_DIR}) # in case it is a relative path
# get the full, real path
get_filename_component(NLOHMANN_JSON_REALPATH ${JSON_HPP} REALPATH)
if(NOT EXISTS ${NLOHMANN_JSON_REALPATH}/nlohmann/json.hpp)
message(FATAL_ERROR "please set NLOHMANN_JSON_DIR to a path in which NLohmann's json.hpp can be found. Looking for nlohmann/json.hpp in '${NLOHMANN_JSON_REALPATH}")
endif()
# create an interface-library for simple cmake-linking
add_library(json-hpp INTERFACE)
target_include_directories(json-hpp
INTERFACE
${NLOHMANN_JSON_REALPATH})
endif()
# and one for the validator
add_library(json-schema-validator
# the library
add_library(nlohmann_json_schema_validator
src/json-schema-draft7.json.cpp
src/json-uri.cpp
src/json-validator.cpp
src/string-format-check.cpp)
set_target_properties(json-schema-validator
target_include_directories(nlohmann_json_schema_validator
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>)
target_compile_features(nlohmann_json_schema_validator
PUBLIC
cxx_range_for) # for C++11 - flags
set_target_properties(nlohmann_json_schema_validator
PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1)
install(TARGETS json-schema-validator
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)
# here we decice how nlohmann::json is found and used to build this project
install(DIRECTORY src/
DESTINATION include
FILES_MATCHING PATTERN "*.h*")
# first, check whether a nlohmann_json::nlohmann_json target exists already
# -> we are used as a sub-directory from within another project
if(TARGET nlohmann_json::nlohmann_json)
message(STATUS "Found nlohmann_json::nlohmann_json-target - linking with it")
target_link_libraries(
nlohmann_json_schema_validator
PUBLIC nlohmann_json::nlohmann_json)
target_include_directories(json-schema-validator
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src)
elseif(TARGET nlohmann_json) # or nlohmann_json, we are used a sub-project next to nlohmann-json's git repo
message(STATUS "Found nlohmann_json-target - linking with it")
target_link_libraries(
nlohmann_json_schema_validator
PUBLIC nlohmann_json)
else()
if (NOT IS_ABSOLUTE ${nlohmann_json_DIR}) # make nlohmann_json_DIR absolute
get_filename_component(nlohmann_json_DIR
"${CMAKE_CURRENT_BINARY_DIR}/${nlohmann_json_DIR}"
REALPATH)
endif()
target_compile_features(json-schema-validator
PUBLIC
cxx_range_for) # for C++11 - flags
set(nlohmann_json_orignal_DIR ${nlohmann_json_DIR}) # save path for later use
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(json-schema-validator
# find nlohmann_json-cmake-package
find_package(nlohmann_json QUIET)
if(TARGET nlohmann_json::nlohmann_json)
message(STATUS "Found nlohmann_json-cmake-package - linking with it")
target_link_libraries(
nlohmann_json_schema_validator
PUBLIC nlohmann_json::nlohmann_json)
else()
# find nlohmann/json.hpp
message(STATUS ${nlohmann_json_orignal_DIR})
find_path(JSON_HPP nlohmann/json.hpp
PATHS ${nlohmann_json_orignal_DIR})
if(EXISTS ${JSON_HPP}/nlohmann/json.hpp)
message(STATUS "Found nlohmann/json.hpp in given path: ${JSON_HPP}")
target_include_directories(
nlohmann_json_schema_validator
PUBLIC $<BUILD_INTERFACE:${JSON_HPP}>)
else()
message(FATAL_ERROR "could not find nlohmann/json.hpp or any related cmake-target. Please set nlohmann_json_DIR.")
endif()
# nlohmann_json_DIR has to be reset (for later use in tests)
set(nlohmann_json_DIR ${JSON_HPP})
endif()
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(nlohmann_json_schema_validator
PRIVATE
-Wall -Wextra)
endif()
target_link_libraries(json-schema-validator
PUBLIC
json-hpp)
if(BUILD_SHARED_LIBS)
target_compile_definitions(json-schema-validator
target_compile_definitions(nlohmann_json_schema_validator
PRIVATE
-DJSON_SCHEMA_VALIDATOR_EXPORTS)
endif()
@ -83,38 +103,68 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
find_package(Boost COMPONENTS regex)
if(NOT Boost_FOUND)
message(STATUS "GCC less then 4.9 and boost-regex NOT found - no regex used")
target_compile_definitions(json-schema-validator PRIVATE -DJSON_SCHEMA_NO_REGEX)
target_compile_definitions(nlohmann_json_schema_validator PRIVATE -DJSON_SCHEMA_NO_REGEX)
else()
message(STATUS "GCC less then 4.9 and boost-regex FOUND - using boost::regex")
target_compile_definitions(json-schema-validator PRIVATE -DJSON_SCHEMA_BOOST_REGEX)
target_include_directories(json-schema-validator PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(json-schema-validator PRIVATE ${Boost_LIBRARIES})
target_compile_definitions(nlohmann_json_schema_validator PRIVATE -DJSON_SCHEMA_BOOST_REGEX)
target_include_directories(nlohmann_json_schema_validator PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(nlohmann_json_schema_validator PRIVATE ${Boost_LIBRARIES})
endif()
endif()
endif()
if(NOT TARGET json-hpp) # if used as a subdirectory do not install json-schema.hpp
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/json-schema.hpp
DESTINATION
${CMAKE_INSTALL_PREFIX}/include
)
endif()
install(TARGETS nlohmann_json_schema_validator
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)
install(FILES src/nlohmann/json-schema.hpp
DESTINATION include/nlohmann)
if (BUILD_EXAMPLES)
# simple json-schema-validator-executable
# simple nlohmann_json_schema_validator-executable
add_executable(json-schema-validate app/json-schema-validate.cpp)
target_link_libraries(json-schema-validate json-schema-validator)
target_link_libraries(json-schema-validate nlohmann_json_schema_validator)
add_executable(readme-json-schema app/readme.cpp)
target_link_libraries(readme-json-schema json-schema-validator)
target_link_libraries(readme-json-schema nlohmann_json_schema_validator)
endif()
#add_subdirectory(ng)
if (BUILD_TESTS)
# test-zone
enable_testing()
add_subdirectory(test)
endif()
#---------------------------------------------------------------------------##
# Set Up the Project Targets and Config Files for CMake
#---------------------------------------------------------------------------##
# Set the install path to the cmake config files
set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_PREFIX}/lib/cmake/${PROJECT_NAME})
# Create the ConfigVersion file
include(CMakePackageConfigHelpers) # write_basic_package_version_file
write_basic_package_version_file( ${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY SameMajorVersion)
# Get the relative path from the INSTALL_CMAKE_DIR to the include directory
file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${CMAKE_INSTALL_PREFIX}/include")
# Configure the Config.cmake file with the proper include directory
set(CONF_INCLUDE_DIRS "\${JSON_SCHEMA_VALIDATOR_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file(${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" @ONLY)
# Install the Config.cmake and ConfigVersion.cmake files
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}")
# Install Targets
install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION "${INSTALL_CMAKE_DIR}")

143
README.md
View File

@ -42,67 +42,138 @@ messages if a JSON-document/instance does not comply to its schema.
By default this is done with exceptions thrown at the users with a helpful
message telling what's wrong with the document while validating.
With **2.0.0** the user can pass a `json_schema::basic_error_handler`-derived
object along with the instance to validate to receive a callback each time a
validation error occurs and decide what to do (throwing, counting, collecting).
Starting with **2.0.0** the user can pass a `json_schema::basic_error_handler`-derived
object along with the instance to validate to receive a callback each time
a validation error occurs and decide what to do (throwing, counting, collecting).
Another goal was to use Niels Lohmann's JSON-library. This is why the validator
lives in his namespace.
# Weaknesses
Numerical validation uses nlohmann integer, unsigned and floating point types, depending on if
the schema type is "integer" or "number". Bignum (i.e. arbitrary precision and
range) is not supported at this time.
Numerical validation uses nlohmann-json's integer, unsigned and floating point
types, depending on if the schema type is "integer" or "number". Bignum
(i.e. arbitrary precision and range) is not supported at this time.
# How to use
# Building
The current state of the build-system needs at least version **3.6.0** of NLohmann's
JSON library. It is looking for the `json.hpp` within a `nlohmann/`-path.
This library is based on Niels Lohmann's JSON-library and thus has
a build-dependency to it.
When build the library you need to provide the path to the directory where the include-file
is located as `nlohmann/json.hpp`.
Currently at least version **3.6.0** of NLohmann's JSON library
is required.
## Build
Various methods using CMake can be used to build this project.
### Within a build-dir
## Build out-of-source
Do not run cmake inside the source-dir. Rather create a dedicated build-dir:
```Bash
git clone https://github.com/pboettch/json-schema-validator.git
cd json-schema-validator
mkdir build
cd build
cmake .. \
-DNLOHMANN_JSON_DIR=<path/to/>nlohmann/json.hpp \
-DJSON_SCHEMA_TEST_SUITE_PATH=<path/to/JSON-Schema-test-suite> # optional
make # install
cmake [..]
make
make install # if needed
ctest # run unit, non-regression and test-suite tests
```
### As a subdirectory from within
```CMake
# create an interface-target called json-hpp
add_library(json-hpp INTERFACE)
target_include_directories(json-hpp
INTERFACE
path/to/nlohmann/json.hpp)
## Building as shared library
# set this path to schema-test-suite to get tests compiled - optional
set(JSON_SCHEMA_TEST_SUITE_PATH "path/to/json-schema-test-suite")
enable_testing() # if you want to inherit tests
add_subdirectory(path-to-this-project json-schema-validator)
```
### Building a shared library
By default a static library is built. Shared libraries are generated by using
By default a static library is built. Shared libraries can be generated by using
the `BUILD_SHARED_LIBS`-cmake variable:
In your initial call to cmake simply add:
```bash
cmake -DBUILD_SHARED_LIBS=ON
cmake [..] -DBUILD_SHARED_LIBS=ON [..]
```
## Providing access to nlohmann-json
The CMake-file of this libraries tries several ways to ultimately include
`nlohmann/json.hpp`
During the cmake-configurate-step there are 3 tries done trying to
access nlohmann-json:
1. link with a nlohmann_json::nlohmann_json-target,
2. find the nlohmann_json-cmake-package and link with nlohmann_json::nlohmann_json-target or
3. find path to `nlohmann/json.hpp`.
1 is there to make it work when this project is added as
a sub-directory (via `add_subdirectory()`), 2 and 3 can be
assisted by setting the `nlohmann_json_DIR`-variable.
### Building as a CMake-subdirectory from within another project
Adding this library as a subdirectory to a parent project is one way of
building it.
If the parent project
- already used `find_package()` to find the CMake-package of nlohmann_json, method 1 will work.
- uses the git-repo of nlohmann_json as a subdirectory, method 1 will work.
- sets nlohmann_json_DIR, method 2 or 3 will work.
Afterwards a target called `nlohmann_json_schema_validator`
is available in order to compile and link.
### Building directly, finding a CMake-package. (short)
When nlohmann-json has been installed, it provides files which allows
CMake's `find_package()` to be used.
This library is using this mechanism if `nlohmann_json::nlohmann_json`-target
does not exist.
The variable `nlohmann_json_DIR` can be used to help `find_package()` find this package.
### Building directly: provide a path to where to find json.hpp
The last method before fataling out is by providing a path where the file json.hpp can be found.
The variable `nlohmann_json_DIR` has to be used to point to the path
where `json.hpp` is found in a subdirectory called `nlohmann`, e.g.:
`json.hpp` is located in `/path/to/nlohmann/json.hpp`. The `cmake`-command has to be run as follows:
```bash
cmake -Dnlohmann_json_DIR=/path/to [..]
```
### Method 1 - long version
Since version 2.1.0 this library can be installed and CMake-package-files will be
created accordingly. If the installation of nlohmann-json and this library
is done into default unix-system-paths CMake will be able to find this
library by simply doing:
```CMake
find_package(nlohmann_json REQUIRED)
find_package(nlohmann_json_schema_validator REQUIRED)
```
and
```CMake
target_link_libraries(<your-target> [..] nlohmann_json_schema_validator)
```
to build and link.
If a custom path has been used to install this library (and nlohmann-json), `find_package()`
needs a hint for where to find the package-files, it can be provided by setting the following variables
```CMake
cmake .. \
-Dnlohmann_json_DIR=<path/to/>lib/cmake/nlohmann_json \
-Dnlohmann_json_schema_validator_DIR:PATH=<path/to/>/lib/cmake/nlohmann_json_schema_validator
```
Note that if the this library is used as cmake-package, nlohmann-json also has
to be used a cmake-package.
## Code
See also `app/json-schema-validate.cpp`.
@ -111,7 +182,7 @@ See also `app/json-schema-validate.cpp`.
#include <iostream>
#include <iomanip>
#include "json-schema.hpp"
#include <nlohmann/json-schema.hpp>
using nlohmann::json;
using nlohmann::json_schema::json_validator;

View File

@ -6,7 +6,7 @@
* SPDX-License-Identifier: MIT
*
*/
#include <json-schema.hpp>
#include <nlohmann/json-schema.hpp>
#include <fstream>
#include <iostream>

View File

@ -1,7 +1,7 @@
#include <iostream>
#include <iomanip>
#include "json-schema.hpp"
#include <nlohmann/json-schema.hpp>
using nlohmann::json;
using nlohmann::json_schema::json_validator;

View File

@ -0,0 +1,13 @@
# Config file for the json-schema-validator
# It defines the following variables
# NLOHMANN_JSON_SCHEMA_VALIDATOR_INCLUDE_DIRS - include directories for json-schema-validator
# nlohmann_json_schema_validator - json-schema-validator library to link against
# Compute paths
get_filename_component(NLOHMANN_JSON_SCHEMA_VALIDATOR_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(NLOHMANN_JSON_SCHEMA_VALIDATOR_INCLUDE_DIRS @CONF_INCLUDE_DIRS@)
# 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")
endif()

View File

@ -6,7 +6,7 @@
* SPDX-License-Identifier: MIT
*
*/
#include "json-schema.hpp"
#include <nlohmann/json-schema.hpp>
#include <sstream>

View File

@ -6,7 +6,7 @@
* SPDX-License-Identifier: MIT
*
*/
#include <json-schema.hpp>
#include <nlohmann/json-schema.hpp>
#include <memory>
#include <set>

View File

@ -1,4 +1,4 @@
#include <json-schema.hpp>
#include <nlohmann/json-schema.hpp>
#include <algorithm>
#include <exception>

View File

@ -20,24 +20,24 @@ foreach(DIR ${TEST_DIRS})
endforeach()
add_executable(uri uri.cpp)
target_link_libraries(uri json-schema-validator)
target_link_libraries(uri nlohmann_json_schema_validator)
add_test(NAME uri COMMAND uri)
add_executable(errors errors.cpp)
target_link_libraries(errors json-schema-validator)
target_link_libraries(errors nlohmann_json_schema_validator)
add_test(NAME errors COMMAND errors)
add_executable(issue-70 issue-70.cpp)
target_link_libraries(issue-70 json-schema-validator)
target_link_libraries(issue-70 nlohmann_json_schema_validator)
add_test(NAME issue-70 COMMAND issue-70)
add_executable(issue-70-root-schema-constructor issue-70-root-schema-constructor.cpp)
target_link_libraries(issue-70-root-schema-constructor json-schema-validator)
target_link_libraries(issue-70-root-schema-constructor nlohmann_json_schema_validator)
add_test(NAME issue-70-root-schema-constructor COMMAND issue-70-root-schema-constructor)
# Unit test for string format checks
add_executable("string-format-check-test" "string-format-check-test.cpp")
target_include_directories("string-format-check-test" PRIVATE "${PROJECT_SOURCE_DIR}/src/")
target_link_libraries("string-format-check-test" json-schema-validator)
target_link_libraries("string-format-check-test" nlohmann_json_schema_validator)
add_test(NAME "string-format-check-test" COMMAND "string-format-check-test")

View File

@ -15,7 +15,7 @@ endif()
if(JSON_SCHEMA_TEST_SUITE_PATH)
# json-schema-validator-tester
add_executable(json-schema-test json-schema-test.cpp)
target_link_libraries(json-schema-test json-schema-validator)
target_link_libraries(json-schema-test nlohmann_json_schema_validator)
target_compile_definitions(json-schema-test
PRIVATE
JSON_SCHEMA_TEST_SUITE_PATH="${JSON_SCHEMA_TEST_SUITE_PATH}")

View File

@ -6,7 +6,7 @@
* SPDX-License-Identifier: MIT
*
*/
#include "json-schema.hpp"
#include <nlohmann/json-schema.hpp>
#include <fstream>
#include <iostream>

View File

@ -0,0 +1,15 @@
# Configure install script
configure_file(test.sh.in
${CMAKE_CURRENT_BINARY_DIR}/test.sh @ONLY)
get_filename_component(TEST_NAME
${CMAKE_CURRENT_SOURCE_DIR}
NAME)
# this build test only works, if nlohmann-json was found via a cmake-package
if(TARGET nlohmann_json::nlohmann_json)
add_test(NAME Build::${TEST_NAME}
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()

View File

@ -0,0 +1,34 @@
# This is a simple project that tests using cmake to load the installed libraries
cmake_minimum_required(VERSION 3.2)
project(cmake_install_test LANGUAGES CXX)
set(PROJECT_VERSION 1.0.0)
# Find the nlohmann_json and the validator package
set(CMAKE_FIND_DEBUG_MODE ON)
find_package(nlohmann_json REQUIRED)
find_package(nlohmann_json_schema_validator REQUIRED)
# Add simple json-schema-validator-executable
add_executable(json-schema-validate ${CMAKE_CURRENT_SOURCE_DIR}/../../../app/json-schema-validate.cpp)
target_link_libraries(json-schema-validate nlohmann_json_schema_validator)
enable_testing()
# Add built-in tests function needed for issues
set(PIPE_IN_TEST_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/../../test-pipe-in.sh)
function(add_test_simple_schema name schema instance)
add_test(
NAME ${name}
COMMAND ${PIPE_IN_TEST_SCRIPT}
$<TARGET_FILE:json-schema-validate>
${schema}
${instance}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endfunction()
# Run tests for issues 9, 12, 27, 48, 54
foreach(NUMBER "9" "12" "27" "48" "54")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../issue-${NUMBER}" "${CMAKE_CURRENT_BINARY_DIR}/issue-${NUMBER}" EXCLUDE_FROM_ALL)
endforeach()

55
test/cmake-install/test.sh.in Executable file
View File

@ -0,0 +1,55 @@
#!/bin/bash
## Configure, build, install, and test json-schema-validator with CMAKE
## This script is instantiated via configure_file() to run cmake the same the original build has been invoked.
set -xe
EXTRA_ARGS=$@
SRC_DIR=@PROJECT_SOURCE_DIR@
BUILD_DIR=@CMAKE_CURRENT_BINARY_DIR@/build-dir
INSTALL_DIR=@CMAKE_CURRENT_BINARY_DIR@/install-dir
NLOHMANN_JSON_DIR=@nlohmann_json_DIR@
TEST_SRC_DIR=@CMAKE_CURRENT_SOURCE_DIR@/project
cmake --version
# Clear out build directory
rm -rf ${BUILD_DIR}
# Create build-dir
mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}
# configure json-schema-validator
printf "\n-----------------------------------------------------------\n"
printf "Configuring, building, and installing json-schema-validator"
printf "\n-----------------------------------------------------------\n"
cmake \
-DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_DIR} \
-Dnlohmann_json_DIR:PATH=${NLOHMANN_JSON_DIR} \
${EXTRA_ARGS} \
${SRC_DIR}
CPU_COUNT=$(nproc)
# Build and install json-schema-validator
cmake --build . -- -j${CPU_COUNT}
cmake --build . --target install -- -j${CPU_COUNT}
# Make sure build directory is empty
rm -rf ./*
# configure test project
printf "\n-----------------------------------------------------------\n"
printf "Configuring, building, and running test project"
printf "\n-----------------------------------------------------------\n"
cmake \
-Dnlohmann_json_DIR:PATH=${NLOHMANN_JSON_DIR} \
-Dnlohmann_json_schema_validator_DIR:PATH=${INSTALL_DIR}/lib/cmake/nlohmann_json_schema_validator \
-DVALIDATOR_INSTALL_DIR:PATH=${INSTALL_DIR} \
${EXTRA_ARGS} \
${TEST_SRC_DIR}
# Build test project and test
cmake --build .
ctest --output-on-failure

View File

@ -1,4 +1,4 @@
#include <json-schema.hpp>
#include <nlohmann/json-schema.hpp>
#include <iostream>

View File

@ -1,6 +1,6 @@
#include <nlohmann/json.hpp>
#include "../src/json-schema.hpp"
#include <nlohmann/json-schema.hpp>
#include <iostream>

View File

@ -1,4 +1,4 @@
#include <json-schema.hpp>
#include <nlohmann/json-schema.hpp>
#include <iostream>

View File

@ -1,4 +1,4 @@
#include <json-schema.hpp>
#include <nlohmann/json-schema.hpp>
using nlohmann::json;
using nlohmann::json_schema::json_validator;

View File

@ -1,6 +1,6 @@
#include <iostream>
#include <json-schema.hpp>
#include <nlohmann/json-schema.hpp>
/** @return number of failed tests */
size_t

View File

@ -7,7 +7,7 @@
*
*/
#include <cstdlib>
#include <json-schema.hpp>
#include <nlohmann/json-schema.hpp>
#include <iostream>