2018-12-31 18:42:09 +01:00
|
|
|
cmake_minimum_required(VERSION 3.1)
|
2015-04-26 22:47:40 +02:00
|
|
|
|
2017-07-29 11:59:09 +02:00
|
|
|
##
|
|
|
|
## PROJECT
|
|
|
|
## name and version
|
|
|
|
##
|
2018-12-21 23:52:29 +01:00
|
|
|
project(nlohmann_json VERSION 3.5.0 LANGUAGES CXX)
|
2015-04-26 22:47:40 +02:00
|
|
|
|
2017-08-14 20:45:33 +02:00
|
|
|
##
|
|
|
|
## INCLUDE
|
|
|
|
##
|
|
|
|
##
|
|
|
|
include(ExternalProject)
|
|
|
|
|
2017-07-29 11:59:09 +02:00
|
|
|
##
|
|
|
|
## OPTIONS
|
|
|
|
##
|
2017-12-20 17:54:45 +01:00
|
|
|
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ON)
|
2018-01-13 13:07:03 +01:00
|
|
|
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." OFF)
|
2016-05-08 17:30:24 +02:00
|
|
|
|
2017-07-29 11:59:09 +02:00
|
|
|
##
|
|
|
|
## CONFIGURATION
|
|
|
|
##
|
|
|
|
set(NLOHMANN_JSON_TARGET_NAME ${PROJECT_NAME})
|
2018-04-09 17:31:25 +02:00
|
|
|
set(NLOHMANN_JSON_CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}"
|
|
|
|
CACHE INTERNAL "")
|
2017-07-29 11:59:09 +02:00
|
|
|
set(NLOHMANN_JSON_INCLUDE_INSTALL_DIR "include")
|
|
|
|
set(NLOHMANN_JSON_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
|
|
|
|
set(NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in")
|
2018-04-09 17:32:18 +02:00
|
|
|
set(NLOHMANN_JSON_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
2017-07-29 11:59:09 +02:00
|
|
|
set(NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
|
|
|
|
set(NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake")
|
2018-04-09 17:32:18 +02:00
|
|
|
set(NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")
|
2015-04-26 22:47:40 +02:00
|
|
|
|
2018-01-13 13:07:03 +01:00
|
|
|
if (JSON_MultipleHeaders)
|
2018-01-29 11:21:11 +01:00
|
|
|
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/")
|
2018-02-10 14:46:39 +01:00
|
|
|
message(STATUS "Using the multi-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
|
2018-01-13 13:07:03 +01:00
|
|
|
else()
|
2018-01-29 11:21:11 +01:00
|
|
|
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/single_include/")
|
2018-02-10 14:46:39 +01:00
|
|
|
message(STATUS "Using the single-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
|
2018-01-13 13:07:03 +01:00
|
|
|
endif()
|
|
|
|
|
2017-07-29 11:59:09 +02:00
|
|
|
##
|
|
|
|
## TARGET
|
|
|
|
## create target and add include path
|
|
|
|
##
|
|
|
|
add_library(${NLOHMANN_JSON_TARGET_NAME} INTERFACE)
|
2018-04-09 17:32:18 +02:00
|
|
|
add_library(${PROJECT_NAME}::${NLOHMANN_JSON_TARGET_NAME} ALIAS ${NLOHMANN_JSON_TARGET_NAME})
|
2019-01-16 14:21:49 +01:00
|
|
|
if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
|
|
|
|
target_compile_features(${NLOHMANN_JSON_TARGET_NAME} INTERFACE cxx_range_for)
|
|
|
|
else()
|
|
|
|
target_compile_features(${NLOHMANN_JSON_TARGET_NAME} INTERFACE cxx_std_11)
|
|
|
|
endif()
|
2018-03-27 18:51:30 +02:00
|
|
|
|
2017-07-29 11:59:09 +02:00
|
|
|
target_include_directories(
|
|
|
|
${NLOHMANN_JSON_TARGET_NAME}
|
2017-12-05 11:27:03 +01:00
|
|
|
INTERFACE
|
2018-01-29 11:21:11 +01:00
|
|
|
$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_BUILD_DIR}>
|
2017-12-05 11:27:03 +01:00
|
|
|
$<INSTALL_INTERFACE:include>
|
2017-07-29 11:59:09 +02:00
|
|
|
)
|
2017-11-26 10:31:33 +01:00
|
|
|
|
2018-04-08 21:46:25 +02:00
|
|
|
## add debug view definition file for msvc (natvis)
|
2018-04-07 13:15:44 +02:00
|
|
|
if (MSVC)
|
2017-11-30 13:26:45 +01:00
|
|
|
set(NLOHMANN_ADD_NATVIS TRUE)
|
|
|
|
set(NLOHMANN_NATVIS_FILE "nlohmann_json.natvis")
|
2017-11-28 23:43:39 +01:00
|
|
|
target_sources(
|
2018-11-02 09:35:17 +01:00
|
|
|
${NLOHMANN_JSON_TARGET_NAME}
|
|
|
|
INTERFACE
|
2017-11-30 13:26:45 +01:00
|
|
|
$<INSTALL_INTERFACE:${NLOHMANN_NATVIS_FILE}>
|
2018-11-02 09:35:17 +01:00
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${NLOHMANN_NATVIS_FILE}>
|
2017-11-28 23:43:39 +01:00
|
|
|
)
|
|
|
|
endif()
|
2018-04-07 13:15:44 +02:00
|
|
|
|
2017-07-29 11:59:09 +02:00
|
|
|
##
|
|
|
|
## TESTS
|
|
|
|
## create and configure the unit test target
|
|
|
|
##
|
2017-12-20 17:54:45 +01:00
|
|
|
include(CTest) #adds option BUILD_TESTING (default ON)
|
|
|
|
|
|
|
|
if(BUILD_TESTING AND JSON_BuildTests)
|
2017-07-27 16:50:24 +02:00
|
|
|
enable_testing()
|
2016-05-11 02:25:54 +02:00
|
|
|
add_subdirectory(test)
|
2016-05-08 17:30:24 +02:00
|
|
|
endif()
|
2016-04-25 09:36:05 +02:00
|
|
|
|
2017-07-29 11:59:09 +02:00
|
|
|
##
|
|
|
|
## INSTALL
|
|
|
|
## install header files, generate and install cmake config files for find_package()
|
|
|
|
##
|
2016-04-25 10:23:14 +02:00
|
|
|
include(CMakePackageConfigHelpers)
|
2017-07-29 11:59:09 +02:00
|
|
|
write_basic_package_version_file(
|
|
|
|
${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE} COMPATIBILITY SameMajorVersion
|
|
|
|
)
|
2018-09-26 19:08:49 +02:00
|
|
|
configure_file(
|
2017-07-29 11:59:09 +02:00
|
|
|
${NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE}
|
|
|
|
${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE}
|
2018-09-26 19:08:49 +02:00
|
|
|
@ONLY
|
2017-07-29 11:59:09 +02:00
|
|
|
)
|
2018-01-29 11:21:11 +01:00
|
|
|
|
2017-07-29 11:59:09 +02:00
|
|
|
install(
|
2018-01-29 11:21:11 +01:00
|
|
|
DIRECTORY ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}
|
|
|
|
DESTINATION ${NLOHMANN_JSON_INCLUDE_INSTALL_DIR}
|
2017-07-29 11:59:09 +02:00
|
|
|
)
|
|
|
|
install(
|
|
|
|
FILES ${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE} ${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE}
|
|
|
|
DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR}
|
|
|
|
)
|
2017-11-30 13:26:45 +01:00
|
|
|
if (NLOHMANN_ADD_NATVIS)
|
|
|
|
install(
|
|
|
|
FILES ${NLOHMANN_NATVIS_FILE}
|
|
|
|
DESTINATION .
|
|
|
|
)
|
|
|
|
endif()
|
2018-04-09 17:32:18 +02:00
|
|
|
export(
|
|
|
|
TARGETS ${NLOHMANN_JSON_TARGET_NAME}
|
|
|
|
NAMESPACE ${PROJECT_NAME}::
|
|
|
|
FILE ${NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE}
|
|
|
|
)
|
2017-07-29 11:59:09 +02:00
|
|
|
install(
|
|
|
|
TARGETS ${NLOHMANN_JSON_TARGET_NAME}
|
|
|
|
EXPORT ${NLOHMANN_JSON_TARGETS_EXPORT_NAME}
|
|
|
|
INCLUDES DESTINATION ${NLOHMANN_JSON_INCLUDE_INSTALL_DIR}
|
|
|
|
)
|
|
|
|
install(
|
|
|
|
EXPORT ${NLOHMANN_JSON_TARGETS_EXPORT_NAME}
|
2018-04-09 17:32:18 +02:00
|
|
|
NAMESPACE ${PROJECT_NAME}::
|
2017-07-29 11:59:09 +02:00
|
|
|
DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR}
|
2017-11-30 13:37:58 +01:00
|
|
|
)
|