diff --git a/README.md b/README.md index 79d0d4c..5794d2a 100644 --- a/README.md +++ b/README.md @@ -13,92 +13,47 @@ Niels Lohmann et al develop a great JSON parser for C++ called [JSON for Modern C++](https://github.com/nlohmann/json). This validator is based on this library, hence the name. -## Building +## Getting started -This library is based on Niels Lohmann's JSON-library and thus has -a build-dependency to it. +Currently, this package only offers a C++ library interface, and is only +available via cmake's `FetchContent` and conan. It is highly recommended +to use cmake to link to this library -Currently at least version **3.6.0** of NLohmann's JSON library -is required. +Dependencies: -Various methods using CMake can be used to build this project. +- NLohmann's Json library: At least **3.6.0** + (See Github actions for officially tested versions) -### Build out-of-source +### CMake configuration -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 [..] -make -make install # if needed -ctest # run unit, non-regression and test-suite tests +Bellow is a minimum cmake configuration file using `FetchContent`: + +```cmake +cmake_minimum_required(VERSION 3.11) + +project(example) + +include(FetchContent) + +FetchContent_Declare(nlohmann_json_schema_validator + GIT_REPOSITORY pboettch/json-schema-validator + # Please use a specific version tag + GIT_TAG main + ) +FetchContent_MakeAvailable(nlohmann_json_schema_validator) + +add_executable(example main.cpp) +target_link_libraries(example PRIVATE nlohmann_json_schema_validator::validator) ``` -### Building as shared library + -By default a static library is built. Shared libraries can be generated by using -the `BUILD_SHARED_LIBS`-cmake variable: +For more details about the available cmake options and recommended configurations +see [docs/cmake](docs/cmake/index.md) -In your initial call to cmake simply add: - -```bash -cmake [..] -DBUILD_SHARED_LIBS=ON [..] -``` - -### nlohmann-json integration - -As nlohmann-json is a dependency, this library tries find it. - -The cmake-configuration first checks if nlohmann-json is available as a cmake-target. This may be the case, because it is used as a submodule in a super-project which already provides and uses nlohmann-json. -Otherwise, it calls `find_package` for nlohmann-json and requires nlohmann-json to be installed on the system. - -#### Building with Hunter package manager - -To enable access to nlohmann json library, Hunter can be used. Just run with `JSON_VALIDATOR_HUNTER=ON` option. No further dependencies needed - -```bash -cmake [..] -DJSON_VALIDATOR_HUNTER=ON [..] -``` - -#### 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 or includes it as a submodule likewise. - -#### 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. - -#### Install - -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_schema_validator REQUIRED) -``` - -and - -```CMake -target_link_libraries( [..] nlohmann_json_schema_validator) -``` - -to build and link. - -### Code +### Api example See also `app/json-schema-validate.cpp`. diff --git a/docs/cmake/index.md b/docs/cmake/index.md new file mode 100644 index 0000000..99113ad --- /dev/null +++ b/docs/cmake/index.md @@ -0,0 +1,16 @@ +# CMake configuration guide + +:::{toctree} +--- +maxdepth: 2 +glob: true +hidden: true +--- +::: + +:::{include} ../../README.md +--- +start-after: +end-before: +--- +::: diff --git a/docs/index.md b/docs/index.md index dfa05c5..8ae5565 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3,14 +3,13 @@ :::{toctree} --- maxdepth: 2 -titlesonly: true -caption: Contents glob: true hidden: true --- CONTRIBUTING changelog roadmap +cmake/index.md ::: :::{include} ../README.md