fix / workaround for #79

This commit is contained in:
Patrick Boettcher 2020-01-27 11:06:24 +01:00 committed by Patrick Boettcher
parent 5976915897
commit 2969393afa

View File

@ -29,6 +29,10 @@ set_target_properties(nlohmann_json_schema_validator
VERSION ${PROJECT_VERSION} VERSION ${PROJECT_VERSION}
SOVERSION 1) SOVERSION 1)
# if used as a sub-directory, do not create install-rules -
# because of the dependency to nlohmann_json.
set(JSON_VALIDATOR_INSTALL ON)
# here we decice how nlohmann::json is found and used to build this project # here we decice how nlohmann::json is found and used to build this project
# first, check whether a nlohmann_json::nlohmann_json target exists already # first, check whether a nlohmann_json::nlohmann_json target exists already
@ -39,11 +43,15 @@ if(TARGET nlohmann_json::nlohmann_json)
nlohmann_json_schema_validator nlohmann_json_schema_validator
PUBLIC nlohmann_json::nlohmann_json) PUBLIC nlohmann_json::nlohmann_json)
set(JSON_VALIDATOR_INSTALL OFF)
elseif(TARGET nlohmann_json) # or nlohmann_json, we are used a sub-project next to nlohmann-json's git repo elseif(TARGET nlohmann_json) # or nlohmann_json, we are used a sub-project next to nlohmann-json's git repo
message(STATUS "Found nlohmann_json-target - linking with it") message(STATUS "Found nlohmann_json-target - linking with it")
target_link_libraries( target_link_libraries(
nlohmann_json_schema_validator nlohmann_json_schema_validator
PUBLIC nlohmann_json) PUBLIC nlohmann_json)
set(JSON_VALIDATOR_INSTALL OFF)
else() else()
if (NOT IS_ABSOLUTE ${nlohmann_json_DIR}) # make nlohmann_json_DIR absolute if (NOT IS_ABSOLUTE ${nlohmann_json_DIR}) # make nlohmann_json_DIR absolute
get_filename_component(nlohmann_json_DIR get_filename_component(nlohmann_json_DIR
@ -113,6 +121,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
endif() endif()
endif() endif()
if(JSON_VALIDATOR_INSTALL)
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
@ -121,6 +130,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)
endif()
if (BUILD_EXAMPLES) if (BUILD_EXAMPLES)
# simple nlohmann_json_schema_validator-executable # simple nlohmann_json_schema_validator-executable
@ -139,9 +149,9 @@ if (BUILD_TESTS)
enable_testing() enable_testing()
add_subdirectory(test) add_subdirectory(test)
endif() endif()
#---------------------------------------------------------------------------##
if(JSON_VALIDATOR_INSTALL)
# 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 # Set the install path to the cmake config files
set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_PREFIX}/lib/cmake/${PROJECT_NAME}) set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_PREFIX}/lib/cmake/${PROJECT_NAME})
@ -171,3 +181,4 @@ install(FILES
install(EXPORT ${PROJECT_NAME}Targets install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake FILE ${PROJECT_NAME}Targets.cmake
DESTINATION "${INSTALL_CMAKE_DIR}") DESTINATION "${INSTALL_CMAKE_DIR}")
endif()