Simplify cmake documentation
Signed-off-by: Cristian Le <git@lecris.dev>
This commit is contained in:
parent
57a4172ee8
commit
f5d730fb66
107
README.md
107
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
|
C++](https://github.com/nlohmann/json). This validator is based on this
|
||||||
library, hence the name.
|
library, hence the name.
|
||||||
|
|
||||||
## Building
|
## Getting started
|
||||||
|
|
||||||
This library is based on Niels Lohmann's JSON-library and thus has
|
Currently, this package only offers a C++ library interface, and is only
|
||||||
a build-dependency to it.
|
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
|
Dependencies:
|
||||||
is required.
|
|
||||||
|
|
||||||
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:
|
<!-- SHINX-CMAKE-START -->
|
||||||
|
|
||||||
```Bash
|
Bellow is a minimum cmake configuration file using `FetchContent`:
|
||||||
git clone https://github.com/pboettch/json-schema-validator.git
|
|
||||||
cd json-schema-validator
|
```cmake
|
||||||
mkdir build
|
cmake_minimum_required(VERSION 3.11)
|
||||||
cd build
|
|
||||||
cmake [..]
|
project(example)
|
||||||
make
|
|
||||||
make install # if needed
|
include(FetchContent)
|
||||||
ctest # run unit, non-regression and test-suite tests
|
|
||||||
|
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
|
<!-- SHINX-CMAKE-END -->
|
||||||
|
|
||||||
By default a static library is built. Shared libraries can be generated by using
|
For more details about the available cmake options and recommended configurations
|
||||||
the `BUILD_SHARED_LIBS`-cmake variable:
|
see [docs/cmake](docs/cmake/index.md)
|
||||||
|
|
||||||
In your initial call to cmake simply add:
|
### Api example
|
||||||
|
|
||||||
```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(<your-target> [..] nlohmann_json_schema_validator)
|
|
||||||
```
|
|
||||||
|
|
||||||
to build and link.
|
|
||||||
|
|
||||||
### Code
|
|
||||||
|
|
||||||
See also `app/json-schema-validate.cpp`.
|
See also `app/json-schema-validate.cpp`.
|
||||||
|
|
||||||
|
|||||||
16
docs/cmake/index.md
Normal file
16
docs/cmake/index.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# CMake configuration guide
|
||||||
|
|
||||||
|
:::{toctree}
|
||||||
|
---
|
||||||
|
maxdepth: 2
|
||||||
|
glob: true
|
||||||
|
hidden: true
|
||||||
|
---
|
||||||
|
:::
|
||||||
|
|
||||||
|
:::{include} ../../README.md
|
||||||
|
---
|
||||||
|
start-after: <!-- SHINX-CMAKE-START -->
|
||||||
|
end-before: <!-- SHINX-CMAKE-END -->
|
||||||
|
---
|
||||||
|
:::
|
||||||
@ -3,14 +3,13 @@
|
|||||||
:::{toctree}
|
:::{toctree}
|
||||||
---
|
---
|
||||||
maxdepth: 2
|
maxdepth: 2
|
||||||
titlesonly: true
|
|
||||||
caption: Contents
|
|
||||||
glob: true
|
glob: true
|
||||||
hidden: true
|
hidden: true
|
||||||
---
|
---
|
||||||
CONTRIBUTING
|
CONTRIBUTING
|
||||||
changelog
|
changelog
|
||||||
roadmap
|
roadmap
|
||||||
|
cmake/index.md
|
||||||
:::
|
:::
|
||||||
|
|
||||||
:::{include} ../README.md
|
:::{include} ../README.md
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user