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>
35 lines
1.2 KiB
CMake
35 lines
1.2 KiB
CMake
# 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()
|