mirror of
https://github.com/nlohmann/json.git
synced 2024-11-27 16:49:02 +08:00
6f551930e5
* ⚗️ move CI targets to CMake * ♻️ add target for cpplint * ♻️ add target for self-contained binaries * ♻️ add targets for iwyu and infer * 🔊 add version output * ♻️ add target for oclint * 🚨 fix warnings * ♻️ rename targets * ♻️ use iwyu properly * 🚨 fix warnings * ♻️ use iwyu properly * ♻️ add target for benchmarks * ♻️ add target for CMake flags * 👷 use GitHub Actions * ⚗️ try to install Clang 11 * ⚗️ try to install GCC 11 * ⚗️ try to install Clang 11 * ⚗️ try to install GCC 11 * ⚗️ add clang analyze target * 🔥 remove Google Benchmark * ⬆️ Google Benchmark 1.5.2 * 🔥 use fetchcontent * 🐧 add target to download a Linux version of CMake * 🔨 fix dependency * 🚨 fix includes * 🚨 fix comment * 🔧 adjust flags for GCC 11.0.0 20210110 (experimental) * 🐳 user Docker image to run CI * 🔧 add target for Valgrind * 👷 add target for Valgrind tests * ⚗️ add Dart * ⏪ remove Dart * ⚗️ do not call ctest in test subdirectory * ⚗️ download test data explicitly * ⚗️ only execute Valgrind tests * ⚗️ fix labels * 🔥 remove unneeded jobs * 🔨 cleanup * 🐛 fix OCLint call * ✅ add targets for offline and git-independent tests * ✅ add targets for C++ language versions and reproducible tests * 🔨 clean up * 👷 add CI steps for cppcheck and cpplint * 🚨 fix warnings from Clang-Tidy * 👷 add CI steps for Clang-Tidy * 🚨 fix warnings * 🔧 select proper binary * 🚨 fix warnings * 🚨 suppress some unhelpful warnings * 🚨 fix warnings * 🎨 fix format * 🚨 fix warnings * 👷 add CI steps for Sanitizers * 🚨 fix warnings * ⚡ add optimization to sanitizer build * 🚨 fix warnings * 🚨 add missing header * 🚨 fix warnings * 👷 add CI step for coverage * 👷 add CI steps for disabled exceptions and implicit conversions * 🚨 fix warnings * 👷 add CI steps for checking indentation * 🐛 fix variable use * 💚 fix build * ➖ remove CircleCI * 👷 add CI step for diagnostics * 🚨 fix warning * 🔥 clean Travis
184 lines
5.6 KiB
CMake
184 lines
5.6 KiB
CMake
cmake_minimum_required(VERSION 3.1)
|
|
|
|
##
|
|
## PROJECT
|
|
## name and version
|
|
##
|
|
project(nlohmann_json VERSION 3.9.1 LANGUAGES CXX)
|
|
|
|
##
|
|
## MAIN_PROJECT CHECK
|
|
## determine if nlohmann_json is built as a subproject (using add_subdirectory) or if it is the main project
|
|
##
|
|
set(MAIN_PROJECT OFF)
|
|
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|
set(MAIN_PROJECT ON)
|
|
endif()
|
|
|
|
##
|
|
## INCLUDE
|
|
##
|
|
##
|
|
include(ExternalProject)
|
|
|
|
##
|
|
## OPTIONS
|
|
##
|
|
|
|
if (POLICY CMP0077)
|
|
# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory.
|
|
cmake_policy(SET CMP0077 NEW)
|
|
endif ()
|
|
|
|
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${MAIN_PROJECT})
|
|
option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT})
|
|
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." OFF)
|
|
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
|
option(JSON_Diagnostics "Enable better diagnostic messages." OFF)
|
|
option(JSON_CI "Enable CI build targets." OFF)
|
|
|
|
if (JSON_CI)
|
|
include(cmake/ci.cmake)
|
|
endif ()
|
|
|
|
##
|
|
## CONFIGURATION
|
|
##
|
|
include(GNUInstallDirs)
|
|
|
|
set(NLOHMANN_JSON_TARGET_NAME ${PROJECT_NAME})
|
|
set(NLOHMANN_JSON_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "")
|
|
set(NLOHMANN_JSON_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
|
|
set(NLOHMANN_JSON_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
|
|
set(NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in")
|
|
set(NLOHMANN_JSON_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
|
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")
|
|
set(NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")
|
|
set(NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
|
|
|
if (JSON_MultipleHeaders)
|
|
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/")
|
|
message(STATUS "Using the multi-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
|
|
else()
|
|
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/single_include/")
|
|
message(STATUS "Using the single-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
|
|
endif()
|
|
|
|
if (NOT JSON_ImplicitConversions)
|
|
message(STATUS "Implicit conversions are disabled")
|
|
endif()
|
|
|
|
if (JSON_Diagnostics)
|
|
message(STATUS "Diagnostics enabled")
|
|
endif()
|
|
|
|
##
|
|
## TARGET
|
|
## create target and add include path
|
|
##
|
|
add_library(${NLOHMANN_JSON_TARGET_NAME} INTERFACE)
|
|
add_library(${PROJECT_NAME}::${NLOHMANN_JSON_TARGET_NAME} ALIAS ${NLOHMANN_JSON_TARGET_NAME})
|
|
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()
|
|
|
|
target_compile_definitions(
|
|
${NLOHMANN_JSON_TARGET_NAME}
|
|
INTERFACE
|
|
JSON_USE_IMPLICIT_CONVERSIONS=$<BOOL:${JSON_ImplicitConversions}>
|
|
JSON_DIAGNOSTICS=$<BOOL:${JSON_Diagnostics}>
|
|
)
|
|
|
|
target_include_directories(
|
|
${NLOHMANN_JSON_TARGET_NAME}
|
|
INTERFACE
|
|
$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_BUILD_DIR}>
|
|
$<INSTALL_INTERFACE:include>
|
|
)
|
|
|
|
## add debug view definition file for msvc (natvis)
|
|
if (MSVC)
|
|
set(NLOHMANN_ADD_NATVIS TRUE)
|
|
set(NLOHMANN_NATVIS_FILE "nlohmann_json.natvis")
|
|
target_sources(
|
|
${NLOHMANN_JSON_TARGET_NAME}
|
|
INTERFACE
|
|
$<INSTALL_INTERFACE:${NLOHMANN_NATVIS_FILE}>
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${NLOHMANN_NATVIS_FILE}>
|
|
)
|
|
endif()
|
|
|
|
# Install a pkg-config file, so other tools can find this.
|
|
CONFIGURE_FILE(
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
|
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
|
)
|
|
|
|
##
|
|
## TESTS
|
|
## create and configure the unit test target
|
|
##
|
|
if (JSON_BuildTests)
|
|
include(CTest)
|
|
enable_testing()
|
|
add_subdirectory(test)
|
|
endif()
|
|
|
|
##
|
|
## INSTALL
|
|
## install header files, generate and install cmake config files for find_package()
|
|
##
|
|
include(CMakePackageConfigHelpers)
|
|
# use a custom package version config file instead of
|
|
# write_basic_package_version_file to ensure that it's architecture-independent
|
|
# https://github.com/nlohmann/json/issues/1697
|
|
configure_file(
|
|
"cmake/nlohmann_jsonConfigVersion.cmake.in"
|
|
${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE}
|
|
@ONLY
|
|
)
|
|
configure_file(
|
|
${NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE}
|
|
${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE}
|
|
@ONLY
|
|
)
|
|
|
|
if(JSON_Install)
|
|
install(
|
|
DIRECTORY ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}
|
|
DESTINATION ${NLOHMANN_JSON_INCLUDE_INSTALL_DIR}
|
|
)
|
|
install(
|
|
FILES ${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE} ${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE}
|
|
DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR}
|
|
)
|
|
if (NLOHMANN_ADD_NATVIS)
|
|
install(
|
|
FILES ${NLOHMANN_NATVIS_FILE}
|
|
DESTINATION .
|
|
)
|
|
endif()
|
|
export(
|
|
TARGETS ${NLOHMANN_JSON_TARGET_NAME}
|
|
NAMESPACE ${PROJECT_NAME}::
|
|
FILE ${NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE}
|
|
)
|
|
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}
|
|
NAMESPACE ${PROJECT_NAME}::
|
|
DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR}
|
|
)
|
|
install(
|
|
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
|
DESTINATION ${NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR}
|
|
)
|
|
endif()
|