cmake: allow this project to be used as a cmake-subdirectory
Needs to have a json-hpp-target-available.
This commit is contained in:
parent
94b7e44dfa
commit
e0a69cff39
@ -2,20 +2,23 @@ project(json-schema-validator CXX)
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.2)
|
cmake_minimum_required(VERSION 3.2)
|
||||||
|
|
||||||
|
# if used as a subdirectory just define a json-hpp-target (INTERFACE)
|
||||||
|
if(NOT TARGET json-hpp)
|
||||||
# find nlohmann's json.hpp
|
# find nlohmann's json.hpp
|
||||||
find_path(NLOHMANN_JSON_DIR
|
find_path(NLOHMANN_JSON_DIR
|
||||||
NAMES
|
NAMES
|
||||||
json.hpp)
|
json.hpp)
|
||||||
|
|
||||||
if(NOT NLOHMANN_JSON_DIR)
|
if(NOT NLOHMANN_JSON_DIR)
|
||||||
message(FATAL_ERROR "please set NLOHMANN_JSON_DIR to a path in which NLohmann's json.hpp can be found.")
|
message(FATAL_ERROR "please set NLOHMANN_JSON_DIR to a path in which NLohmann's json.hpp can be found.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# create an interface-library for simple linking
|
# create an interface-library for simple cmake-linking
|
||||||
add_library(json INTERFACE)
|
add_library(json-hpp INTERFACE)
|
||||||
target_include_directories(json
|
target_include_directories(json-hpp
|
||||||
INTERFACE
|
INTERFACE
|
||||||
${NLOHMANN_JSON_DIR})
|
${NLOHMANN_JSON_DIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
# and one for the validator
|
# and one for the validator
|
||||||
add_library(json-schema-validator INTERFACE)
|
add_library(json-schema-validator INTERFACE)
|
||||||
@ -27,7 +30,7 @@ target_compile_options(json-schema-validator
|
|||||||
-Wall -Wextra) # bad, better use something else based on compiler type
|
-Wall -Wextra) # bad, better use something else based on compiler type
|
||||||
target_link_libraries(json-schema-validator
|
target_link_libraries(json-schema-validator
|
||||||
INTERFACE
|
INTERFACE
|
||||||
json)
|
json-hpp)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
FILES
|
FILES
|
||||||
@ -44,6 +47,7 @@ target_link_libraries(json-schema-validate json-schema-validator)
|
|||||||
add_executable(json-schema-test app/json-schema-test.cpp)
|
add_executable(json-schema-test app/json-schema-test.cpp)
|
||||||
target_link_libraries(json-schema-test json-schema-validator)
|
target_link_libraries(json-schema-test json-schema-validator)
|
||||||
|
|
||||||
|
# test-zone
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
# find schema-test-suite
|
# find schema-test-suite
|
||||||
@ -63,7 +67,7 @@ if(JSON_SCHEMA_TEST_SUITE_PATH)
|
|||||||
)
|
)
|
||||||
endforeach()
|
endforeach()
|
||||||
else()
|
else()
|
||||||
message(STATUS "Please test JSON_SCHEMA_TEST_SUITE_PATH to a path in which you've cloned JSON-Schema-Test-Suite (github.com/json-schema-org/JSON-Schema-Test-Suite).")
|
message(STATUS "Consider setting JSON_SCHEMA_TEST_SUITE_PATH to a path in which JSON-Schema-Test-Suite is located (github.com/json-schema-org/JSON-Schema-Test-Suite).")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
18
README.md
18
README.md
@ -14,7 +14,7 @@ C++](https://github.com/nlohmann/json). This validator is based on this
|
|||||||
library, hence the name.
|
library, hence the name.
|
||||||
|
|
||||||
The name is for the moment purely marketing, because there is, IMHO, not much
|
The name is for the moment purely marketing, because there is, IMHO, not much
|
||||||
modern C++ inside.
|
modern C++ inside. But I think the whole thing could be rewritten mode "modern".
|
||||||
|
|
||||||
External documentation is missing as well. However the API of the validator
|
External documentation is missing as well. However the API of the validator
|
||||||
will be rather simple.
|
will be rather simple.
|
||||||
@ -23,6 +23,8 @@ will be rather simple.
|
|||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
|
Directly
|
||||||
|
|
||||||
```Bash
|
```Bash
|
||||||
git clone https://github.com/pboettch/json-schema-validator.git
|
git clone https://github.com/pboettch/json-schema-validator.git
|
||||||
cd json-schema-validator
|
cd json-schema-validator
|
||||||
@ -32,6 +34,20 @@ cmake .. \
|
|||||||
-DNLOHMANN_JSON_DIR=<path/to/json.hpp> \
|
-DNLOHMANN_JSON_DIR=<path/to/json.hpp> \
|
||||||
-DJSON_SCHEMA_TEST_SUITE_PATH=<path/to/JSON-Schema-test-suite> # optional
|
-DJSON_SCHEMA_TEST_SUITE_PATH=<path/to/JSON-Schema-test-suite> # optional
|
||||||
make # install
|
make # install
|
||||||
|
ctest # if test-suite has been given
|
||||||
|
```
|
||||||
|
or from another CMakeLists.txt as a subdirectory:
|
||||||
|
|
||||||
|
```CMake
|
||||||
|
# create an interface-target called json-hpp
|
||||||
|
add_library(json-hpp INTERFACE)
|
||||||
|
target_include_directories(json-hpp
|
||||||
|
INTERFACE
|
||||||
|
path/to/json.hpp)
|
||||||
|
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)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Code
|
## Code
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user