From 475c8d34b7db9380dcf4288e46be17a23ac80667 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Thu, 22 Sep 2022 12:02:35 +0200 Subject: [PATCH] Move CMake options into cmake/json_opts.cmake --- CMakeLists.txt | 18 +------------ cmake/json_opts.cmake | 63 +++++++++++++++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 6 ----- 3 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 cmake/json_opts.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 71fb12242..1d689298b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,23 +34,7 @@ include(ExternalProject) ## ## OPTIONS ## - -# VERSION_GREATER_EQUAL is not available in CMake 3.1 -if(${JSON_MAIN_PROJECT} AND (${CMAKE_VERSION} VERSION_EQUAL 3.13 OR ${CMAKE_VERSION} VERSION_GREATER 3.13)) - set(JSON_BuildTests_INIT ON) -else() - set(JSON_BuildTests_INIT OFF) -endif() -option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${JSON_BuildTests_INIT}) -option(JSON_CI "Enable CI build targets." OFF) -option(JSON_Diagnostics "Use extended diagnostic messages." OFF) -option(JSON_GlobalUDLs "Place use-defined string literals in the global namespace." ON) -option(JSON_ImplicitConversions "Enable implicit conversions." ON) -option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF) -option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF) -option(JSON_Install "Install CMake targets during install step." ${JSON_MAIN_PROJECT}) -option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON) -option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF) +include (json_opts) if (JSON_CI) include(ci) diff --git a/cmake/json_opts.cmake b/cmake/json_opts.cmake new file mode 100644 index 000000000..ea5e59238 --- /dev/null +++ b/cmake/json_opts.cmake @@ -0,0 +1,63 @@ +include(CMakeDependentOption) + +############################################################################# +# test options +############################################################################# + +# VERSION_GREATER_EQUAL is not available in CMake 3.1 +if(${JSON_MAIN_PROJECT} AND (${CMAKE_VERSION} VERSION_EQUAL 3.13 OR ${CMAKE_VERSION} VERSION_GREATER 3.13)) + set(JSON_BuildTests_INIT ON) +else() + set(JSON_BuildTests_INIT OFF) +endif() +option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${JSON_BuildTests_INIT}) +set(JSON_32bitTest AUTO CACHE STRING "Enable the 32bit unit test (ON/OFF/AUTO/ONLY).") +cmake_dependent_option(JSON_FastTests "Skip expensive/slow tests." OFF "JSON_BuildTests" OFF) +cmake_dependent_option(JSON_Valgrind "Execute test suite with Valgrind." OFF "JSON_BuildTests" OFF) + +set(JSON_TestStandards "" CACHE STRING "The list of standards to test explicitly.") + +############################################################################# +# CI options +############################################################################# + +option(JSON_CI "Enable CI build targets." OFF) + +############################################################################# +# build & install options +############################################################################# + +option(JSON_Diagnostics "Use extended diagnostic messages." OFF) +option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF) +option(JSON_GlobalUDLs "Place user-defined string literals in the global namespace." ON) +option(JSON_ImplicitConversions "Enable implicit conversions." ON) +option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF) + +option(JSON_Install "Install CMake targets during install step." ${JSON_MAIN_PROJECT}) +option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON) +option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF) + +############################################################################# +# configuration +############################################################################# + +set(NLOHMANN_JSON_TARGET_NAME ${PROJECT_NAME}) +set(NLOHMANN_JSON_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/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_DATADIR}/pkgconfig") + +if (JSON_MultipleHeaders) + set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/") +else() + set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/single_include/") +endif() + +if (JSON_SystemInclude) + set(NLOHMANN_JSON_SYSTEM_INCLUDE "SYSTEM") +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1afb000ae..99f0d3efd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,11 +1,5 @@ cmake_minimum_required(VERSION 3.13) -option(JSON_Valgrind "Execute test suite with Valgrind." OFF) -option(JSON_FastTests "Skip expensive/slow tests." OFF) - -set(JSON_32bitTest AUTO CACHE STRING "Enable the 32bit unit test (ON/OFF/AUTO/ONLY).") -set(JSON_TestStandards "" CACHE STRING "The list of standards to test explicitly.") - include(test) #############################################################################