Add print_meta target

Add a target to print JSON meta for all tested C++ standard versions.
This commit is contained in:
Florian Albrechtskirchinger 2022-05-09 19:54:57 +02:00
parent c24067e5fc
commit 6a501169c7
No known key found for this signature in database
GPG Key ID: 19618CE9B2D4BE6D

View File

@ -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 $<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/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)