Now when json-schema-validator is installed CMake config files are installed in the lib/cmake/json-schema-validator directory. The install json-schema-validatorTargets.cmake file properly imports the json-hpp and json-schema-validator libraries. The install json-schema-validatorConfig.cmake file is used by CMake find_package function to include the json-schema-validatorTargets.cmake file and to set the variable JSON_SCHEMA_VALIDATOR_INCLUDE_DIRS to the install include directory. To use find_package to find the json-schema-validator simply include. A new test (test_cmake_install) has been added. When NLohmann's JSON is install with CMake, it follows a certain naming convention. As we learned to do proper CMake-install thanks to @lkersting's work this project now adapts to the way NLohmann is doing it. Namely: - json-schema.hpp is now located (and installed) in a nlohmann/-subdirectory - the CMake library and project's name is now nlohmann_json_schema_validator Instead of doing non-standard acrobatics to find the json.hpp now find_package is used in order to find NLohmann's package Co-Authored-By: Patrick Boettcher <p@yai.se>
56 lines
1.7 KiB
Bash
Executable File
56 lines
1.7 KiB
Bash
Executable File
#!/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
|