From a76b2c5229ec82c4c98fe416d3d6ec76ad40e874 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 9 May 2022 19:03:22 +0200 Subject: [PATCH 01/15] Add CMake function to associate macros with C++ standards Add and use the following CMake function: json_test_add_standard_keyphrases( PHRASES ... CXX_STANDARDS ...) Create a mapping between C++ standard versions and key phrases. json_test_add_test_for() will search for these key phrases and build tests for associated C++ standard versions. --- cmake/test.cmake | 42 ++++++++++++++++++++++++++++++++++++++++-- tests/CMakeLists.txt | 16 ++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/cmake/test.cmake b/cmake/test.cmake index bb840c6c0..351119225 100644 --- a/cmake/test.cmake +++ b/cmake/test.cmake @@ -42,6 +42,37 @@ endforeach() # test functions ############################################################################# +############################################################################# +# json_test_add_standard_keyphrases( +# PHRASES ... +# CXX_STANDARDS ...) +# +# Create a mapping between C++ standard versions and key phrases. +# +# json_test_add_test_for() will search for these key phrases and build tests +# for associated C++ standard versions. +############################################################################# + +function(json_test_add_standard_keyphrases) + cmake_parse_arguments(args "" "" + "CXX_STANDARDS;PHRASES" + ${ARGN}) + + if(NOT args_PHRASES) + message(FATAL_ERROR "At least one key phrase is required.") + endif() + + if(NOT args_CXX_STANDARDS) + message(FATAL_ERROR "At least one C++ standard version is required.") + endif() + + foreach(cxx_standard ${args_CXX_STANDARDS}) + set(var _JSON_TEST_STANDARD_KEYPHRASES_CPP_${cxx_standard}) + list(APPEND ${var} ${args_PHRASES}) + set(${var} CACHE INTERNAL "Mapping of key phrases to C++ standard version ${cxx_standard}") + endforeach() +endfunction() + ############################################################################# # json_test_set_test_options( # all| @@ -233,8 +264,15 @@ function(json_test_add_test_for file) # add unconditionally if C++11 (default) or forced if(NOT ("${cxx_standard}" STREQUAL 11 OR args_FORCE)) - string(FIND "${file_content}" JSON_HAS_CPP_${cxx_standard} has_cpp_found) - if(${has_cpp_found} EQUAL -1) + set(build FALSE) + foreach(phrase JSON_HAS_CPP_${cxx_standard} ${_JSON_TEST_STANDARD_KEYPHRASES_CPP_${cxx_standard}}) + string(FIND "${file_content}" ${phrase} phrase_found) + if(NOT ${phrase_found} EQUAL -1) + set(build TRUE) + break() + endif() + endforeach() + if(NOT build) continue() endif() endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 65b610f0e..2a3866bc6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -94,6 +94,22 @@ json_test_set_test_options(test-disabled_exceptions # raise timeout of expensive Unicode test json_test_set_test_options(test-unicode4 TEST_PROPERTIES TIMEOUT 3000) +############################################################################# +# define additional macro to C++ standard version mappings +############################################################################# + +json_test_add_standard_keyphrases( + PHRASES + JSON_HAS_EXPERIMENTAL_FILESYSTEM + JSON_HAS_FILESYSTEM + CXX_STANDARDS 17) + +json_test_add_standard_keyphrases( + PHRASES + JSON_HAS_RANGES + JSON_HAS_THREE_WAY_COMPARISON + CXX_STANDARDS 20) + ############################################################################# # add unit tests ############################################################################# From 46ec41871e1936cb61144009e7fe78ec67003543 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 9 May 2022 19:43:09 +0200 Subject: [PATCH 02/15] Reorder JSON meta Use "logical" ordering for use with ordered_json. --- include/nlohmann/json.hpp | 4 ++-- single_include/nlohmann/json.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 49188b314..fcb3a9379 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -247,9 +247,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { basic_json result; - result["copyright"] = "(C) 2013-2022 Niels Lohmann"; result["name"] = "JSON for Modern C++"; - result["url"] = "https://github.com/nlohmann/json"; result["version"]["string"] = detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR), '.', std::to_string(NLOHMANN_JSON_VERSION_MINOR), '.', @@ -257,6 +255,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec result["version"]["major"] = NLOHMANN_JSON_VERSION_MAJOR; result["version"]["minor"] = NLOHMANN_JSON_VERSION_MINOR; result["version"]["patch"] = NLOHMANN_JSON_VERSION_PATCH; + result["url"] = "https://github.com/nlohmann/json"; + result["copyright"] = "(C) 2013-2022 Niels Lohmann"; #ifdef _WIN32 result["platform"] = "win32"; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 4d86493e1..cc7d6107f 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -19258,9 +19258,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { basic_json result; - result["copyright"] = "(C) 2013-2022 Niels Lohmann"; result["name"] = "JSON for Modern C++"; - result["url"] = "https://github.com/nlohmann/json"; result["version"]["string"] = detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR), '.', std::to_string(NLOHMANN_JSON_VERSION_MINOR), '.', @@ -19268,6 +19266,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec result["version"]["major"] = NLOHMANN_JSON_VERSION_MAJOR; result["version"]["minor"] = NLOHMANN_JSON_VERSION_MINOR; result["version"]["patch"] = NLOHMANN_JSON_VERSION_PATCH; + result["url"] = "https://github.com/nlohmann/json"; + result["copyright"] = "(C) 2013-2022 Niels Lohmann"; #ifdef _WIN32 result["platform"] = "win32"; From 81c6ba33875936f13109a17e41aa967668b6d2c3 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 9 May 2022 19:45:17 +0200 Subject: [PATCH 03/15] Fix HP compiler detection in JSON meta --- include/nlohmann/json.hpp | 6 ++++-- single_include/nlohmann/json.hpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index fcb3a9379..138ab78e7 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -281,8 +281,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec std::to_string(__GNUC_PATCHLEVEL__)) } }; -#elif defined(__HP_cc) || defined(__HP_aCC) - result["compiler"] = "hp" +#elif defined(__HP_aCC) + result["compiler"] = {{"family", "hp"}, {"version", __HP_aCC}}; +#elif defined(__HP_cc) + result["compiler"] = {{"family", "hp"}, {"version", __HP_cc}}; #elif defined(__IBMCPP__) result["compiler"] = {{"family", "ilecpp"}, {"version", __IBMCPP__}}; #elif defined(_MSC_VER) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index cc7d6107f..51b06c874 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -19292,8 +19292,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec std::to_string(__GNUC_PATCHLEVEL__)) } }; -#elif defined(__HP_cc) || defined(__HP_aCC) - result["compiler"] = "hp" +#elif defined(__HP_aCC) + result["compiler"] = {{"family", "hp"}, {"version", __HP_aCC}}; +#elif defined(__HP_cc) + result["compiler"] = {{"family", "hp"}, {"version", __HP_cc}}; #elif defined(__IBMCPP__) result["compiler"] = {{"family", "ilecpp"}, {"version", __IBMCPP__}}; #elif defined(_MSC_VER) From 146aebc77fe535056fe3d8e7b33c293e336538c0 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 9 May 2022 19:46:19 +0200 Subject: [PATCH 04/15] Add _MSC_FULL_VER to JSON meta --- include/nlohmann/json.hpp | 3 +-- single_include/nlohmann/json.hpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 138ab78e7..357815f7d 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -288,7 +288,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec #elif defined(__IBMCPP__) result["compiler"] = {{"family", "ilecpp"}, {"version", __IBMCPP__}}; #elif defined(_MSC_VER) - result["compiler"] = {{"family", "msvc"}, {"version", _MSC_VER}}; + result["compiler"] = {{"family", "msvc"}, {"version", _MSC_VER}, {"version_full", _MSC_FULL_VER}}; #elif defined(__PGI) result["compiler"] = {{"family", "pgcpp"}, {"version", __PGI}}; #elif defined(__SUNPRO_CC) @@ -297,7 +297,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}}; #endif - #if defined(_MSVC_LANG) result["compiler"]["c++"] = std::to_string(_MSVC_LANG); #elif defined(__cplusplus) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 51b06c874..42694e559 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -19299,7 +19299,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec #elif defined(__IBMCPP__) result["compiler"] = {{"family", "ilecpp"}, {"version", __IBMCPP__}}; #elif defined(_MSC_VER) - result["compiler"] = {{"family", "msvc"}, {"version", _MSC_VER}}; + result["compiler"] = {{"family", "msvc"}, {"version", _MSC_VER}, {"version_full", _MSC_FULL_VER}}; #elif defined(__PGI) result["compiler"] = {{"family", "pgcpp"}, {"version", __PGI}}; #elif defined(__SUNPRO_CC) @@ -19308,7 +19308,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}}; #endif - #if defined(_MSVC_LANG) result["compiler"]["c++"] = std::to_string(_MSVC_LANG); #elif defined(__cplusplus) From 867621ee5a30766a0d55144f5c839131be480544 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 9 May 2022 19:47:25 +0200 Subject: [PATCH 05/15] Export library configuration in JSON meta --- include/nlohmann/json.hpp | 78 ++++++++++++++++++++++++++++++++ single_include/nlohmann/json.hpp | 78 ++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 357815f7d..85b3974ec 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -304,6 +304,84 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec #else result["compiler"]["c++"] = "unknown"; #endif + + // NOLINTBEGIN(modernize-use-bool-literals) + + result["config"]["JSON_DIAGNOSTICS"] = + static_cast(JSON_DIAGNOSTICS); // NOLINT(modernize-use-bool-literals) + + result["config"]["JSON_DISABLE_ENUM_SERIALIZATION"] = + static_cast(JSON_DISABLE_ENUM_SERIALIZATION); + + result["config"]["JSON_HAS_CPP_11"] = +#ifdef JSON_HAS_CPP_11 + true; +#else + false; +#endif + + result["config"]["JSON_HAS_CPP_14"] = +#ifdef JSON_HAS_CPP_14 + true; +#else + false; +#endif + + result["config"]["JSON_HAS_CPP_17"] = +#ifdef JSON_HAS_CPP_17 + true; +#else + false; +#endif + + result["config"]["JSON_HAS_CPP_20"] = +#ifdef JSON_HAS_CPP_20 + true; +#else + false; +#endif + + result["config"]["JSON_HAS_CPP_23"] = +#ifdef JSON_HAS_CPP_23 + true; +#else + false; +#endif + + result["config"]["JSON_HAS_EXPERIMENTAL_FILESYSTEM"] = + static_cast(JSON_HAS_EXPERIMENTAL_FILESYSTEM); + + result["config"]["JSON_HAS_FILESYSTEM"] = + static_cast(JSON_HAS_FILESYSTEM); + + result["config"]["JSON_HAS_THREE_WAY_COMPARISON"] = + static_cast(JSON_HAS_THREE_WAY_COMPARISON); + + result["config"]["JSON_NOEXCEPTION"] = +#ifdef JSON_NOEXCEPTION + true; +#else + false; +#endif + + result["config"]["JSON_NO_IO"] = +#ifdef JSON_NO_IO + true; +#else + false; +#endif + + result["config"]["JSON_USE_IMPLICIT_CONVERSIONS"] = + static_cast(JSON_USE_IMPLICIT_CONVERSIONS); + + result["config"]["JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON"] = + static_cast(JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON); + + result["config"]["NLOHMANN_JSON_ABI_STRING"] = + JSON_HEDLEY_STRINGIFY(NLOHMANN_JSON_ABI_STRING); + + // NOLINTEND(modernize-use-bool-literals) + return result; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 42694e559..0335565b9 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -19315,6 +19315,84 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec #else result["compiler"]["c++"] = "unknown"; #endif + + // NOLINTBEGIN(modernize-use-bool-literals) + + result["config"]["JSON_DIAGNOSTICS"] = + static_cast(JSON_DIAGNOSTICS); // NOLINT(modernize-use-bool-literals) + + result["config"]["JSON_DISABLE_ENUM_SERIALIZATION"] = + static_cast(JSON_DISABLE_ENUM_SERIALIZATION); + + result["config"]["JSON_HAS_CPP_11"] = +#ifdef JSON_HAS_CPP_11 + true; +#else + false; +#endif + + result["config"]["JSON_HAS_CPP_14"] = +#ifdef JSON_HAS_CPP_14 + true; +#else + false; +#endif + + result["config"]["JSON_HAS_CPP_17"] = +#ifdef JSON_HAS_CPP_17 + true; +#else + false; +#endif + + result["config"]["JSON_HAS_CPP_20"] = +#ifdef JSON_HAS_CPP_20 + true; +#else + false; +#endif + + result["config"]["JSON_HAS_CPP_23"] = +#ifdef JSON_HAS_CPP_23 + true; +#else + false; +#endif + + result["config"]["JSON_HAS_EXPERIMENTAL_FILESYSTEM"] = + static_cast(JSON_HAS_EXPERIMENTAL_FILESYSTEM); + + result["config"]["JSON_HAS_FILESYSTEM"] = + static_cast(JSON_HAS_FILESYSTEM); + + result["config"]["JSON_HAS_THREE_WAY_COMPARISON"] = + static_cast(JSON_HAS_THREE_WAY_COMPARISON); + + result["config"]["JSON_NOEXCEPTION"] = +#ifdef JSON_NOEXCEPTION + true; +#else + false; +#endif + + result["config"]["JSON_NO_IO"] = +#ifdef JSON_NO_IO + true; +#else + false; +#endif + + result["config"]["JSON_USE_IMPLICIT_CONVERSIONS"] = + static_cast(JSON_USE_IMPLICIT_CONVERSIONS); + + result["config"]["JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON"] = + static_cast(JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON); + + result["config"]["NLOHMANN_JSON_ABI_STRING"] = + JSON_HEDLEY_STRINGIFY(NLOHMANN_JSON_ABI_STRING); + + // NOLINTEND(modernize-use-bool-literals) + return result; } From 77baab32e6ab803c7a0c57b97b6e2bf991761dfa Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 9 May 2022 19:48:23 +0200 Subject: [PATCH 06/15] Add C++ standard library to JSON meta --- include/nlohmann/detail/macro_scope.hpp | 4 ++++ include/nlohmann/json.hpp | 11 +++++++++++ single_include/nlohmann/json.hpp | 15 +++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/include/nlohmann/detail/macro_scope.hpp b/include/nlohmann/detail/macro_scope.hpp index ff739f5d5..b414ec64d 100644 --- a/include/nlohmann/detail/macro_scope.hpp +++ b/include/nlohmann/detail/macro_scope.hpp @@ -50,7 +50,11 @@ #ifdef __has_include #if __has_include() #include + #elif __has_include() + #include #endif +#else + #include #endif #if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 85b3974ec..011a1d7b9 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -305,6 +305,17 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec result["compiler"]["c++"] = "unknown"; #endif + // see https://en.cppreference.com/w/cpp/header/ciso646 +#ifdef _LIBCPP_VERSION + result["compiler"]["libc++"] = {{"family", "LLVM libc++"}, {"version", _LIBCPP_VERSION}}; +#elif __GLIBCXX__ // Note: only version 6.1 or newer define this in ciso646 + result["compiler"]["libc++"] = {{"family", "GNU libstdc++"}, {"version", __GLIBCXX__}}; +#elif _CPPLIB_VER + result["compiler"]["libc++"] = {{"family", "Microsoft STL"}, {"version", _CPPLIB_VER}}; +#else + result["compiler"]["libc++"] = {{"family", "unknown"}, {"version", "unknown"}}; +#endif + // NOLINTBEGIN(modernize-use-bool-literals) result["config"]["JSON_DIAGNOSTICS"] = diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 0335565b9..1012196c4 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2379,7 +2379,11 @@ JSON_HEDLEY_DIAGNOSTIC_POP #ifdef __has_include #if __has_include() #include + #elif __has_include() + #include #endif +#else + #include #endif #if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM) @@ -19316,6 +19320,17 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec result["compiler"]["c++"] = "unknown"; #endif + // see https://en.cppreference.com/w/cpp/header/ciso646 +#ifdef _LIBCPP_VERSION + result["compiler"]["libc++"] = {{"family", "LLVM libc++"}, {"version", _LIBCPP_VERSION}}; +#elif __GLIBCXX__ // Note: only version 6.1 or newer define this in ciso646 + result["compiler"]["libc++"] = {{"family", "GNU libstdc++"}, {"version", __GLIBCXX__}}; +#elif _CPPLIB_VER + result["compiler"]["libc++"] = {{"family", "Microsoft STL"}, {"version", _CPPLIB_VER}}; +#else + result["compiler"]["libc++"] = {{"family", "unknown"}, {"version", "unknown"}}; +#endif + // NOLINTBEGIN(modernize-use-bool-literals) result["config"]["JSON_DIAGNOSTICS"] = From c24067e5fccf67bba5e3ab6c216c630b3f24c577 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 9 May 2022 19:54:03 +0200 Subject: [PATCH 07/15] Print JSON meta at the start of each unit test --- cmake/test.cmake | 11 +++++ tests/src/print_meta.cpp | 44 +++++++++++++++++++ tests/src/unit-32bit.cpp | 2 + tests/src/unit-algorithms.cpp | 2 + tests/src/unit-allocator.cpp | 2 + tests/src/unit-alt-string.cpp | 2 + tests/src/unit-assert_macro.cpp | 2 + tests/src/unit-binary_formats.cpp | 2 + tests/src/unit-bjdata.cpp | 2 + tests/src/unit-bson.cpp | 2 + .../src/unit-byte_container_with_subtype.cpp | 2 + tests/src/unit-capacity.cpp | 2 + tests/src/unit-cbor.cpp | 2 + tests/src/unit-class_const_iterator.cpp | 2 + tests/src/unit-class_iterator.cpp | 2 + tests/src/unit-class_lexer.cpp | 2 + tests/src/unit-class_parser.cpp | 2 + tests/src/unit-comparison.cpp | 2 + tests/src/unit-concepts.cpp | 2 + tests/src/unit-constructor1.cpp | 2 + tests/src/unit-constructor2.cpp | 2 + tests/src/unit-convenience.cpp | 2 + tests/src/unit-conversions.cpp | 2 + tests/src/unit-deserialization.cpp | 2 + tests/src/unit-diagnostics.cpp | 2 + tests/src/unit-disabled_exceptions.cpp | 2 + tests/src/unit-element_access1.cpp | 2 + tests/src/unit-element_access2.cpp | 2 + tests/src/unit-hash.cpp | 2 + tests/src/unit-inspection.cpp | 2 + tests/src/unit-items.cpp | 2 + tests/src/unit-iterators1.cpp | 2 + tests/src/unit-iterators2.cpp | 2 + tests/src/unit-json_patch.cpp | 2 + tests/src/unit-json_pointer.cpp | 2 + tests/src/unit-large_json.cpp | 2 + tests/src/unit-merge_patch.cpp | 2 + tests/src/unit-meta.cpp | 2 + tests/src/unit-modifiers.cpp | 2 + tests/src/unit-msgpack.cpp | 2 + tests/src/unit-noexcept.cpp | 2 + tests/src/unit-ordered_json.cpp | 2 + tests/src/unit-ordered_map.cpp | 2 + tests/src/unit-pointer_access.cpp | 2 + tests/src/unit-readme.cpp | 2 + tests/src/unit-reference_access.cpp | 2 + tests/src/unit-regression1.cpp | 2 + tests/src/unit-regression2.cpp | 2 + tests/src/unit-serialization.cpp | 2 + tests/src/unit-testsuites.cpp | 2 + tests/src/unit-to_chars.cpp | 2 + tests/src/unit-ubjson.cpp | 2 + tests/src/unit-udl.cpp | 2 + tests/src/unit-udt.cpp | 2 + tests/src/unit-udt_macro.cpp | 2 + tests/src/unit-unicode1.cpp | 2 + tests/src/unit-unicode2.cpp | 2 + tests/src/unit-unicode3.cpp | 2 + tests/src/unit-unicode4.cpp | 2 + tests/src/unit-unicode5.cpp | 2 + tests/src/unit-user_defined_input.cpp | 2 + tests/src/unit-windows_h.cpp | 2 + tests/src/unit-wstring.cpp | 2 + tests/src/unit.cpp | 14 +++++- 64 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 tests/src/print_meta.cpp diff --git a/cmake/test.cmake b/cmake/test.cmake index 351119225..551729e79 100644 --- a/cmake/test.cmake +++ b/cmake/test.cmake @@ -148,7 +148,18 @@ function(_json_test_add_test test_name file main cxx_standard) message(FATAL_ERROR "Target ${test_target} has already been added.") endif() + file(READ ${file} file_content) + string(REGEX MATCH "[\n\r \t]+#[ \t]*include[ \t]+\"print_meta.cpp\"" match_result "${file_content}") + if(NOT match_result) + message(FATAL_ERROR "Please append\n" + "#include \"print_meta.cpp\" // NOLINT(bugprone-suspicious-include)\n" + "to the end of file: ${file}") + endif() + + # add test executable add_executable(${test_target} ${file}) + # add parentheses to silence clang-tidy warning + target_compile_definitions(${test_target} PRIVATE "JSON_TEST_NAME=(${test_target})") target_link_libraries(${test_target} PRIVATE ${main}) # set and require C++ standard diff --git a/tests/src/print_meta.cpp b/tests/src/print_meta.cpp new file mode 100644 index 000000000..e8a14c71b --- /dev/null +++ b/tests/src/print_meta.cpp @@ -0,0 +1,44 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ (supporting code) +// | | |__ | | | | | | version 3.10.5 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + +#include + +#ifdef JSON_TEST_PRINT_META_WITH_MAIN + #include +#endif + +#define STRINGIZE_EX(x) #x +#define STRINGIZE(x) STRINGIZE_EX(x) + +void print_meta(); + +void print_meta() +{ + auto meta = nlohmann::ordered_json::meta(); + meta.erase("name"); + meta.erase("url"); + meta.erase("copyright"); + meta["version"] = meta["version"]["string"]; + + // strip off the parentheses added to silence clang-tidy warning + auto strip_parens = [](const std::string & str) + { + return (str[0] == '(') ? std::string(str.data() + 1, str.size() - 2) : str; + }; + std::cout << strip_parens(STRINGIZE(JSON_TEST_NAME)) << '\n'; + std::cout << meta.dump(4) << '\n' << std::endl; +} + +#ifdef JSON_TEST_PRINT_META_WITH_MAIN +int main(int /*argc*/, char* /*argv*/[]) +{ + print_meta(); + + return 0; +} +#endif diff --git a/tests/src/unit-32bit.cpp b/tests/src/unit-32bit.cpp index 82e6f33b2..c82cb3664 100644 --- a/tests/src/unit-32bit.cpp +++ b/tests/src/unit-32bit.cpp @@ -134,3 +134,5 @@ TEST_CASE("BJData") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-algorithms.cpp b/tests/src/unit-algorithms.cpp index d10c14dcf..3a7886024 100644 --- a/tests/src/unit-algorithms.cpp +++ b/tests/src/unit-algorithms.cpp @@ -295,3 +295,5 @@ TEST_CASE("algorithms") CHECK(j_array == json({false, true, 3, 13, 29, {{"one", 1}, {"two", 2}}, {1, 2, 3}, "baz", "foo"})); } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-allocator.cpp b/tests/src/unit-allocator.cpp index 9e5edc4f8..51c321aa3 100644 --- a/tests/src/unit-allocator.cpp +++ b/tests/src/unit-allocator.cpp @@ -252,3 +252,5 @@ TEST_CASE("bad my_allocator::construct") j["test"].push_back("should not leak"); } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-alt-string.cpp b/tests/src/unit-alt-string.cpp index 0c94d0fb9..a760c0ecd 100644 --- a/tests/src/unit-alt-string.cpp +++ b/tests/src/unit-alt-string.cpp @@ -322,3 +322,5 @@ TEST_CASE("alternative string type") CHECK(j.at(alt_json::json_pointer("/foo/1")) == j["foo"][1]); } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-assert_macro.cpp b/tests/src/unit-assert_macro.cpp index e9be6b5e2..f45e41ceb 100644 --- a/tests/src/unit-assert_macro.cpp +++ b/tests/src/unit-assert_macro.cpp @@ -46,3 +46,5 @@ TEST_CASE("JSON_ASSERT(x)") DOCTEST_GCC_SUPPRESS_WARNING_POP DOCTEST_CLANG_SUPPRESS_WARNING_POP + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-binary_formats.cpp b/tests/src/unit-binary_formats.cpp index 896bc1bdb..8c18a79ac 100644 --- a/tests/src/unit-binary_formats.cpp +++ b/tests/src/unit-binary_formats.cpp @@ -209,3 +209,5 @@ TEST_CASE("Binary Formats" * doctest::skip()) CHECK((100.0 * double(ubjson_3_size) / double(json_size)) == Approx(89.450)); } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-bjdata.cpp b/tests/src/unit-bjdata.cpp index c245e87e9..52eadf5cc 100644 --- a/tests/src/unit-bjdata.cpp +++ b/tests/src/unit-bjdata.cpp @@ -3547,3 +3547,5 @@ TEST_CASE("BJData roundtrips" * doctest::skip()) } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-bson.cpp b/tests/src/unit-bson.cpp index 05fe8d3e8..3c876049e 100644 --- a/tests/src/unit-bson.cpp +++ b/tests/src/unit-bson.cpp @@ -1296,3 +1296,5 @@ TEST_CASE("BSON roundtrips" * doctest::skip()) } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-byte_container_with_subtype.cpp b/tests/src/unit-byte_container_with_subtype.cpp index c651273fe..6dd66070f 100644 --- a/tests/src/unit-byte_container_with_subtype.cpp +++ b/tests/src/unit-byte_container_with_subtype.cpp @@ -75,3 +75,5 @@ TEST_CASE("byte_container_with_subtype") CHECK(container2 == container4); } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-capacity.cpp b/tests/src/unit-capacity.cpp index 858e111ad..59de2e25c 100644 --- a/tests/src/unit-capacity.cpp +++ b/tests/src/unit-capacity.cpp @@ -541,3 +541,5 @@ TEST_CASE("capacity") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-cbor.cpp b/tests/src/unit-cbor.cpp index 78bdeb2b9..66d013fe9 100644 --- a/tests/src/unit-cbor.cpp +++ b/tests/src/unit-cbor.cpp @@ -2665,3 +2665,5 @@ TEST_CASE("Tagged values") CHECK(!jb["binary"].get_binary().has_subtype()); } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-class_const_iterator.cpp b/tests/src/unit-class_const_iterator.cpp index 8e0bc823e..a468d18b0 100644 --- a/tests/src/unit-class_const_iterator.cpp +++ b/tests/src/unit-class_const_iterator.cpp @@ -391,3 +391,5 @@ TEST_CASE("const_iterator class") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-class_iterator.cpp b/tests/src/unit-class_iterator.cpp index 7568d927d..711a21366 100644 --- a/tests/src/unit-class_iterator.cpp +++ b/tests/src/unit-class_iterator.cpp @@ -466,3 +466,5 @@ TEST_CASE("iterator class") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-class_lexer.cpp b/tests/src/unit-class_lexer.cpp index 9991b355e..be77916ca 100644 --- a/tests/src/unit-class_lexer.cpp +++ b/tests/src/unit-class_lexer.cpp @@ -224,3 +224,5 @@ TEST_CASE("lexer class") CHECK((scan_string("/**//**//**/", true) == json::lexer::token_type::end_of_input)); } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-class_parser.cpp b/tests/src/unit-class_parser.cpp index 86dd85a7f..8115a5cf7 100644 --- a/tests/src/unit-class_parser.cpp +++ b/tests/src/unit-class_parser.cpp @@ -1689,3 +1689,5 @@ TEST_CASE("parser class") CHECK_THROWS_WITH_AS(_ = json::parse("/*", nullptr, true, true), "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid comment; missing closing '*/'; last read: '/*'", json::parse_error); } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-comparison.cpp b/tests/src/unit-comparison.cpp index f713c980a..a97c50a87 100644 --- a/tests/src/unit-comparison.cpp +++ b/tests/src/unit-comparison.cpp @@ -593,3 +593,5 @@ TEST_CASE("lexicographical comparison operators") } #endif } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-concepts.cpp b/tests/src/unit-concepts.cpp index c179b0c3c..206c2dd0f 100644 --- a/tests/src/unit-concepts.cpp +++ b/tests/src/unit-concepts.cpp @@ -148,3 +148,5 @@ TEST_CASE("concepts") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-constructor1.cpp b/tests/src/unit-constructor1.cpp index f294e5cd6..b12d2a169 100644 --- a/tests/src/unit-constructor1.cpp +++ b/tests/src/unit-constructor1.cpp @@ -1569,3 +1569,5 @@ TEST_CASE("constructors") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-constructor2.cpp b/tests/src/unit-constructor2.cpp index b1b5a6ed4..411c871c6 100644 --- a/tests/src/unit-constructor2.cpp +++ b/tests/src/unit-constructor2.cpp @@ -184,3 +184,5 @@ TEST_CASE("other constructors and destructor") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-convenience.cpp b/tests/src/unit-convenience.cpp index fcb772320..948f9aa71 100644 --- a/tests/src/unit-convenience.cpp +++ b/tests/src/unit-convenience.cpp @@ -203,3 +203,5 @@ TEST_CASE("convenience functions") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-conversions.cpp b/tests/src/unit-conversions.cpp index d86b614c4..f5312ed00 100644 --- a/tests/src/unit-conversions.cpp +++ b/tests/src/unit-conversions.cpp @@ -1570,3 +1570,5 @@ TEST_CASE("JSON to enum mapping") } DOCTEST_CLANG_SUPPRESS_WARNING_POP + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-deserialization.cpp b/tests/src/unit-deserialization.cpp index 3616f35c5..5dc1be7c8 100644 --- a/tests/src/unit-deserialization.cpp +++ b/tests/src/unit-deserialization.cpp @@ -1187,3 +1187,5 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T, CHECK(json::sax_parse(v, &l)); CHECK(l.events.size() == 1); } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-diagnostics.cpp b/tests/src/unit-diagnostics.cpp index a1aff57af..121d84ea8 100644 --- a/tests/src/unit-diagnostics.cpp +++ b/tests/src/unit-diagnostics.cpp @@ -244,3 +244,5 @@ TEST_CASE("Regression tests for extended diagnostics") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-disabled_exceptions.cpp b/tests/src/unit-disabled_exceptions.cpp index 6a7d5000d..eff5099fe 100644 --- a/tests/src/unit-disabled_exceptions.cpp +++ b/tests/src/unit-disabled_exceptions.cpp @@ -50,3 +50,5 @@ TEST_CASE("Tests with disabled exceptions") } DOCTEST_GCC_SUPPRESS_WARNING_POP + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-element_access1.cpp b/tests/src/unit-element_access1.cpp index f28f2f9f2..e09c64f5b 100644 --- a/tests/src/unit-element_access1.cpp +++ b/tests/src/unit-element_access1.cpp @@ -879,3 +879,5 @@ TEST_CASE("element access 1") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-element_access2.cpp b/tests/src/unit-element_access2.cpp index 5f28e5a2c..db2c5f25f 100644 --- a/tests/src/unit-element_access2.cpp +++ b/tests/src/unit-element_access2.cpp @@ -1488,3 +1488,5 @@ TEST_CASE_TEMPLATE("element access 2 (throwing tests)", Json, nlohmann::json, nl } } #endif + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-hash.cpp b/tests/src/unit-hash.cpp index 1ed21bd39..bbbbdc14c 100644 --- a/tests/src/unit-hash.cpp +++ b/tests/src/unit-hash.cpp @@ -111,3 +111,5 @@ TEST_CASE("hash") CHECK(hashes.size() == 21); } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-inspection.cpp b/tests/src/unit-inspection.cpp index c5ea684d0..7277d5f3e 100644 --- a/tests/src/unit-inspection.cpp +++ b/tests/src/unit-inspection.cpp @@ -457,3 +457,5 @@ TEST_CASE("object inspection") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-items.cpp b/tests/src/unit-items.cpp index 55d9edd39..22708061d 100644 --- a/tests/src/unit-items.cpp +++ b/tests/src/unit-items.cpp @@ -1431,3 +1431,5 @@ TEST_CASE("items()") DOCTEST_GCC_SUPPRESS_WARNING_POP DOCTEST_CLANG_SUPPRESS_WARNING_POP + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-iterators1.cpp b/tests/src/unit-iterators1.cpp index 14bbdf844..494aac832 100644 --- a/tests/src/unit-iterators1.cpp +++ b/tests/src/unit-iterators1.cpp @@ -1628,3 +1628,5 @@ TEST_CASE("iterators 1") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-iterators2.cpp b/tests/src/unit-iterators2.cpp index 57326a289..bc53f6cf3 100644 --- a/tests/src/unit-iterators2.cpp +++ b/tests/src/unit-iterators2.cpp @@ -970,3 +970,5 @@ TEST_CASE("iterators 2") } #endif } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-json_patch.cpp b/tests/src/unit-json_patch.cpp index 3be0f8ecf..df99e2744 100644 --- a/tests/src/unit-json_patch.cpp +++ b/tests/src/unit-json_patch.cpp @@ -1319,3 +1319,5 @@ TEST_CASE("JSON patch") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-json_pointer.cpp b/tests/src/unit-json_pointer.cpp index 93559eb31..6130b215d 100644 --- a/tests/src/unit-json_pointer.cpp +++ b/tests/src/unit-json_pointer.cpp @@ -699,3 +699,5 @@ TEST_CASE("JSON pointers") CHECK_FALSE(ptr != ptr_oj); } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-large_json.cpp b/tests/src/unit-large_json.cpp index 69f47df64..e59ac6502 100644 --- a/tests/src/unit-large_json.cpp +++ b/tests/src/unit-large_json.cpp @@ -27,3 +27,5 @@ TEST_CASE("tests on very large JSONs") } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-merge_patch.cpp b/tests/src/unit-merge_patch.cpp index 5098d1278..7622c0460 100644 --- a/tests/src/unit-merge_patch.cpp +++ b/tests/src/unit-merge_patch.cpp @@ -242,3 +242,5 @@ TEST_CASE("JSON Merge Patch") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-meta.cpp b/tests/src/unit-meta.cpp index ad3a841c6..a6a1f0015 100644 --- a/tests/src/unit-meta.cpp +++ b/tests/src/unit-meta.cpp @@ -34,3 +34,5 @@ TEST_CASE("version information") CHECK(j.at("compiler").find("c++") != j.at("compiler").end()); } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-modifiers.cpp b/tests/src/unit-modifiers.cpp index 8b06f1809..6c74ef817 100644 --- a/tests/src/unit-modifiers.cpp +++ b/tests/src/unit-modifiers.cpp @@ -951,3 +951,5 @@ TEST_CASE("modifiers") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-msgpack.cpp b/tests/src/unit-msgpack.cpp index d0e5ff3d5..61d01f903 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp @@ -1835,3 +1835,5 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip()) } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-noexcept.cpp b/tests/src/unit-noexcept.cpp index 89a7db7b0..6ccf6c432 100644 --- a/tests/src/unit-noexcept.cpp +++ b/tests/src/unit-noexcept.cpp @@ -80,3 +80,5 @@ TEST_CASE("runtime checks") } DOCTEST_GCC_SUPPRESS_WARNING_POP + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-ordered_json.cpp b/tests/src/unit-ordered_json.cpp index 3ce0aa155..a73949741 100644 --- a/tests/src/unit-ordered_json.cpp +++ b/tests/src/unit-ordered_json.cpp @@ -70,3 +70,5 @@ TEST_CASE("ordered_json") CHECK(oj1.size() == 4); CHECK(oj1.dump() == "{\"c\":1,\"b\":2,\"a\":3,\"d\":42}"); } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-ordered_map.cpp b/tests/src/unit-ordered_map.cpp index d907263b4..b265f0361 100644 --- a/tests/src/unit-ordered_map.cpp +++ b/tests/src/unit-ordered_map.cpp @@ -309,3 +309,5 @@ TEST_CASE("ordered_map") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-pointer_access.cpp b/tests/src/unit-pointer_access.cpp index b48a4297c..9f9b86eec 100644 --- a/tests/src/unit-pointer_access.cpp +++ b/tests/src/unit-pointer_access.cpp @@ -477,3 +477,5 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() != nullptr); } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-readme.cpp b/tests/src/unit-readme.cpp index 6d296f02f..fc7e643a4 100644 --- a/tests/src/unit-readme.cpp +++ b/tests/src/unit-readme.cpp @@ -303,3 +303,5 @@ TEST_CASE("README" * doctest::skip()) } DOCTEST_MSVC_SUPPRESS_WARNING_POP + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-reference_access.cpp b/tests/src/unit-reference_access.cpp index abe8bd1f5..7eb7acf9b 100644 --- a/tests/src/unit-reference_access.cpp +++ b/tests/src/unit-reference_access.cpp @@ -245,3 +245,5 @@ TEST_CASE("reference access") CHECK_NOTHROW(value.get_ref()); } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-regression1.cpp b/tests/src/unit-regression1.cpp index 45c4bd620..ce500ca4d 100644 --- a/tests/src/unit-regression1.cpp +++ b/tests/src/unit-regression1.cpp @@ -1511,3 +1511,5 @@ template class number_integer {}; template class number_unsigned {}; template class number_float {}; #endif + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index 73c8f3906..d99876038 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -926,3 +926,5 @@ TEST_CASE("regression tests 2") } DOCTEST_CLANG_SUPPRESS_WARNING_POP + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-serialization.cpp b/tests/src/unit-serialization.cpp index 50dc58b4c..418a6038a 100644 --- a/tests/src/unit-serialization.cpp +++ b/tests/src/unit-serialization.cpp @@ -295,3 +295,5 @@ TEST_CASE("dump with binary values") "]"); } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-testsuites.cpp b/tests/src/unit-testsuites.cpp index 268a48327..6c5eec77f 100644 --- a/tests/src/unit-testsuites.cpp +++ b/tests/src/unit-testsuites.cpp @@ -1389,3 +1389,5 @@ TEST_CASE("Big List of Naughty Strings") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-to_chars.cpp b/tests/src/unit-to_chars.cpp index 44d4f3801..6dcb363d7 100644 --- a/tests/src/unit-to_chars.cpp +++ b/tests/src/unit-to_chars.cpp @@ -514,3 +514,5 @@ TEST_CASE("formatting") check_integer(1000000000000000000LL, "1000000000000000000"); } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-ubjson.cpp b/tests/src/unit-ubjson.cpp index 5086149ce..6f7773703 100644 --- a/tests/src/unit-ubjson.cpp +++ b/tests/src/unit-ubjson.cpp @@ -2515,3 +2515,5 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip()) } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-udl.cpp b/tests/src/unit-udl.cpp index 934744364..238bdbc5d 100644 --- a/tests/src/unit-udl.cpp +++ b/tests/src/unit-udl.cpp @@ -55,3 +55,5 @@ TEST_CASE("user-defined string literals") } #endif } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-udt.cpp b/tests/src/unit-udt.cpp index 681536f95..e7520b456 100644 --- a/tests/src/unit-udt.cpp +++ b/tests/src/unit-udt.cpp @@ -862,3 +862,5 @@ TEST_CASE("compatible array type, without iterator type alias") } DOCTEST_GCC_SUPPRESS_WARNING_POP + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-udt_macro.cpp b/tests/src/unit-udt_macro.cpp index eed81cdfa..d2b61303e 100644 --- a/tests/src/unit-udt_macro.cpp +++ b/tests/src/unit-udt_macro.cpp @@ -412,3 +412,5 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-unicode1.cpp b/tests/src/unit-unicode1.cpp index 03c5b8006..9eb59eab5 100644 --- a/tests/src/unit-unicode1.cpp +++ b/tests/src/unit-unicode1.cpp @@ -618,3 +618,5 @@ TEST_CASE("Markus Kuhn's UTF-8 decoder capability and stress test") } } } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-unicode2.cpp b/tests/src/unit-unicode2.cpp index b91d0be86..7025898c1 100644 --- a/tests/src/unit-unicode2.cpp +++ b/tests/src/unit-unicode2.cpp @@ -608,3 +608,5 @@ TEST_CASE("Unicode (2/5)" * doctest::skip()) } DOCTEST_CLANG_SUPPRESS_WARNING_POP + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-unicode3.cpp b/tests/src/unit-unicode3.cpp index d5740e3e0..dd3fb6465 100644 --- a/tests/src/unit-unicode3.cpp +++ b/tests/src/unit-unicode3.cpp @@ -322,3 +322,5 @@ TEST_CASE("Unicode (3/5)" * doctest::skip()) } DOCTEST_CLANG_SUPPRESS_WARNING_POP + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-unicode4.cpp b/tests/src/unit-unicode4.cpp index 0a7a58bc3..7f14114f1 100644 --- a/tests/src/unit-unicode4.cpp +++ b/tests/src/unit-unicode4.cpp @@ -322,3 +322,5 @@ TEST_CASE("Unicode (4/5)" * doctest::skip()) } DOCTEST_CLANG_SUPPRESS_WARNING_POP + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-unicode5.cpp b/tests/src/unit-unicode5.cpp index 2360dbe36..d788974eb 100644 --- a/tests/src/unit-unicode5.cpp +++ b/tests/src/unit-unicode5.cpp @@ -322,3 +322,5 @@ TEST_CASE("Unicode (5/5)" * doctest::skip()) } DOCTEST_CLANG_SUPPRESS_WARNING_POP + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-user_defined_input.cpp b/tests/src/unit-user_defined_input.cpp index a3095a8d9..22ba09b34 100644 --- a/tests/src/unit-user_defined_input.cpp +++ b/tests/src/unit-user_defined_input.cpp @@ -128,3 +128,5 @@ TEST_CASE("Custom iterator") } } // namespace + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-windows_h.cpp b/tests/src/unit-windows_h.cpp index 5fa641091..5dd852f9a 100644 --- a/tests/src/unit-windows_h.cpp +++ b/tests/src/unit-windows_h.cpp @@ -19,3 +19,5 @@ TEST_CASE("include windows.h") { CHECK(true); } + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit-wstring.cpp b/tests/src/unit-wstring.cpp index b8ed08db8..01d6f5a24 100644 --- a/tests/src/unit-wstring.cpp +++ b/tests/src/unit-wstring.cpp @@ -97,3 +97,5 @@ TEST_CASE("wide strings") } } #endif + +#include "print_meta.cpp" // NOLINT(bugprone-suspicious-include) diff --git a/tests/src/unit.cpp b/tests/src/unit.cpp index 8074687a5..d598d43c6 100644 --- a/tests/src/unit.cpp +++ b/tests/src/unit.cpp @@ -6,5 +6,17 @@ // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT -#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#define DOCTEST_CONFIG_IMPLEMENT #include "doctest_compatibility.h" + +// defined in print_meta.cpp which is automatically appended to each unit test +extern void print_meta(); + +DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4007) +int main(int argc, char* argv[]) +{ + print_meta(); + + return doctest::Context(argc, argv).run(); +} +DOCTEST_MSVC_SUPPRESS_WARNING_POP From 6a501169c73d3ac412758579f9990647eef3d0df Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 9 May 2022 19:54:57 +0200 Subject: [PATCH 08/15] Add print_meta target Add a target to print JSON meta for all tested C++ standard versions. --- tests/CMakeLists.txt | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2a3866bc6..7be1c057c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -188,3 +188,39 @@ add_subdirectory(cmake_add_subdirectory) add_subdirectory(cmake_fetch_content) add_subdirectory(cmake_fetch_content2) add_subdirectory(cmake_target_include_directories) + +############################################################################# +# print JSON meta for tested C++ standard versions +############################################################################# + +set(print_meta_targets) +set(print_meta_commands) +foreach(cxx_standard ${test_cxx_standards}) + if(NOT compiler_supports_cpp_${cxx_standard}) + continue() + endif() + + set(print_meta_target print_meta_cpp${cxx_standard}) + add_executable(${print_meta_target} EXCLUDE_FROM_ALL src/print_meta.cpp) + target_compile_definitions(${print_meta_target} PRIVATE JSON_TEST_PRINT_META_WITH_MAIN JSON_TEST_NAME=${print_meta_target}) + target_compile_options(${print_meta_target} PRIVATE $<$:/EHsc;$<$:/Od>>) + target_link_libraries(${print_meta_target} PRIVATE ${NLOHMANN_JSON_TARGET_NAME}) + + # set and require C++ standard + set_target_properties(${print_meta_target} PROPERTIES + CXX_STANDARD ${cxx_standard} + CXX_STANDARD_REQUIRED ON + ) + + # apply standard-specific build settings + if(TARGET _json_test_interface__cpp_${cxx_standard}) + target_link_libraries(${print_meta_target} PRIVATE _json_test_interface__cpp_${cxx_standard}) + endif() + + list(APPEND print_meta_targets ${print_meta_target}) + list(APPEND print_meta_commands COMMAND ${print_meta_target}) +endforeach() + +add_custom_target(print_meta + ${print_meta_commands} + USES_TERMINAL) From 1465077636109e710e2321e8abd5e77851444bfc Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 1 Aug 2022 12:35:15 +0200 Subject: [PATCH 09/15] Update examples/meta.output --- docs/examples/meta.output | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/examples/meta.output b/docs/examples/meta.output index 43fe0a887..1dfa76e06 100644 --- a/docs/examples/meta.output +++ b/docs/examples/meta.output @@ -2,11 +2,32 @@ "compiler": { "c++": "201103", "family": "gcc", - "version": "11.3.0" + "libc++": { + "family": "GNU libstdc++", + "version": 20220730 + }, + "version": "12.1.1" + }, + "config": { + "JSON_DIAGNOSTICS": false, + "JSON_DISABLE_ENUM_SERIALIZATION": false, + "JSON_HAS_CPP_11": true, + "JSON_HAS_CPP_14": false, + "JSON_HAS_CPP_17": false, + "JSON_HAS_CPP_20": false, + "JSON_HAS_CPP_23": false, + "JSON_HAS_EXPERIMENTAL_FILESYSTEM": false, + "JSON_HAS_FILESYSTEM": false, + "JSON_HAS_THREE_WAY_COMPARISON": false, + "JSON_NOEXCEPTION": false, + "JSON_NO_IO": false, + "JSON_USE_IMPLICIT_CONVERSIONS": true, + "JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON": false, + "NLOHMANN_JSON_ABI_STRING": "json_v3_11_0" }, "copyright": "(C) 2013-2022 Niels Lohmann", "name": "JSON for Modern C++", - "platform": "apple", + "platform": "linux", "url": "https://github.com/nlohmann/json", "version": { "major": 3, From b65a9045741593414f3b245909efabac62de5cce Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 1 Aug 2022 12:34:43 +0200 Subject: [PATCH 10/15] Update unit test meta --- tests/src/unit-meta.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/src/unit-meta.cpp b/tests/src/unit-meta.cpp index a6a1f0015..8d78c00c9 100644 --- a/tests/src/unit-meta.cpp +++ b/tests/src/unit-meta.cpp @@ -28,10 +28,19 @@ TEST_CASE("version information") {"patch", 1} })); - CHECK(j.find("platform") != j.end()); - CHECK(j.at("compiler").find("family") != j.at("compiler").end()); - CHECK(j.at("compiler").find("version") != j.at("compiler").end()); - CHECK(j.at("compiler").find("c++") != j.at("compiler").end()); + CHECK(j.contains("platform")); + CHECK(j.contains("compiler")); + CHECK(j.contains("config")); + + const auto& j_cxx = j["compiler"]; + CHECK(j_cxx.contains("family")); + CHECK(j_cxx.contains("version")); + CHECK(j_cxx.contains("c++")); + CHECK(j_cxx.contains("libc++")); + + const auto& j_lib = j_cxx["libc++"]; + CHECK(j_lib.contains("family")); + CHECK(j_lib.contains("version")); } } From 34ac1f2c2d7fd91c6a92d1341f21edd66a0f9864 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Tue, 10 May 2022 21:07:54 +0200 Subject: [PATCH 11/15] Move test-related CMake files into tests/cmake --- tests/CMakeLists.txt | 2 ++ {cmake => tests/cmake}/download_test_data.cmake | 0 {cmake => tests/cmake}/test.cmake | 0 3 files changed, 2 insertions(+) rename {cmake => tests/cmake}/download_test_data.cmake (100%) rename {cmake => tests/cmake}/test.cmake (100%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7be1c057c..f13bbf4c7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,6 +6,8 @@ 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.") +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) + include(test) ############################################################################# diff --git a/cmake/download_test_data.cmake b/tests/cmake/download_test_data.cmake similarity index 100% rename from cmake/download_test_data.cmake rename to tests/cmake/download_test_data.cmake diff --git a/cmake/test.cmake b/tests/cmake/test.cmake similarity index 100% rename from cmake/test.cmake rename to tests/cmake/test.cmake From d8d9d635361e022387c52a99503a2e3eaa295dd4 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 1 Aug 2022 09:21:28 +0200 Subject: [PATCH 12/15] Cleanup ci.cmake --- cmake/ci.cmake | 223 +++++++++++++++++++++++++++---------------------- 1 file changed, 125 insertions(+), 98 deletions(-) diff --git a/cmake/ci.cmake b/cmake/ci.cmake index 22cf09093..3415bfc36 100644 --- a/cmake/ci.cmake +++ b/cmake/ci.cmake @@ -413,23 +413,25 @@ set(GCC_CXXFLAGS -Wzero-length-bounds ) +set(binary_dir ${PROJECT_BINARY_DIR}/build_gcc) add_custom_target(ci_test_gcc COMMAND CXX=${GCC_TOOL} CXXFLAGS="${GCC_CXXFLAGS}" ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_gcc - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_gcc - COMMAND cd ${PROJECT_BINARY_DIR}/build_gcc && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with GCC using maximal warning flags" ) +set(binary_dir ${PROJECT_BINARY_DIR}/build_clang) add_custom_target(ci_test_clang COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS}" ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang - COMMAND cd ${PROJECT_BINARY_DIR}/build_clang && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with Clang using maximal warning flags" ) @@ -438,25 +440,27 @@ add_custom_target(ci_test_clang ############################################################################### foreach(CXX_STANDARD 11 14 17 20) + set(binary_dir ${PROJECT_BINARY_DIR}/build_gcc_cxx${CXX_STANDARD}) add_custom_target(ci_test_gcc_cxx${CXX_STANDARD} COMMAND CXX=${GCC_TOOL} CXXFLAGS="${GCC_CXXFLAGS}" ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_TestStandards=${CXX_STANDARD} - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_gcc_cxx${CXX_STANDARD} - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_gcc_cxx${CXX_STANDARD} - COMMAND cd ${PROJECT_BINARY_DIR}/build_gcc_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with GCC for C++${CXX_STANDARD}" ) + set(binary_dir ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD}) add_custom_target(ci_test_clang_cxx${CXX_STANDARD} COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS}" ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_TestStandards=${CXX_STANDARD} - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} - COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_cxx${CXX_STANDARD} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with Clang for C++${CXX_STANDARD}" ) endforeach() @@ -465,13 +469,14 @@ endforeach() # Disable exceptions. ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_noexceptions) add_custom_target(ci_test_noexceptions COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND} - -DCMAKE_BUILD_TYPE=Debug -GNinja - -DJSON_BuildTests=ON -DCMAKE_CXX_FLAGS=-DJSON_NOEXCEPTION -DDOCTEST_TEST_FILTER=--no-throw - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_noexceptions - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_noexceptions - COMMAND cd ${PROJECT_BINARY_DIR}/build_noexceptions && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + -DCMAKE_BUILD_TYPE=Debug -GNinja + -DJSON_BuildTests=ON -DCMAKE_CXX_FLAGS=-DJSON_NOEXCEPTION -DDOCTEST_TEST_FILTER=--no-throw + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with exceptions switched off" ) @@ -479,13 +484,14 @@ add_custom_target(ci_test_noexceptions # Disable implicit conversions. ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_noimplicitconversions) add_custom_target(ci_test_noimplicitconversions COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND} - -DCMAKE_BUILD_TYPE=Debug -GNinja - -DJSON_BuildTests=ON -DJSON_ImplicitConversions=OFF - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_noimplicitconversions - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_noimplicitconversions - COMMAND cd ${PROJECT_BINARY_DIR}/build_noimplicitconversions && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + -DCMAKE_BUILD_TYPE=Debug -GNinja + -DJSON_BuildTests=ON -DJSON_ImplicitConversions=OFF + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with implicit conversions switched off" ) @@ -493,13 +499,14 @@ add_custom_target(ci_test_noimplicitconversions # Enable improved diagnostics. ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_diagnostics) add_custom_target(ci_test_diagnostics COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND} - -DCMAKE_BUILD_TYPE=Debug -GNinja - -DJSON_BuildTests=ON -DJSON_Diagnostics=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_diagnostics - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_diagnostics - COMMAND cd ${PROJECT_BINARY_DIR}/build_diagnostics && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + -DCMAKE_BUILD_TYPE=Debug -GNinja + -DJSON_BuildTests=ON -DJSON_Diagnostics=ON + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with improved diagnostics enabled" ) @@ -507,13 +514,14 @@ add_custom_target(ci_test_diagnostics # Enable legacy discarded value comparison. ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_legacycomparison) add_custom_target(ci_test_legacycomparison COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND} - -DCMAKE_BUILD_TYPE=Debug -GNinja - -DJSON_BuildTests=ON -DJSON_LegacyDiscardedValueComparison=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_legacycomparison - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_legacycomparison - COMMAND cd ${PROJECT_BINARY_DIR}/build_legacycomparison && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + -DCMAKE_BUILD_TYPE=Debug -GNinja + -DJSON_BuildTests=ON -DJSON_LegacyDiscardedValueComparison=ON + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with legacy discarded value comparison enabled" ) @@ -536,24 +544,26 @@ add_custom_target(ci_test_noglobaludls # Coverage. ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_coverage) +set(binary_dir32 ${PROJECT_BINARY_DIR}/build_coverage32) add_custom_target(ci_test_coverage COMMAND CXX=g++ ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_CXX_FLAGS="--coverage;-fprofile-arcs;-ftest-coverage" -DJSON_BuildTests=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_coverage - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_coverage - COMMAND cd ${PROJECT_BINARY_DIR}/build_coverage && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMAND CXX=g++ ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_CXX_FLAGS="-m32;--coverage;-fprofile-arcs;-ftest-coverage" -DJSON_BuildTests=ON -DJSON_32bitTest=ONLY - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_coverage32 - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_coverage32 - COMMAND cd ${PROJECT_BINARY_DIR}/build_coverage32 && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + -S${PROJECT_SOURCE_DIR} -B${binary_dir32} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir32} -j${N} + COMMAND cd ${binary_dir32} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMAND ${LCOV_TOOL} --directory . --capture --output-file json.info --rc lcov_branch_coverage=1 COMMAND ${LCOV_TOOL} -e json.info ${SRC_FILES} --output-file json.info.filtered --rc lcov_branch_coverage=1 - COMMAND ${CMAKE_SOURCE_DIR}/tests/thirdparty/imapdl/filterbr.py json.info.filtered > json.info.filtered.noexcept + COMMAND ${PROJECT_SOURCE_DIR}/tests/thirdparty/imapdl/filterbr.py json.info.filtered > json.info.filtered.noexcept COMMAND genhtml --title "JSON for Modern C++" --legend --demangle-cpp --output-directory html --show-details --branch-coverage json.info.filtered.noexcept COMMENT "Compile and test with coverage" @@ -565,13 +575,14 @@ add_custom_target(ci_test_coverage set(CLANG_CXX_FLAGS_SANITIZER "-g -O1 -fsanitize=address -fsanitize=undefined -fsanitize=integer -fsanitize=nullability -fno-omit-frame-pointer -fno-sanitize-recover=all -fno-sanitize=unsigned-integer-overflow -fno-sanitize=unsigned-shift-base") +set(binary_dir ${PROJECT_BINARY_DIR}/build_clang_sanitizer) add_custom_target(ci_test_clang_sanitizer COMMAND CXX=${CLANG_TOOL} CXXFLAGS=${CLANG_CXX_FLAGS_SANITIZER} ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_sanitizer - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_sanitizer - COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_sanitizer && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with sanitizers" ) @@ -607,13 +618,14 @@ add_custom_target(ci_test_amalgamation # Build and test using the amalgamated header ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_single_header) add_custom_target(ci_test_single_header COMMAND CXX=${GCC_TOOL} CXXFLAGS="${GCC_CXXFLAGS}" ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_MultipleHeaders=OFF -DJSON_FastTests=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_single_header - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_single_header - COMMAND cd ${PROJECT_BINARY_DIR}/build_single_header && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test single-header version" ) @@ -621,13 +633,14 @@ add_custom_target(ci_test_single_header # Valgrind. ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_valgrind) add_custom_target(ci_test_valgrind COMMAND CXX=${GCC_TOOL} ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_Valgrind=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_valgrind - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_valgrind - COMMAND cd ${PROJECT_BINARY_DIR}/build_valgrind && ${CMAKE_CTEST_COMMAND} -L valgrind --parallel ${N} --output-on-failure + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -L valgrind -j${N} --output-on-failure COMMENT "Compile and test with Valgrind" ) @@ -637,12 +650,13 @@ add_custom_target(ci_test_valgrind set(CLANG_ANALYZER_CHECKS "fuchsia.HandleChecker,nullability.NullableDereferenced,nullability.NullablePassedToNonnull,nullability.NullableReturnedFromNonnull,optin.cplusplus.UninitializedObject,optin.cplusplus.VirtualCall,optin.mpi.MPI-Checker,optin.osx.OSObjectCStyleCast,optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,optin.osx.cocoa.localizability.NonLocalizedStringChecker,optin.performance.GCDAntipattern,optin.performance.Padding,optin.portability.UnixAPI,security.FloatLoopCounter,security.insecureAPI.DeprecatedOrUnsafeBufferHandling,security.insecureAPI.bcmp,security.insecureAPI.bcopy,security.insecureAPI.bzero,security.insecureAPI.rand,security.insecureAPI.strcpy,valist.CopyToSelf,valist.Uninitialized,valist.Unterminated,webkit.NoUncountedMemberChecker,webkit.RefCntblBaseVirtualDtor,core.CallAndMessage,core.DivideZero,core.NonNullParamChecker,core.NullDereference,core.StackAddressEscape,core.UndefinedBinaryOperatorResult,core.VLASize,core.uninitialized.ArraySubscript,core.uninitialized.Assign,core.uninitialized.Branch,core.uninitialized.CapturedBlockVariable,core.uninitialized.UndefReturn,cplusplus.InnerPointer,cplusplus.Move,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,cplusplus.PlacementNew,cplusplus.PureVirtualCall,deadcode.DeadStores,nullability.NullPassedToNonnull,nullability.NullReturnedFromNonnull,osx.API,osx.MIG,osx.NumberObjectConversion,osx.OSObjectRetainCount,osx.ObjCProperty,osx.SecKeychainAPI,osx.cocoa.AtSync,osx.cocoa.AutoreleaseWrite,osx.cocoa.ClassRelease,osx.cocoa.Dealloc,osx.cocoa.IncompatibleMethodTypes,osx.cocoa.Loops,osx.cocoa.MissingSuperCall,osx.cocoa.NSAutoreleasePool,osx.cocoa.NSError,osx.cocoa.NilArg,osx.cocoa.NonNilReturnValue,osx.cocoa.ObjCGenerics,osx.cocoa.RetainCount,osx.cocoa.RunLoopAutoreleaseLeak,osx.cocoa.SelfInit,osx.cocoa.SuperDealloc,osx.cocoa.UnusedIvars,osx.cocoa.VariadicMethodTypes,osx.coreFoundation.CFError,osx.coreFoundation.CFNumber,osx.coreFoundation.CFRetainRelease,osx.coreFoundation.containers.OutOfBounds,osx.coreFoundation.containers.PointerSizedValues,security.insecureAPI.UncheckedReturn,security.insecureAPI.decodeValueOfObjCType,security.insecureAPI.getpw,security.insecureAPI.gets,security.insecureAPI.mkstemp,security.insecureAPI.mktemp,security.insecureAPI.vfork,unix.API,unix.Malloc,unix.MallocSizeof,unix.MismatchedDeallocator,unix.Vfork,unix.cstring.BadSizeArg,unix.cstring.NullArg") +set(binary_dir ${PROJECT_BINARY_DIR}/build_clang_analyze) add_custom_target(ci_clang_analyze COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_analyze - COMMAND cd ${PROJECT_BINARY_DIR}/build_clang_analyze && ${SCAN_BUILD_TOOL} -enable-checker ${CLANG_ANALYZER_CHECKS} --use-c++=${CLANG_TOOL} -analyze-headers -o ${PROJECT_BINARY_DIR}/report ninja + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND cd ${binary_dir} && ${SCAN_BUILD_TOOL} -enable-checker ${CLANG_ANALYZER_CHECKS} --use-c++=${CLANG_TOOL} -analyze-headers -o ${PROJECT_BINARY_DIR}/report ninja COMMENT "Check code with Clang Analyzer" ) @@ -668,11 +682,12 @@ add_custom_target(ci_cpplint # Check code with OCLint. ############################################################################### -file(COPY ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp DESTINATION ${PROJECT_BINARY_DIR}/src_single) -file(RENAME ${PROJECT_BINARY_DIR}/src_single/json.hpp ${PROJECT_BINARY_DIR}/src_single/all.cpp) -file(APPEND "${PROJECT_BINARY_DIR}/src_single/all.cpp" "\n\nint main()\n{}\n") +set(binary_dir ${PROJECT_BINARY_DIR}/build_oclint) +file(COPY ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp DESTINATION ${binary_dir}/src_single/) +file(RENAME ${binary_dir}/src_single/json.hpp ${binary_dir}/src_single/all.cpp) +file(APPEND "${binary_dir}/src_single/all.cpp" "\n\nint main()\n{}\n") -add_executable(single_all ${PROJECT_BINARY_DIR}/src_single/all.cpp) +add_executable(single_all ${binary_dir}/src_single/all.cpp) target_compile_features(single_all PRIVATE cxx_std_11) add_custom_target(ci_oclint @@ -680,15 +695,15 @@ add_custom_target(ci_oclint -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DJSON_BuildTests=OFF -DJSON_CI=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_oclint - COMMAND ${OCLINT_TOOL} -i ${PROJECT_BINARY_DIR}/build_oclint/src_single/all.cpp -p ${PROJECT_BINARY_DIR}/build_oclint -- + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${OCLINT_TOOL} -i ${binary_dir}/src_single/all.cpp -p ${binary_dir} -- -report-type html -enable-global-analysis --max-priority-1=0 --max-priority-2=1000 --max-priority-3=2000 --disable-rule=MultipleUnaryOperator --disable-rule=DoubleNegative --disable-rule=ShortVariableName --disable-rule=GotoStatement --disable-rule=LongLine - -o ${PROJECT_BINARY_DIR}/build_oclint/oclint_report.html + -o ${binary_dir}/oclint_report.html COMMENT "Check code with OCLint" ) @@ -696,13 +711,14 @@ add_custom_target(ci_oclint # Check code with Clang-Tidy. ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_clang_tidy) add_custom_target(ci_clang_tidy COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_CLANG_TIDY=${CLANG_TIDY_TOOL} -DJSON_BuildTests=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_tidy - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_tidy + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} COMMENT "Check code with Clang-Tidy" ) @@ -710,14 +726,15 @@ add_custom_target(ci_clang_tidy # Check code with PVS-Studio Analyzer . ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_pvs_studio) add_custom_target(ci_pvs_studio COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DJSON_BuildTests=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_pvs_studio - COMMAND cd ${PROJECT_BINARY_DIR}/build_pvs_studio && ${PVS_STUDIO_ANALYZER_TOOL} analyze -j 10 - COMMAND cd ${PROJECT_BINARY_DIR}/build_pvs_studio && ${PLOG_CONVERTER_TOOL} -a'GA:1,2;64:1;CS' -t fullhtml PVS-Studio.log -o pvs + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND cd ${binary_dir} && ${PVS_STUDIO_ANALYZER_TOOL} analyze -j${N} + COMMAND cd ${binary_dir} && ${PLOG_CONVERTER_TOOL} -a'GA:1,2;64:1;CS' -t fullhtml PVS-Studio.log -o pvs COMMENT "Check code with PVS Studio" ) @@ -725,10 +742,11 @@ add_custom_target(ci_pvs_studio # Check code with Infer static analyzer. ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_infer) add_custom_target(ci_infer - COMMAND mkdir -p ${PROJECT_BINARY_DIR}/build_infer - COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} compile -- ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${PROJECT_SOURCE_DIR} -DJSON_BuildTests=ON - COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} run -- make + COMMAND mkdir -p ${binary_dir} + COMMAND cd ${binary_dir} && ${INFER_TOOL} compile -- ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${PROJECT_SOURCE_DIR} -DJSON_BuildTests=ON + COMMAND cd ${binary_dir} && ${INFER_TOOL} run -- make COMMENT "Check code with Infer" ) @@ -736,15 +754,16 @@ add_custom_target(ci_infer # Run test suite with previously downloaded test data. ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_offline_testdata) add_custom_target(ci_offline_testdata - COMMAND mkdir -p ${PROJECT_BINARY_DIR}/build_offline_testdata/test_data - COMMAND cd ${PROJECT_BINARY_DIR}/build_offline_testdata/test_data && ${GIT_TOOL} clone -c advice.detachedHead=false --branch v3.1.0 https://github.com/nlohmann/json_test_data.git --quiet --depth 1 + COMMAND mkdir -p ${binary_dir}/test_data + COMMAND cd ${binary_dir}/test_data && ${GIT_TOOL} clone -c advice.detachedHead=false --branch v3.1.0 https://github.com/nlohmann/json_test_data.git --quiet --depth 1 COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja - -DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_TestDataDirectory=${PROJECT_BINARY_DIR}/build_offline_testdata/test_data/json_test_data - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_offline_testdata - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_offline_testdata - COMMAND cd ${PROJECT_BINARY_DIR}/build_offline_testdata && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + -DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_TestDataDirectory=${binary_dir}/test_data/json_test_data + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Check code with previously downloaded test data" ) @@ -752,16 +771,17 @@ add_custom_target(ci_offline_testdata # Run test suite when project was not checked out from Git ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_non_git_tests) add_custom_target(ci_non_git_tests COMMAND git config --global --add safe.directory ${PROJECT_SOURCE_DIR} - COMMAND mkdir -p ${PROJECT_BINARY_DIR}/build_non_git_tests/sources + COMMAND mkdir -p ${binary_dir}/sources COMMAND cd ${PROJECT_SOURCE_DIR} && for FILE in `${GIT_TOOL} ls-tree --name-only HEAD`\; do cp -r $$FILE ${PROJECT_BINARY_DIR}/build_non_git_tests/sources \; done COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_FastTests=ON - -S${PROJECT_BINARY_DIR}/build_non_git_tests/sources -B${PROJECT_BINARY_DIR}/build_non_git_tests - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_non_git_tests - COMMAND cd ${PROJECT_BINARY_DIR}/build_non_git_tests && ${CMAKE_CTEST_COMMAND} --parallel ${N} -LE git_required --output-on-failure + -S${binary_dir}/sources -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} -LE git_required --output-on-failure COMMENT "Check code when project was not checked out from Git" ) @@ -769,13 +789,14 @@ add_custom_target(ci_non_git_tests # Run test suite and exclude tests that change installed files ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_reproducible_tests) add_custom_target(ci_reproducible_tests COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_FastTests=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_reproducible_tests - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_reproducible_tests - COMMAND cd ${PROJECT_BINARY_DIR}/build_reproducible_tests && ${CMAKE_CTEST_COMMAND} --parallel ${N} -LE not_reproducible --output-on-failure + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} -LE not_reproducible --output-on-failure COMMENT "Check code and exclude tests that change installed files" ) @@ -812,12 +833,13 @@ add_custom_target(ci_single_binaries # Benchmarks ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_benchmarks) add_custom_target(ci_benchmarks COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release -GNinja - -S${PROJECT_SOURCE_DIR}/benchmarks -B${PROJECT_BINARY_DIR}/build_benchmarks - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_benchmarks --target json_benchmarks - COMMAND cd ${PROJECT_BINARY_DIR}/build_benchmarks && ./json_benchmarks + -S${PROJECT_SOURCE_DIR}/benchmarks -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} --target json_benchmarks + COMMAND ${binary_dir}/json_benchmarks COMMENT "Run benchmarks" ) @@ -861,22 +883,24 @@ function(ci_add_cmake_flags_targets flag min_version) string(TOLOWER "ci_cmake_flag_${flag}" flag_target) string(REPLACE . _ min_version_var ${min_version}) set(cmake_binary ${CMAKE_${min_version_var}_BINARY}) + set(binary_dir ${PROJECT_BINARY_DIR}/build_${flag_target}) add_custom_target(${flag_target} COMMENT "Check CMake flag ${flag} (CMake ${CMAKE_VERSION})" COMMAND ${CMAKE_COMMAND} - -Werror=dev - -D${flag}=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_${flag_target} + -Werror=dev -D${flag}=ON + -S${PROJECT_SOURCE_DIR} -B${binary_dir} ) + set(binary_dir_min_version ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var}) add_custom_target(${flag_target}_${min_version_var} - COMMENT "Check CMake flag ${JSON_CMAKE_FLAG} (CMake ${min_version})" - COMMAND mkdir -pv ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var} - COMMAND cd ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var} - && ${cmake_binary} -Werror=dev ${PROJECT_SOURCE_DIR} -D${flag}=ON + COMMENT "Check CMake flag ${flag} (CMake ${min_version})" + COMMAND mkdir -pv ${binary_dir_min_version} + COMMAND cd ${binary_dir_min_version} && ${cmake_binary} + -Werror=dev -D${flag}=ON + ${PROJECT_SOURCE_DIR} DEPENDS ${cmake_binary} ) list(APPEND JSON_CMAKE_FLAG_TARGETS ${JSON_CMAKE_FLAG_TARGET} ${flag_target}_${min_version_var}) - list(APPEND JSON_CMAKE_FLAG_BUILD_DIRS ${PROJECT_BINARY_DIR}/build_${flag_target} ${PROJECT_BINARY_DIR}/build_${flag_target}_${min_version_var}) + list(APPEND JSON_CMAKE_FLAG_BUILD_DIRS ${binary_dir} ${binary_dir_min_version}) set(JSON_CMAKE_FLAG_TARGETS ${JSON_CMAKE_FLAG_TARGETS} PARENT_SCOPE) set(JSON_CMAKE_FLAG_BUILD_DIRS ${JSON_CMAKE_FLAG_BUILD_DIRS} PARENT_SCOPE) endfunction() @@ -908,14 +932,15 @@ foreach(COMPILER g++-4.8 g++-4.9 g++-5 g++-6 g++-7 g++-8 g++-9 g++-10 g++-11 cla unset(ADDITIONAL_FLAGS) endif() + set(binary_dir ${PROJECT_BINARY_DIR}/build_compiler_${COMPILER}) add_custom_target(ci_test_compiler_${COMPILER} COMMAND CXX=${COMPILER} ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_FastTests=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_compiler_${COMPILER} + -S${PROJECT_SOURCE_DIR} -B${binary_dir} ${ADDITIONAL_FLAGS} - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_compiler_${COMPILER} - COMMAND cd ${PROJECT_BINARY_DIR}/build_compiler_${COMPILER} && ${CMAKE_CTEST_COMMAND} --parallel ${N} --exclude-regex "test-unicode" --output-on-failure + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} -E "test-unicode" --output-on-failure COMMENT "Compile and test with ${COMPILER}" ) endif() @@ -926,26 +951,28 @@ endforeach() # CUDA example ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_cuda_example) add_custom_target(ci_cuda_example COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_CUDA_HOST_COMPILER=g++-8 - -S${PROJECT_SOURCE_DIR}/tests/cuda_example -B${PROJECT_BINARY_DIR}/build_cuda_example - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_cuda_example + -S${PROJECT_SOURCE_DIR}/tests/cuda_example -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} ) ############################################################################### # Intel C++ Compiler ############################################################################### +set(binary_dir ${PROJECT_BINARY_DIR}/build_icpc) add_custom_target(ci_icpc COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icpc -DJSON_BuildTests=ON -DJSON_FastTests=ON - -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_icpc - COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_icpc - COMMAND cd ${PROJECT_BINARY_DIR}/build_icpc && ${CMAKE_CTEST_COMMAND} --parallel ${N} --exclude-regex "test-unicode" --output-on-failure + -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} -E "test-unicode" --output-on-failure COMMENT "Compile and test with ICPC" ) @@ -954,7 +981,7 @@ add_custom_target(ci_icpc ############################################################################### add_custom_target(ci_test_documentation - COMMAND make CXX="${GCC_TOOL}" check_output_portable -j8 + COMMAND make CXX="${GCC_TOOL}" check_output_portable -j${N} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/docs COMMENT "Check that all examples compile and create the desired output" ) From e5f1821bb3c893d76f2c104cf607ec3bc4ca6ebd Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 1 Aug 2022 08:44:08 +0200 Subject: [PATCH 13/15] Build print_meta target in CI --- .github/workflows/macos.yml | 6 ++++++ .github/workflows/windows.yml | 14 ++++++++++++++ cmake/ci.cmake | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 7eaedd73c..f33cbf903 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -26,6 +26,8 @@ jobs: - uses: actions/checkout@v3 - name: Run CMake run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON + - name: Print JSON meta + run: cmake --build build --target print_meta --parallel 10 - name: Build run: cmake --build build --parallel 10 - name: Test @@ -43,6 +45,8 @@ jobs: - uses: actions/checkout@v3 - name: Run CMake run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_FastTests=ON + - name: Print JSON meta + run: cmake --build build --target print_meta --parallel 10 - name: Build run: cmake --build build --parallel 10 - name: Test @@ -60,6 +64,8 @@ jobs: - uses: actions/checkout@v3 - name: Run CMake run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On -DJSON_TestStandards=${{ matrix.standard }} + - name: Print JSON meta + run: cmake --build build --target print_meta --parallel 10 - name: Build run: cmake --build build --parallel 10 - name: Test diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index fb4b893d6..63845de3e 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -49,6 +49,8 @@ jobs: # platform: ${{ matrix.architecture }} - name: Run CMake run: cmake -S . -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On + - name: Print JSON meta + run: cmake --build build --target print_meta --parallel 10 - name: Build run: cmake --build build --parallel 10 - name: Test @@ -69,6 +71,8 @@ jobs: - name: Run CMake run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="/W4 /WX" if: matrix.build_type == 'Debug' + - name: Print JSON meta + run: cmake --build build --config ${{ matrix.build_type }} --target print_meta --parallel 10 - name: Build run: cmake --build build --config ${{ matrix.build_type }} --parallel 10 - name: Test @@ -81,6 +85,8 @@ jobs: - uses: actions/checkout@v3 - name: Run CMake run: cmake -S . -B build -G "Visual Studio 16 2019" -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX" + - name: Print JSON meta + run: cmake --build build --config Release --target print_meta --parallel 10 - name: Build run: cmake --build build --config Release --parallel 10 - name: Test @@ -101,6 +107,8 @@ jobs: - name: Run CMake run: cmake -S . -B build -G "Visual Studio 17 2022" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="/W4 /WX" if: matrix.build_type == 'Debug' + - name: Print JSON meta + run: cmake --build build --config ${{ matrix.build_type }} --target print_meta --parallel 10 - name: Build run: cmake --build build --config ${{ matrix.build_type }} --parallel 10 - name: Test @@ -113,6 +121,8 @@ jobs: - uses: actions/checkout@v3 - name: Run CMake run: cmake -S . -B build -G "Visual Studio 17 2022" -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX" + - name: Print JSON meta + run: cmake --build build --config Release --target print_meta --parallel 10 - name: Build run: cmake --build build --config Release --parallel 10 - name: Test @@ -130,6 +140,8 @@ jobs: run: curl -fsSL -o LLVM${{ matrix.version }}.exe https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ matrix.version }}.0.0/LLVM-${{ matrix.version }}.0.0-win64.exe ; 7z x LLVM${{ matrix.version }}.exe -y -o"C:/Program Files/LLVM" - name: Run CMake run: cmake -S . -B build -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On + - name: Print JSON meta + run: cmake --build build --target print_meta --parallel 10 - name: Build run: cmake --build build --parallel 10 - name: Test @@ -145,6 +157,8 @@ jobs: - uses: actions/checkout@v3 - name: Run CMake run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -T ClangCL -DJSON_BuildTests=On + - name: Print JSON meta + run: cmake --build build --target print_meta --parallel 10 - name: Build run: cmake --build build --config Debug --parallel 10 - name: Test diff --git a/cmake/ci.cmake b/cmake/ci.cmake index 3415bfc36..a2fd2a3b9 100644 --- a/cmake/ci.cmake +++ b/cmake/ci.cmake @@ -419,6 +419,7 @@ add_custom_target(ci_test_gcc -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with GCC using maximal warning flags" @@ -430,6 +431,7 @@ add_custom_target(ci_test_clang -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with Clang using maximal warning flags" @@ -447,6 +449,7 @@ foreach(CXX_STANDARD 11 14 17 20) -DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_TestStandards=${CXX_STANDARD} -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with GCC for C++${CXX_STANDARD}" @@ -459,6 +462,7 @@ foreach(CXX_STANDARD 11 14 17 20) -DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_TestStandards=${CXX_STANDARD} -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with Clang for C++${CXX_STANDARD}" @@ -475,6 +479,7 @@ add_custom_target(ci_test_noexceptions -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DCMAKE_CXX_FLAGS=-DJSON_NOEXCEPTION -DDOCTEST_TEST_FILTER=--no-throw -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with exceptions switched off" @@ -490,6 +495,7 @@ add_custom_target(ci_test_noimplicitconversions -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_ImplicitConversions=OFF -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with implicit conversions switched off" @@ -505,6 +511,7 @@ add_custom_target(ci_test_diagnostics -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_Diagnostics=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with improved diagnostics enabled" @@ -520,6 +527,7 @@ add_custom_target(ci_test_legacycomparison -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_LegacyDiscardedValueComparison=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with legacy discarded value comparison enabled" @@ -939,6 +947,7 @@ foreach(COMPILER g++-4.8 g++-4.9 g++-5 g++-6 g++-7 g++-8 g++-9 g++-10 g++-11 cla -DJSON_BuildTests=ON -DJSON_FastTests=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} ${ADDITIONAL_FLAGS} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} -E "test-unicode" --output-on-failure COMMENT "Compile and test with ${COMPILER}" @@ -971,6 +980,7 @@ add_custom_target(ci_icpc -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icpc -DJSON_BuildTests=ON -DJSON_FastTests=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} -E "test-unicode" --output-on-failure COMMENT "Compile and test with ICPC" From c4e21ba91a477e58f0c94029f48653357df8503a Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 1 Aug 2022 09:55:14 +0200 Subject: [PATCH 14/15] Silence warning about hidden global declaration --- tests/src/unit-noexcept.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/src/unit-noexcept.cpp b/tests/src/unit-noexcept.cpp index 6ccf6c432..d2ad27061 100644 --- a/tests/src/unit-noexcept.cpp +++ b/tests/src/unit-noexcept.cpp @@ -34,20 +34,18 @@ void to_json(json& /*unused*/, pod_bis /*unused*/) {} void from_json(const json& /*unused*/, pod /*unused*/) noexcept {} void from_json(const json& /*unused*/, pod_bis /*unused*/) {} -json* j = nullptr; - static_assert(noexcept(json{}), ""); -static_assert(noexcept(nlohmann::to_json(*j, 2)), ""); -static_assert(noexcept(nlohmann::to_json(*j, 2.5)), ""); -static_assert(noexcept(nlohmann::to_json(*j, true)), ""); -static_assert(noexcept(nlohmann::to_json(*j, test{})), ""); -static_assert(noexcept(nlohmann::to_json(*j, pod{})), ""); -static_assert(!noexcept(nlohmann::to_json(*j, pod_bis{})), ""); +static_assert(noexcept(nlohmann::to_json(std::declval(), 2)), ""); +static_assert(noexcept(nlohmann::to_json(std::declval(), 2.5)), ""); +static_assert(noexcept(nlohmann::to_json(std::declval(), true)), ""); +static_assert(noexcept(nlohmann::to_json(std::declval(), test{})), ""); +static_assert(noexcept(nlohmann::to_json(std::declval(), pod{})), ""); +static_assert(!noexcept(nlohmann::to_json(std::declval(), pod_bis{})), ""); static_assert(noexcept(json(2)), ""); static_assert(noexcept(json(test{})), ""); static_assert(noexcept(json(pod{})), ""); -static_assert(noexcept(j->get()), ""); -static_assert(!noexcept(j->get()), ""); +static_assert(noexcept(std::declval().get()), ""); +static_assert(!noexcept(std::declval().get()), ""); static_assert(noexcept(json(pod{})), ""); } // namespace @@ -70,7 +68,6 @@ TEST_CASE("runtime checks") SECTION("silence -Wunneeded-internal-declaration errors") { - j = nullptr; json j2; to_json(j2, pod()); to_json(j2, pod_bis()); From 35f6a61dadb7bb2718845272577f592ee788c339 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Tue, 2 Aug 2022 14:06:50 +0200 Subject: [PATCH 15/15] Don't build in parallel to avoid OOM conditions --- cmake/ci.cmake | 58 +++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/cmake/ci.cmake b/cmake/ci.cmake index a2fd2a3b9..40f84b7dc 100644 --- a/cmake/ci.cmake +++ b/cmake/ci.cmake @@ -419,8 +419,8 @@ add_custom_target(ci_test_gcc -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -t print_meta + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with GCC using maximal warning flags" ) @@ -431,8 +431,8 @@ add_custom_target(ci_test_clang -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -t print_meta + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with Clang using maximal warning flags" ) @@ -449,8 +449,8 @@ foreach(CXX_STANDARD 11 14 17 20) -DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_TestStandards=${CXX_STANDARD} -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -t print_meta + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with GCC for C++${CXX_STANDARD}" ) @@ -462,8 +462,8 @@ foreach(CXX_STANDARD 11 14 17 20) -DJSON_BuildTests=ON -DJSON_FastTests=ON -DJSON_TestStandards=${CXX_STANDARD} -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -t print_meta + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with Clang for C++${CXX_STANDARD}" ) @@ -479,8 +479,8 @@ add_custom_target(ci_test_noexceptions -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DCMAKE_CXX_FLAGS=-DJSON_NOEXCEPTION -DDOCTEST_TEST_FILTER=--no-throw -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -t print_meta + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with exceptions switched off" ) @@ -495,8 +495,8 @@ add_custom_target(ci_test_noimplicitconversions -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_ImplicitConversions=OFF -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -t print_meta + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with implicit conversions switched off" ) @@ -511,8 +511,8 @@ add_custom_target(ci_test_diagnostics -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_Diagnostics=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -t print_meta + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with improved diagnostics enabled" ) @@ -527,8 +527,8 @@ add_custom_target(ci_test_legacycomparison -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_LegacyDiscardedValueComparison=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -t print_meta + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with legacy discarded value comparison enabled" ) @@ -559,14 +559,14 @@ add_custom_target(ci_test_coverage -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_CXX_FLAGS="--coverage;-fprofile-arcs;-ftest-coverage" -DJSON_BuildTests=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMAND CXX=g++ ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_CXX_FLAGS="-m32;--coverage;-fprofile-arcs;-ftest-coverage" -DJSON_BuildTests=ON -DJSON_32bitTest=ONLY -S${PROJECT_SOURCE_DIR} -B${binary_dir32} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir32} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir32} COMMAND cd ${binary_dir32} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMAND ${LCOV_TOOL} --directory . --capture --output-file json.info --rc lcov_branch_coverage=1 @@ -589,7 +589,7 @@ add_custom_target(ci_test_clang_sanitizer -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test with sanitizers" ) @@ -632,7 +632,7 @@ add_custom_target(ci_test_single_header -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_MultipleHeaders=OFF -DJSON_FastTests=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} --output-on-failure COMMENT "Compile and test single-header version" ) @@ -647,7 +647,7 @@ add_custom_target(ci_test_valgrind -DCMAKE_BUILD_TYPE=Debug -GNinja -DJSON_BuildTests=ON -DJSON_Valgrind=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -L valgrind -j${N} --output-on-failure COMMENT "Compile and test with Valgrind" ) @@ -726,7 +726,7 @@ add_custom_target(ci_clang_tidy -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_CLANG_TIDY=${CLANG_TIDY_TOOL} -DJSON_BuildTests=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMENT "Check code with Clang-Tidy" ) @@ -741,7 +741,7 @@ add_custom_target(ci_pvs_studio -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DJSON_BuildTests=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND cd ${binary_dir} && ${PVS_STUDIO_ANALYZER_TOOL} analyze -j${N} + COMMAND cd ${binary_dir} && ${PVS_STUDIO_ANALYZER_TOOL} analyze COMMAND cd ${binary_dir} && ${PLOG_CONVERTER_TOOL} -a'GA:1,2;64:1;CS' -t fullhtml PVS-Studio.log -o pvs COMMENT "Check code with PVS Studio" ) @@ -947,8 +947,8 @@ foreach(COMPILER g++-4.8 g++-4.9 g++-5 g++-6 g++-7 g++-8 g++-9 g++-10 g++-11 cla -DJSON_BuildTests=ON -DJSON_FastTests=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} ${ADDITIONAL_FLAGS} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -t print_meta + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} -E "test-unicode" --output-on-failure COMMENT "Compile and test with ${COMPILER}" ) @@ -966,7 +966,7 @@ add_custom_target(ci_cuda_example -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_CUDA_HOST_COMPILER=g++-8 -S${PROJECT_SOURCE_DIR}/tests/cuda_example -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} ) ############################################################################### @@ -980,8 +980,8 @@ add_custom_target(ci_icpc -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icpc -DJSON_BuildTests=ON -DJSON_FastTests=ON -S${PROJECT_SOURCE_DIR} -B${binary_dir} - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} -t print_meta - COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -j${N} + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} -t print_meta + COMMAND ${CMAKE_COMMAND} --build ${binary_dir} COMMAND cd ${binary_dir} && ${CMAKE_CTEST_COMMAND} -j${N} -E "test-unicode" --output-on-failure COMMENT "Compile and test with ICPC" ) @@ -991,7 +991,7 @@ add_custom_target(ci_icpc ############################################################################### add_custom_target(ci_test_documentation - COMMAND make CXX="${GCC_TOOL}" check_output_portable -j${N} + COMMAND make CXX="${GCC_TOOL}" check_output_portable WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/docs COMMENT "Check that all examples compile and create the desired output" )