This commit is contained in:
Trevor Muraro 2021-11-18 17:03:11 -08:00 committed by Thomas Vincent
parent 98a98268c6
commit 69184eb1e5

View File

@ -1,9 +1,16 @@
cmake_minimum_required(VERSION 3.2) cmake_minimum_required(VERSION 3.2)
option(JSON_VALIDATOR_BUILD_TESTS "Build tests" ON) # disable tests and examples if project is not super project
option(JSON_VALIDATOR_BUILD_EXAMPLES "Build examples" ON) set(JSON_VALIDATOR_IS_TOP_LEVEL OFF)
option(JSON_VALIDATOR_INSTALL "Install" ON) if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
option(JSON_VALIDATOR_HUNTER "Enable Hunter package manager" OFF) # I am top-level project.
set(JSON_VALIDATOR_IS_TOP_LEVEL ON)
endif()
option(JSON_VALIDATOR_BUILD_TESTS "Build tests" ${JSON_VALIDATOR_IS_TOP_LEVEL})
option(JSON_VALIDATOR_BUILD_EXAMPLES "Build examples" ${JSON_VALIDATOR_IS_TOP_LEVEL})
option(JSON_VALIDATOR_INSTALL "Install CMake targets during install step." ${JSON_VALIDATOR_IS_TOP_LEVEL})
option(JSON_VALIDATOR_HUNTER "Enable Hunter package manager support" OFF)
if(JSON_VALIDATOR_HUNTER) if(JSON_VALIDATOR_HUNTER)
include("cmake/HunterGate.cmake") include("cmake/HunterGate.cmake")
@ -45,18 +52,6 @@ set_target_properties(nlohmann_json_schema_validator
VERSION ${PROJECT_VERSION} VERSION ${PROJECT_VERSION}
SOVERSION 1) SOVERSION 1)
# disable tests and examples if project is not super project
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
# I am top-level project.
set(JSON_VALIDATOR_IS_TOP_LEVEL TRUE)
endif()
if(NOT JSON_VALIDATOR_IS_TOP_LEVEL)
set(JSON_VALIDATOR_BUILD_TESTS OFF)
set(JSON_VALIDATOR_BUILD_EXAMPLES OFF)
set(JSON_VALIDATOR_INSTALL OFF)
endif()
if(NOT TARGET nlohmann_json::nlohmann_json) if(NOT TARGET nlohmann_json::nlohmann_json)
find_package(nlohmann_json REQUIRED) find_package(nlohmann_json REQUIRED)
endif() endif()
@ -104,9 +99,6 @@ if (JSON_VALIDATOR_BUILD_EXAMPLES)
add_executable(format-json-schema app/format.cpp) add_executable(format-json-schema app/format.cpp)
target_link_libraries(format-json-schema nlohmann_json_schema_validator) target_link_libraries(format-json-schema nlohmann_json_schema_validator)
install(TARGETS json-schema-validate readme-json-schema
DESTINATION bin)
endif() endif()
if (JSON_VALIDATOR_BUILD_TESTS) if (JSON_VALIDATOR_BUILD_TESTS)
@ -115,8 +107,7 @@ if (JSON_VALIDATOR_BUILD_TESTS)
add_subdirectory(test) add_subdirectory(test)
endif() endif()
if (JSON_VALIDATOR_INSTALL) if(JSON_VALIDATOR_INSTALL)
# add install target
install(TARGETS nlohmann_json_schema_validator install(TARGETS nlohmann_json_schema_validator
EXPORT ${PROJECT_NAME}Targets EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION lib LIBRARY DESTINATION lib
@ -126,7 +117,13 @@ if (JSON_VALIDATOR_INSTALL)
install(FILES src/nlohmann/json-schema.hpp install(FILES src/nlohmann/json-schema.hpp
DESTINATION include/nlohmann) DESTINATION include/nlohmann)
if (JSON_VALIDATOR_BUILD_EXAMPLES)
install(TARGETS json-schema-validate readme-json-schema format-json-schema
DESTINATION bin)
endif()
# Set Up the Project Targets and Config Files for CMake # Set Up the Project Targets and Config Files for CMake
# Set the install path to the cmake config files (Relative, so install works correctly under Hunter as well) # Set the install path to the cmake config files (Relative, so install works correctly under Hunter as well)
set(INSTALL_CMAKE_DIR "lib/cmake/${PROJECT_NAME}") set(INSTALL_CMAKE_DIR "lib/cmake/${PROJECT_NAME}")
set(INSTALL_CMAKEDIR_ROOT share/cmake) set(INSTALL_CMAKEDIR_ROOT share/cmake)