prepend all cmake option with JSON_VALIDATOR_ (#179)
Co-authored-by: Thomas Vincent <tvincent@ei3.com>
This commit is contained in:
parent
d8467b7c08
commit
b1ef862832
@ -1,6 +1,10 @@
|
|||||||
# Add Hunter support (Disabled by default)
|
cmake_minimum_required(VERSION 3.2)
|
||||||
option(HUNTER_ENABLED "Enable Hunter package manager support" OFF)
|
|
||||||
if(HUNTER_ENABLED)
|
option(JSON_VALIDATOR_BUILD_TESTS "Build tests" ON)
|
||||||
|
option(JSON_VALIDATOR_BUILD_EXAMPLES "Build examples" ON)
|
||||||
|
option(JSON_VALIDATOR_HUNTER "Enable Hunter package manager support" OFF)
|
||||||
|
|
||||||
|
if(JSON_VALIDATOR_HUNTER)
|
||||||
include("cmake/HunterGate.cmake")
|
include("cmake/HunterGate.cmake")
|
||||||
HunterGate(
|
HunterGate(
|
||||||
URL "https://github.com/cpp-pm/hunter/archive/v0.23.262.tar.gz"
|
URL "https://github.com/cpp-pm/hunter/archive/v0.23.262.tar.gz"
|
||||||
@ -8,18 +12,13 @@ if(HUNTER_ENABLED)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# the project
|
||||||
project(nlohmann_json_schema_validator
|
project(nlohmann_json_schema_validator
|
||||||
LANGUAGES CXX)
|
LANGUAGES CXX)
|
||||||
|
|
||||||
set(PROJECT_VERSION 2.1.1)
|
set(PROJECT_VERSION 2.1.1)
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.2)
|
if(JSON_VALIDATOR_HUNTER)
|
||||||
|
|
||||||
option(BUILD_TESTS "Build tests" ON)
|
|
||||||
option(BUILD_EXAMPLES "Build examples" ON)
|
|
||||||
|
|
||||||
# Add nlohmann_json::nlohmann_json using Hunter package manager
|
|
||||||
if(HUNTER_ENABLED)
|
|
||||||
hunter_add_package(nlohmann_json)
|
hunter_add_package(nlohmann_json)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -52,11 +51,11 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(JSON_VALIDATOR_IS_TOP_LEVEL)
|
if(JSON_VALIDATOR_IS_TOP_LEVEL)
|
||||||
set(BUILD_TESTS ON)
|
set(JSON_VALIDATOR_BUILD_TESTS ON)
|
||||||
set(BUILD_EXAMPLES ON)
|
set(JSON_VALIDATOR_BUILD_EXAMPLES ON)
|
||||||
else()
|
else()
|
||||||
set(BUILD_TESTS OFF)
|
set(JSON_VALIDATOR_BUILD_TESTS OFF)
|
||||||
set(BUILD_EXAMPLES OFF)
|
set(JSON_VALIDATOR_BUILD_EXAMPLES OFF)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT TARGET nlohmann_json::nlohmann_json)
|
if(NOT TARGET nlohmann_json::nlohmann_json)
|
||||||
@ -105,7 +104,7 @@ install(TARGETS nlohmann_json_schema_validator
|
|||||||
install(FILES src/nlohmann/json-schema.hpp
|
install(FILES src/nlohmann/json-schema.hpp
|
||||||
DESTINATION include/nlohmann)
|
DESTINATION include/nlohmann)
|
||||||
|
|
||||||
if (BUILD_EXAMPLES)
|
if (JSON_VALIDATOR_BUILD_EXAMPLES)
|
||||||
# simple nlohmann_json_schema_validator-executable
|
# simple nlohmann_json_schema_validator-executable
|
||||||
add_executable(json-schema-validate app/json-schema-validate.cpp)
|
add_executable(json-schema-validate app/json-schema-validate.cpp)
|
||||||
target_link_libraries(json-schema-validate nlohmann_json_schema_validator)
|
target_link_libraries(json-schema-validate nlohmann_json_schema_validator)
|
||||||
@ -120,7 +119,7 @@ if (BUILD_EXAMPLES)
|
|||||||
DESTINATION bin)
|
DESTINATION bin)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (BUILD_TESTS)
|
if (JSON_VALIDATOR_BUILD_TESTS)
|
||||||
# test-zone
|
# test-zone
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
@ -137,7 +136,6 @@ install(EXPORT ${PROJECT_NAME}Targets
|
|||||||
FILE ${PROJECT_NAME}Targets.cmake
|
FILE ${PROJECT_NAME}Targets.cmake
|
||||||
DESTINATION "${INSTALL_CMAKE_DIR}")
|
DESTINATION "${INSTALL_CMAKE_DIR}")
|
||||||
|
|
||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
write_basic_package_version_file(
|
write_basic_package_version_file(
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||||
@ -145,7 +143,6 @@ write_basic_package_version_file(
|
|||||||
COMPATIBILITY SameMajorVersion
|
COMPATIBILITY SameMajorVersion
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
configure_package_config_file(
|
configure_package_config_file(
|
||||||
${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
|
${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||||
|
|||||||
@ -114,10 +114,10 @@ Otherwise, it calls `find_package` for nlohmann-json and requires nlohmann-json
|
|||||||
|
|
||||||
### Building with Hunter package manager
|
### Building with Hunter package manager
|
||||||
|
|
||||||
To enable access to nlohmann json library, Hunter can be used. Just run with HUNTER_ENABLED=ON option. No further dependencies needed
|
To enable access to nlohmann json library, Hunter can be used. Just run with `JSON_VALIDATOR_HUNTER=ON` option. No further dependencies needed
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cmake [..] -DHUNTER_ENABLED=ON [..]
|
cmake [..] -DJSON_VALIDATOR_HUNTER=ON [..]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Building as a CMake-subdirectory from within another project
|
### Building as a CMake-subdirectory from within another project
|
||||||
|
|||||||
@ -45,8 +45,8 @@ class JsonSchemaValidatorConan(ConanFile):
|
|||||||
def build(self):
|
def build(self):
|
||||||
cmake = CMake(self)
|
cmake = CMake(self)
|
||||||
cmake.definitions['nlohmann_json_DIR'] = os.path.join(self.deps_cpp_info['nlohmann_json'].rootpath, 'include')
|
cmake.definitions['nlohmann_json_DIR'] = os.path.join(self.deps_cpp_info['nlohmann_json'].rootpath, 'include')
|
||||||
cmake.definitions['BUILD_EXAMPLES'] = True
|
cmake.definitions['JSON_VALIDATOR_BUILD_EXAMPLES'] = True
|
||||||
cmake.definitions['BUILD_TESTS'] = False
|
cmake.definitions['JSON_VALIDATOR_BUILD_TESTS'] = False
|
||||||
cmake.configure()
|
cmake.configure()
|
||||||
cmake.build()
|
cmake.build()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user