⚗️ add C++17 copies of the test binaries

This commit is contained in:
Niels Lohmann 2021-10-20 13:03:08 +02:00
parent 879217d008
commit cf2a896bcd
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69

View File

@ -52,6 +52,13 @@ endif()
# one executable for each unit test file # one executable for each unit test file
############################################################################# #############################################################################
# check if compiler supports C++17
foreach(feature ${CMAKE_CXX_COMPILE_FEATURES})
if (${feature} STREQUAL cxx_std_17)
set(compiler_supports_cpp_17 TRUE)
endif()
endforeach()
file(GLOB files src/unit-*.cpp) file(GLOB files src/unit-*.cpp)
foreach(file ${files}) foreach(file ${files})
@ -69,6 +76,7 @@ foreach(file ${files})
target_link_libraries(${testcase} PRIVATE ${NLOHMANN_JSON_TARGET_NAME}) target_link_libraries(${testcase} PRIVATE ${NLOHMANN_JSON_TARGET_NAME})
# add a copy with C++17 compilation # add a copy with C++17 compilation
if (compiler_supports_cpp_17)
file(READ ${file} FILE_CONTENT) file(READ ${file} FILE_CONTENT)
string(FIND "${FILE_CONTENT}" "JSON_HAS_CPP_17" CPP_17_FOUND) string(FIND "${FILE_CONTENT}" "JSON_HAS_CPP_17" CPP_17_FOUND)
if(NOT ${CPP_17_FOUND} EQUAL -1) if(NOT ${CPP_17_FOUND} EQUAL -1)
@ -81,7 +89,7 @@ foreach(file ${files})
) )
target_include_directories(${testcase}_cpp17 PRIVATE ${CMAKE_BINARY_DIR}/include thirdparty/doctest thirdparty/fifo_map) target_include_directories(${testcase}_cpp17 PRIVATE ${CMAKE_BINARY_DIR}/include thirdparty/doctest thirdparty/fifo_map)
target_link_libraries(${testcase}_cpp17 PRIVATE ${NLOHMANN_JSON_TARGET_NAME}) target_link_libraries(${testcase}_cpp17 PRIVATE ${NLOHMANN_JSON_TARGET_NAME})
set_target_properties(${testcase}_cpp17 PROPERTIES CXX_STANDARD 17) target_compile_features(${testcase}_cpp17 PRIVATE cxx_std_17)
if (JSON_FastTests) if (JSON_FastTests)
add_test(NAME "${testcase}_cpp17" add_test(NAME "${testcase}_cpp17"
@ -95,6 +103,7 @@ foreach(file ${files})
) )
endif() endif()
endif() endif()
endif()
if (JSON_FastTests) if (JSON_FastTests)
add_test(NAME "${testcase}" add_test(NAME "${testcase}"