prepend all cmake option with JSON_VALIDATOR_ (#179)

Co-authored-by: Thomas Vincent <tvincent@ei3.com>
This commit is contained in:
vrince 2021-11-19 02:55:17 -05:00 committed by GitHub
parent d8467b7c08
commit b1ef862832
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 22 deletions

View File

@ -1,6 +1,10 @@
# Add Hunter support (Disabled by default)
option(HUNTER_ENABLED "Enable Hunter package manager support" OFF)
if(HUNTER_ENABLED)
cmake_minimum_required(VERSION 3.2)
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")
HunterGate(
URL "https://github.com/cpp-pm/hunter/archive/v0.23.262.tar.gz"
@ -8,18 +12,13 @@ if(HUNTER_ENABLED)
)
endif()
# the project
project(nlohmann_json_schema_validator
LANGUAGES CXX)
set(PROJECT_VERSION 2.1.1)
cmake_minimum_required(VERSION 3.2)
option(BUILD_TESTS "Build tests" ON)
option(BUILD_EXAMPLES "Build examples" ON)
# Add nlohmann_json::nlohmann_json using Hunter package manager
if(HUNTER_ENABLED)
if(JSON_VALIDATOR_HUNTER)
hunter_add_package(nlohmann_json)
endif()
@ -52,11 +51,11 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
endif()
if(JSON_VALIDATOR_IS_TOP_LEVEL)
set(BUILD_TESTS ON)
set(BUILD_EXAMPLES ON)
set(JSON_VALIDATOR_BUILD_TESTS ON)
set(JSON_VALIDATOR_BUILD_EXAMPLES ON)
else()
set(BUILD_TESTS OFF)
set(BUILD_EXAMPLES OFF)
set(JSON_VALIDATOR_BUILD_TESTS OFF)
set(JSON_VALIDATOR_BUILD_EXAMPLES OFF)
endif()
if(NOT TARGET nlohmann_json::nlohmann_json)
@ -105,7 +104,7 @@ install(TARGETS nlohmann_json_schema_validator
install(FILES src/nlohmann/json-schema.hpp
DESTINATION include/nlohmann)
if (BUILD_EXAMPLES)
if (JSON_VALIDATOR_BUILD_EXAMPLES)
# simple nlohmann_json_schema_validator-executable
add_executable(json-schema-validate app/json-schema-validate.cpp)
target_link_libraries(json-schema-validate nlohmann_json_schema_validator)
@ -120,7 +119,7 @@ if (BUILD_EXAMPLES)
DESTINATION bin)
endif()
if (BUILD_TESTS)
if (JSON_VALIDATOR_BUILD_TESTS)
# test-zone
enable_testing()
add_subdirectory(test)
@ -137,7 +136,6 @@ install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION "${INSTALL_CMAKE_DIR}")
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
@ -145,7 +143,6 @@ write_basic_package_version_file(
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake

View File

@ -114,10 +114,10 @@ Otherwise, it calls `find_package` for nlohmann-json and requires nlohmann-json
### 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
cmake [..] -DHUNTER_ENABLED=ON [..]
cmake [..] -DJSON_VALIDATOR_HUNTER=ON [..]
```
### Building as a CMake-subdirectory from within another project

View File

@ -45,8 +45,8 @@ class JsonSchemaValidatorConan(ConanFile):
def build(self):
cmake = CMake(self)
cmake.definitions['nlohmann_json_DIR'] = os.path.join(self.deps_cpp_info['nlohmann_json'].rootpath, 'include')
cmake.definitions['BUILD_EXAMPLES'] = True
cmake.definitions['BUILD_TESTS'] = False
cmake.definitions['JSON_VALIDATOR_BUILD_EXAMPLES'] = True
cmake.definitions['JSON_VALIDATOR_BUILD_TESTS'] = False
cmake.configure()
cmake.build()