From d30cd9d4d330b1ed431bc66cac4b24d67ce95324 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Thu, 22 Sep 2022 13:47:31 +0200 Subject: [PATCH] Add custom CMake feature summary --- CMakeLists.txt | 20 +--------- cmake/json_summary.cmake | 82 ++++++++++++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 18 ++++----- 3 files changed, 91 insertions(+), 29 deletions(-) create mode 100644 cmake/json_summary.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d689298b..dbde03798 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,26 +58,8 @@ set(NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/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_DisableEnumSerialization) - message(STATUS "Enum integer serialization is disabled") -endif() - -if (JSON_LegacyDiscardedValueComparison) - message(STATUS "Legacy discarded value comparison enabled") -endif() - -if (JSON_Diagnostics) - message(STATUS "Diagnostics enabled") endif() if (JSON_SystemInclude) @@ -195,3 +177,5 @@ if(JSON_Install) DESTINATION ${NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR} ) endif() + +include(json_summary) diff --git a/cmake/json_summary.cmake b/cmake/json_summary.cmake new file mode 100644 index 000000000..b20210f1b --- /dev/null +++ b/cmake/json_summary.cmake @@ -0,0 +1,82 @@ +# ANSI codes +set(rst "") +set(bld "") +# no color output on Windows or if disabled via CLICOLOR=0/CLICOLOR_FORCE=0 +if(NOT WIN32 AND NOT ("$ENV{CLICOLOR}" STREQUAL "0" OR "$ENV{CLICOLOR_FORCE}" STREQUAL "0")) + string(ASCII 27 esc) + set(rst "${esc}[0m") # reset + set(bld "${esc}[1m") # bold +endif() + +############################################################################# +# json_feature( +# var text +# [VALUES ...] +# [NEGATE]) +# +# Print feature info using and the boolean value of converted to +# YES/NO. +# +# If additional values are given and matches any of them, is not +# converted to YES/NO. +# +# If NEGATE is specified, the boolean value of is negated. +############################################################################# + +function(json_feature var text) + cmake_parse_arguments(args "NEGATE" "" "VALUES" ${ARGN}) + + set(state NO) + if(args_VALUES) + foreach(value ${args_VALUES}) + if(${var} STREQUAL value) + set(state ${value}) + break() + endif() + endforeach() + elseif(${args_NEGATE} AND NOT ${var} OR ${var}) + set(state YES) + endif() + + message(" ${text} ${bld}${state}${rst}") +endfunction() + +############################################################################# +# print feature summary +############################################################################# + +message(STATUS "[nohmann_json]: Feature summary:") + +json_feature(JSON_BuildTests "Build tests?") +if(JSON_BuildTests) + json_feature(JSON_32bitTest "Build the 32bit unit test?" VALUES AUTO ONLY) + json_feature(JSON_FastTests "Skip expensive/slow tests?") + json_feature(JSON_Valgrind "Execute test suite with Valgrind?") + + set(test_cxx_standards "") + foreach(cxx_standard ${JSON_TEST_CXX_STANDARDS_FEATURE_INFO}) + if(NOT cxx_standard MATCHES "^[\[].+[\]]$") + set(cxx_standard "${bld}${cxx_standard}${rst}") + endif() + set(test_cxx_standards "${test_cxx_standards} ${cxx_standard}") + endforeach() + + if(JSON_TEST_CXX_STANDARDS_FORCED) + set(test_cxx_standards "${test_cxx_standards} ${bld}(forced)${rst}") + endif() + message(" Test C++ standards:${test_cxx_standards}") +endif() + +message("") + +json_feature(JSON_Diagnostics "Diagnostics enabled?" NEGATE) +json_feature(JSON_DisableEnumSerialization "Default integer enum serialization enabled?") +json_feature(JSON_GlobalUDLs "Define user-defined string literals globally?") +json_feature(JSON_ImplicitConversions "Implicit conversions enabled?") +json_feature(JSON_LegacyDiscardedValueComparison "Legacy discarded value comparison enabled?") + +message("") + +json_feature(JSON_MultipleHeaders "Use the multi-header code?") +message(" Include directory: ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}") +json_feature(JSON_SystemInclude "Include as system headers?") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 99f0d3efd..d85db0451 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -95,27 +95,23 @@ json_test_set_test_options(test-unicode4 TEST_PROPERTIES TIMEOUT 3000) if("${JSON_TestStandards}" STREQUAL "") set(test_cxx_standards 11 14 17 20 23) - unset(test_force) + set(test_force "") else() set(test_cxx_standards ${JSON_TestStandards}) set(test_force FORCE) endif() -# Print selected standards marking unavailable ones with brackets -set(msg_standards "") +# create list of selected C++ standards for feature summary +set(info "") foreach(cxx_standard ${test_cxx_standards}) if(compiler_supports_cpp_${cxx_standard}) - list(APPEND msg_standards ${cxx_standard}) + list(APPEND info ${cxx_standard}) else() - list(APPEND msg_standards [${cxx_standard}]) + list(APPEND info [${cxx_standard}]) endif() endforeach() -string(JOIN " " msg_standards ${msg_standards}) -set(msg "Testing standards: ${msg_standards}") -if(test_force) - string(APPEND msg " (forced)") -endif() -message(STATUS "${msg}") +set(JSON_TEST_CXX_STANDARDS_FEATURE_INFO "${info}" PARENT_SCOPE) +set(JSON_TEST_CXX_STANDARDS_FORCED ${test_force} PARENT_SCOPE) # *DO* use json_test_set_test_options() above this line