adapt ci for FetchContent
This commit is contained in:
parent
fab8014020
commit
b5ad137556
@ -71,8 +71,8 @@ script:
|
||||
# Remove previous build and tests
|
||||
- rm -r build
|
||||
|
||||
# Compile and execute with Hunter package manager instead of using local json.hpp
|
||||
# Compile and execute with no nlohmann/json.hpp so it will fetch if
|
||||
- mkdir -p build && cd build
|
||||
- cmake .. -DHUNTER_ENABLED=ON ${CMAKE_OPTIONS} -GNinja && cmake --build . --config Release
|
||||
- cmake .. ${CMAKE_OPTIONS} -GNinja && cmake --build . --config Release
|
||||
- ctest -C Release -V -j
|
||||
- cd ..
|
||||
@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
option(JSON_VALIDATOR_BUILD_TESTS "Build tests" ON)
|
||||
option(JSON_VALIDATOR_BUILD_EXAMPLES "Build examples" ON)
|
||||
option(JSON_VALIDATOR_BUILD_TESTS "Build tests" OFF)
|
||||
option(JSON_VALIDATOR_BUILD_EXAMPLES "Build examples" OFF)
|
||||
|
||||
# the project
|
||||
project(nlohmann_json_schema_validator
|
||||
|
||||
40
README.md
40
README.md
@ -79,8 +79,6 @@ cmake_minimum_required(VERSION 3.16)
|
||||
include(FetchContent)
|
||||
|
||||
...
|
||||
set(JSON_VALIDATOR_BUILD_EXAMPLES OFF)
|
||||
set(JSON_VALIDATOR_BUILD_TESTS OFF)
|
||||
FetchContent_Declare(json_schema_validator
|
||||
GIT_REPOSITORY https://github.com/pboettch/json-schema-validator.git
|
||||
GIT_TAG v2.1.2)
|
||||
@ -107,25 +105,21 @@ is required.
|
||||
|
||||
Various methods using CMake can be used to build this project.
|
||||
|
||||
### Build out-of-source
|
||||
### Build
|
||||
|
||||
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
|
||||
# configure
|
||||
cmake -B build
|
||||
# configure (See options)
|
||||
cmake -B build
|
||||
|
||||
# build
|
||||
cmake --build build
|
||||
|
||||
# install if needed
|
||||
cmake --build build --target install
|
||||
|
||||
# run unit, non-regression and test-suite tests
|
||||
cd build
|
||||
ctest
|
||||
```
|
||||
|
||||
### Building as shared library
|
||||
@ -138,6 +132,34 @@ In your initial call to cmake simply add:
|
||||
cmake [..] -DBUILD_SHARED_LIBS=ON [..]
|
||||
```
|
||||
|
||||
### Building examples
|
||||
|
||||
In your initial call to cmake simply add:
|
||||
```bash
|
||||
cmake [..] -JSON_VALIDATOR_BUILD_EXAMPLES=ON [..]
|
||||
```
|
||||
|
||||
Run examples with:
|
||||
|
||||
```bash
|
||||
./build/format-json-schema [..]
|
||||
```
|
||||
|
||||
### Building tests
|
||||
|
||||
In your initial call to cmake simply add:
|
||||
```bash
|
||||
cmake [..] -JSON_VALIDATOR_BUILD_TESTS=ON [..]
|
||||
```
|
||||
|
||||
Once build run tests with:
|
||||
|
||||
```bash
|
||||
# run unit, non-regression and test-suite tests
|
||||
cd build
|
||||
ctest
|
||||
```
|
||||
|
||||
### Note about nlohmann-json integration
|
||||
|
||||
As `nlohmann-json` is a dependency, this library tries find it using `find_package`, if it's not found proper version of
|
||||
|
||||
@ -3,9 +3,6 @@ include(FetchContent)
|
||||
|
||||
project(stand-alone VERSION 1.0.0 LANGUAGES CXX)
|
||||
|
||||
set(JSON_VALIDATOR_BUILD_EXAMPLES OFF)
|
||||
set(JSON_VALIDATOR_BUILD_TESTS OFF)
|
||||
|
||||
FetchContent_Declare(json_schema_validator
|
||||
GIT_REPOSITORY https://github.com/vrince/json-schema-validator
|
||||
GIT_TAG 379cf8c2b4ad49fe3a21e926ffdf543b9e9da8df)
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
# Configure install script
|
||||
configure_file(test.sh.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/test.sh @ONLY)
|
||||
|
||||
get_filename_component(TEST_NAME
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
NAME)
|
||||
|
||||
|
||||
# this build test only works, if nlohmann-json was found via a cmake-package
|
||||
if(TARGET nlohmann_json::nlohmann_json)
|
||||
add_test(NAME Build::${TEST_NAME}
|
||||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test.sh
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
endif()
|
||||
@ -1,34 +0,0 @@
|
||||
# This is a simple project that tests using cmake to load the installed libraries
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
|
||||
project(cmake_install_test LANGUAGES CXX)
|
||||
|
||||
set(PROJECT_VERSION 1.0.0)
|
||||
|
||||
# Find the nlohmann_json and the validator package
|
||||
set(CMAKE_FIND_DEBUG_MODE ON)
|
||||
find_package(nlohmann_json REQUIRED)
|
||||
find_package(nlohmann_json_schema_validator REQUIRED)
|
||||
|
||||
# Add simple json-schema-validator-executable
|
||||
add_executable(json-schema-validate ${CMAKE_CURRENT_SOURCE_DIR}/../../../app/json-schema-validate.cpp)
|
||||
target_link_libraries(json-schema-validate nlohmann_json_schema_validator)
|
||||
|
||||
enable_testing()
|
||||
|
||||
# Add built-in tests function needed for issues
|
||||
set(PIPE_IN_TEST_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/../../test-pipe-in.sh)
|
||||
function(add_test_simple_schema name schema instance)
|
||||
add_test(
|
||||
NAME ${name}
|
||||
COMMAND ${PIPE_IN_TEST_SCRIPT}
|
||||
$<TARGET_FILE:json-schema-validate>
|
||||
${schema}
|
||||
${instance}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
endfunction()
|
||||
|
||||
# Run tests for issues 9, 12, 27, 48, 54
|
||||
foreach(NUMBER "9" "12" "27" "48" "54")
|
||||
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../issue-${NUMBER}" "${CMAKE_CURRENT_BINARY_DIR}/issue-${NUMBER}" EXCLUDE_FROM_ALL)
|
||||
endforeach()
|
||||
@ -1,55 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
## Configure, build, install, and test json-schema-validator with CMAKE
|
||||
## This script is instantiated via configure_file() to run cmake the same the original build has been invoked.
|
||||
|
||||
set -xe
|
||||
|
||||
EXTRA_ARGS=$@
|
||||
SRC_DIR=@PROJECT_SOURCE_DIR@
|
||||
BUILD_DIR=@CMAKE_CURRENT_BINARY_DIR@/build-dir
|
||||
INSTALL_DIR=@CMAKE_CURRENT_BINARY_DIR@/install-dir
|
||||
NLOHMANN_JSON_DIR=@nlohmann_json_DIR@
|
||||
TEST_SRC_DIR=@CMAKE_CURRENT_SOURCE_DIR@/project
|
||||
|
||||
cmake --version
|
||||
|
||||
# Clear out build directory
|
||||
rm -rf ${BUILD_DIR}
|
||||
# Create build-dir
|
||||
mkdir -p ${BUILD_DIR}
|
||||
cd ${BUILD_DIR}
|
||||
|
||||
# configure json-schema-validator
|
||||
printf "\n-----------------------------------------------------------\n"
|
||||
printf "Configuring, building, and installing json-schema-validator"
|
||||
printf "\n-----------------------------------------------------------\n"
|
||||
cmake \
|
||||
-DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_DIR} \
|
||||
-Dnlohmann_json_DIR:PATH=${NLOHMANN_JSON_DIR} \
|
||||
${EXTRA_ARGS} \
|
||||
${SRC_DIR}
|
||||
|
||||
CPU_COUNT=$(nproc)
|
||||
|
||||
# Build and install json-schema-validator
|
||||
cmake --build . -- -j${CPU_COUNT}
|
||||
cmake --build . --target install -- -j${CPU_COUNT}
|
||||
|
||||
# Make sure build directory is empty
|
||||
rm -rf ./*
|
||||
|
||||
# configure test project
|
||||
printf "\n-----------------------------------------------------------\n"
|
||||
printf "Configuring, building, and running test project"
|
||||
printf "\n-----------------------------------------------------------\n"
|
||||
cmake \
|
||||
-Dnlohmann_json_DIR:PATH=${NLOHMANN_JSON_DIR} \
|
||||
-Dnlohmann_json_schema_validator_DIR:PATH=${INSTALL_DIR}/lib/cmake/nlohmann_json_schema_validator \
|
||||
-DVALIDATOR_INSTALL_DIR:PATH=${INSTALL_DIR} \
|
||||
${EXTRA_ARGS} \
|
||||
${TEST_SRC_DIR}
|
||||
|
||||
# Build test project and test
|
||||
cmake --build .
|
||||
ctest --output-on-failure
|
||||
Loading…
Reference in New Issue
Block a user