This commit is contained in:
vadsul 2021-03-08 18:32:04 +01:00
parent 390b4629fc
commit 6ef6307552

View File

@ -19,9 +19,9 @@ option(BUILD_TESTS "Build tests" ON)
option(BUILD_EXAMPLES "Build examples" ON) option(BUILD_EXAMPLES "Build examples" ON)
# Add nlohmann_json::nlohmann_json using Hunter package manager # Add nlohmann_json::nlohmann_json using Hunter package manager
if(HUNTER_ENABLED) # if(HUNTER_ENABLED)
hunter_add_package(nlohmann_json) # hunter_add_package(nlohmann_json)
endif() # endif()
include_directories(../json/single_include) include_directories(../json/single_include)
@ -55,64 +55,72 @@ set(JSON_VALIDATOR_INSTALL ON)
# first, check whether a nlohmann_json::nlohmann_json target exists already # first, check whether a nlohmann_json::nlohmann_json target exists already
# -> we are used as a sub-directory from within another project # -> we are used as a sub-directory from within another project
if(TARGET nlohmann_json::nlohmann_json) # if(TARGET nlohmann_json::nlohmann_json)
message(STATUS "Found nlohmann_json::nlohmann_json-target - linking with it") # message(STATUS "Found nlohmann_json::nlohmann_json-target - linking with it")
target_link_libraries( # target_link_libraries(
nlohmann_json_schema_validator # nlohmann_json_schema_validator
PUBLIC nlohmann_json::nlohmann_json) # PUBLIC nlohmann_json::nlohmann_json)
set(JSON_VALIDATOR_INSTALL OFF) # set(JSON_VALIDATOR_INSTALL OFF)
set(BUILD_TESTS OFF) # set(BUILD_TESTS OFF)
set(BUILD_EXAMPLES OFF) # set(BUILD_EXAMPLES OFF)
elseif(TARGET nlohmann_json) # or nlohmann_json, we are used a sub-project next to nlohmann-json's git repo # else
if(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) nlohmann_json)
set(JSON_VALIDATOR_INSTALL OFF) set(JSON_VALIDATOR_INSTALL OFF)
set(BUILD_TESTS OFF) set(BUILD_TESTS OFF)
set(BUILD_EXAMPLES OFF) set(BUILD_EXAMPLES 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
"${CMAKE_CURRENT_BINARY_DIR}/${nlohmann_json_DIR}" # "${CMAKE_CURRENT_BINARY_DIR}/${nlohmann_json_DIR}"
REALPATH) # REALPATH)
endif() # endif()
set(nlohmann_json_DIR ../../${CMAKE_CURRENT_SOURCE_DIR}/external/json/) set(nlohmann_json_DIR ${PHASAR_SRC_DIR}/external/json/)
set(nlohmann_json_orignal_DIR ${nlohmann_json_DIR}) # save path for later use set(nlohmann_json_orignal_DIR ${nlohmann_json_DIR}) # save path for later use
message(1 ${nlohmann_json_DIR})
message(2 ${nlohmann_json_orignal_DIR})
# find nlohmann_json-cmake-package # find nlohmann_json-cmake-package
find_package(nlohmann_json QUIET) #find_package(nlohmann_json QUIET)
if(TARGET nlohmann_json::nlohmann_json) if(TARGET nlohmann_json::nlohmann_json)
message(STATUS "Found nlohmann_json-cmake-package - linking with it") message(STATUS "Found nlohmann_json-cmake-package - linking with it")
target_link_libraries( target_link_libraries(
nlohmann_json_schema_validator nlohmann_json_schema_validator
PUBLIC nlohmann_json)
nlohmann_json::nlohmann_json)
else()
# find nlohmann/json.hpp
message(STATUS ${nlohmann_json_orignal_DIR})
find_path(JSON_HPP nlohmann/json.hpp
PATHS ${nlohmann_json_orignal_DIR})
if(EXISTS ${JSON_HPP}/nlohmann/json.hpp)
message(STATUS "Found nlohmann/json.hpp in given path: ${JSON_HPP}")
target_include_directories(
nlohmann_json_schema_validator
PUBLIC $<BUILD_INTERFACE:${JSON_HPP}>)
# else() # else()
# message(FATAL_ERROR "could not find nlohmann/json.hpp or any related cmake-target. Please set nlohmann_json_DIR.")
endif()
# nlohmann_json_DIR has to be reset (for later use in tests) # # find nlohmann/json.hpp
set(nlohmann_json_DIR ${JSON_HPP})
# message(STATUS ${nlohmann_json_orignal_DIR})
# # find_path(JSON_HPP nlohmann/json.hpp
# # ${nlohmann_json_orignal_DIR})
# set(JSON_HPP=${nlohmann_json_orignal_DIR})
# message(HIIII ${JSON_HPP})
# # if(EXISTS ${JSON_HPP}/nlohmann/json.hpp)
# # message(STATUS "Found nlohmann/json.hpp in given path: ${JSON_HPP}")
# # target_include_directories(
# # nlohmann_json_schema_validator
# # PUBLIC $<BUILD_INTERFACE:${JSON_HPP}>)
# # else()
# # message(FATAL_ERROR "could not find nlohmann/json.hpp or any related cmake-target. Please set nlohmann_json_DIR.")
# # endif()
# # nlohmann_json_DIR has to be reset (for later use in tests)
# set(nlohmann_json_DIR ${JSON_HPP})
# message(HHHH ${nlohmann_json_DIR})
endif() endif()
endif() endif()
@ -156,6 +164,10 @@ if(JSON_VALIDATOR_INSTALL)
DESTINATION include/nlohmann) DESTINATION include/nlohmann)
endif() endif()
#message(HERE IT IS)
#message(${nlohmann_json_DIR})
#message(${JSON_HPP})
if (BUILD_EXAMPLES) if (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)
@ -171,11 +183,11 @@ if (BUILD_EXAMPLES)
DESTINATION bin) DESTINATION bin)
endif() endif()
if (BUILD_TESTS) # if (BUILD_TESTS)
# test-zone # # test-zone
enable_testing() # enable_testing()
add_subdirectory(test) # add_subdirectory(test)
endif() # endif()
if(JSON_VALIDATOR_INSTALL) if(JSON_VALIDATOR_INSTALL)
# Set Up the Project Targets and Config Files for CMake # Set Up the Project Targets and Config Files for CMake