Add custom CMake feature summary

This commit is contained in:
Florian Albrechtskirchinger 2022-09-22 13:47:31 +02:00
parent 475c8d34b7
commit d30cd9d4d3
No known key found for this signature in database
GPG Key ID: 19618CE9B2D4BE6D
3 changed files with 91 additions and 29 deletions

View File

@ -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)

82
cmake/json_summary.cmake Normal file
View File

@ -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 <value>...]
# [NEGATE])
#
# Print feature info using <text> and the boolean value of <var> converted to
# YES/NO.
#
# If additional values are given and <var> matches any of them, <var> is not
# converted to YES/NO.
#
# If NEGATE is specified, the boolean value of <var> 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?")

View File

@ -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