parent
3893a2c3af
commit
ecaeea06bc
@ -121,6 +121,8 @@ access nlohmann-json:
|
||||
a sub-directory (via `add_subdirectory()`), 2 and 3 can be
|
||||
assisted by setting the `nlohmann_json_DIR`-variable.
|
||||
|
||||
For 1 there is an example of you to do in example/cmake-submodule.
|
||||
|
||||
### Building with Hunter package manager
|
||||
|
||||
To enable access to nlohmann json library, Hunter can be used. Just run with HUNTER_ENABLED=ON option. No further dependencies needed
|
||||
|
||||
24
example/cmake-submodule/CMakeLists.txt
Normal file
24
example/cmake-submodule/CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
|
||||
project(simple-json-validator-as-submodule-test)
|
||||
|
||||
# absolute-path
|
||||
set(PATH_TO_NLOHMANN_JSON_REPO $ENV{HOME}/devel/upstream/json)
|
||||
|
||||
# build shared library
|
||||
set(BUILD_SHARED_LIBS ON)
|
||||
|
||||
# JSON library
|
||||
option(JSON_BuildTests OFF)
|
||||
add_subdirectory(${PATH_TO_NLOHMANN_JSON_REPO}
|
||||
json-binary-dir
|
||||
EXCLUDE_FROM_ALL)
|
||||
|
||||
# JSON SCHEMA VALIDATOR library
|
||||
option(BUILD_TESTS OFF)
|
||||
add_subdirectory(../..
|
||||
json-validator-binary-dir
|
||||
EXCLUDE_FROM_ALL)
|
||||
|
||||
add_executable(validate validate.cpp)
|
||||
target_link_libraries(validate nlohmann_json_schema_validator)
|
||||
20
example/cmake-submodule/validate.cpp
Normal file
20
example/cmake-submodule/validate.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include <nlohmann/json-schema.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
nlohmann::json schema_json{{"type", "number"}};
|
||||
nlohmann::json_schema::json_validator validator;
|
||||
|
||||
validator.set_root_schema(schema_json);
|
||||
|
||||
validator.validate(1);
|
||||
try {
|
||||
validator.validate("\"1\"");
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "expected exception: " << e.what() << "\n";
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user