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,21 +2,24 @@ project(json-schema-validator CXX)
|
||||
|
||||
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_path(NLOHMANN_JSON_DIR
|
||||
NAMES
|
||||
json.hpp)
|
||||
find_path(NLOHMANN_JSON_DIR
|
||||
NAMES
|
||||
json.hpp)
|
||||
|
||||
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.")
|
||||
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.")
|
||||
endif()
|
||||
|
||||
# create an interface-library for simple cmake-linking
|
||||
add_library(json-hpp INTERFACE)
|
||||
target_include_directories(json-hpp
|
||||
INTERFACE
|
||||
${NLOHMANN_JSON_DIR})
|
||||
endif()
|
||||
|
||||
# create an interface-library for simple linking
|
||||
add_library(json INTERFACE)
|
||||
target_include_directories(json
|
||||
INTERFACE
|
||||
${NLOHMANN_JSON_DIR})
|
||||
|
||||
# and one for the validator
|
||||
add_library(json-schema-validator INTERFACE)
|
||||
target_include_directories(json-schema-validator
|
||||
@ -27,7 +30,7 @@ target_compile_options(json-schema-validator
|
||||
-Wall -Wextra) # bad, better use something else based on compiler type
|
||||
target_link_libraries(json-schema-validator
|
||||
INTERFACE
|
||||
json)
|
||||
json-hpp)
|
||||
|
||||
install(
|
||||
FILES
|
||||
@ -44,6 +47,7 @@ target_link_libraries(json-schema-validate json-schema-validator)
|
||||
add_executable(json-schema-test app/json-schema-test.cpp)
|
||||
target_link_libraries(json-schema-test json-schema-validator)
|
||||
|
||||
# test-zone
|
||||
enable_testing()
|
||||
|
||||
# find schema-test-suite
|
||||
@ -63,7 +67,7 @@ if(JSON_SCHEMA_TEST_SUITE_PATH)
|
||||
)
|
||||
endforeach()
|
||||
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()
|
||||
|
||||
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
will be rather simple.
|
||||
@ -23,6 +23,8 @@ will be rather simple.
|
||||
|
||||
## Build
|
||||
|
||||
Directly
|
||||
|
||||
```Bash
|
||||
git clone https://github.com/pboettch/json-schema-validator.git
|
||||
cd json-schema-validator
|
||||
@ -32,6 +34,20 @@ cmake .. \
|
||||
-DNLOHMANN_JSON_DIR=<path/to/json.hpp> \
|
||||
-DJSON_SCHEMA_TEST_SUITE_PATH=<path/to/JSON-Schema-test-suite> # optional
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user