Merge pull request #844 from TinyTinni/develop

Add .natvis for MSVC debug view
This commit is contained in:
Niels Lohmann 2017-12-04 21:43:22 +01:00 committed by GitHub
commit f4c01601fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 2 deletions

View file

@ -36,6 +36,18 @@ target_include_directories(
INTERFACE $<INSTALL_INTERFACE:include/>
)
## add debug view defintion file for msvc (natvis) [cmake <= 3.2.2 does not support export of source files]
if (MSVC AND CMAKE_VERSION VERSION_GREATER "3.2.2")
set(NLOHMANN_ADD_NATVIS TRUE)
set(NLOHMANN_NATVIS_FILE "nlohmann_json.natvis")
target_sources(
${NLOHMANN_JSON_TARGET_NAME}
INTERFACE
$<INSTALL_INTERFACE:${NLOHMANN_NATVIS_FILE}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${NLOHMANN_NATVIS_FILE}>
)
endif()
##
## TESTS
## create and configure the unit test target
@ -67,6 +79,12 @@ install(
FILES ${NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE} ${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE}
DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR}
)
if (NLOHMANN_ADD_NATVIS)
install(
FILES ${NLOHMANN_NATVIS_FILE}
DESTINATION .
)
endif()
install(
TARGETS ${NLOHMANN_JSON_TARGET_NAME}
EXPORT ${NLOHMANN_JSON_TARGETS_EXPORT_NAME}

32
nlohmann_json.natvis Normal file
View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="nlohmann::basic_json&lt;*&gt;">
<DisplayString Condition="m_type == nlohmann::detail::value_t::null">null</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::object">{*(m_value.object)}</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::array">{*(m_value.array)}</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::string">{*(m_value.string)}</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::boolean">{m_value.boolean}</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::number_integer">{m_value.number_integer}</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::number_unsigned">{m_value.number_unsigned}</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::number_float">{m_value.number_float}</DisplayString>
<DisplayString Condition="m_type == nlohmann::detail::value_t::discarded">discarded</DisplayString>
<Expand>
<ExpandedItem Condition="m_type == nlohmann::detail::value_t::object">
*(m_value.object),view(simple)
</ExpandedItem>
<ExpandedItem Condition="m_type == nlohmann::detail::value_t::array">
*(m_value.array),view(simple)
</ExpandedItem>
</Expand>
</Type>
<!-- skip the pair first/second members in the treeview while traversing a map.
Only works in VS 2015 Update 2 and beyond using the new visualization -->
<Type Name="std::pair&lt;*, nlohmann::basic_json&lt;*&gt;&gt;" IncludeView="MapHelper">
<DisplayString>{second}</DisplayString>
<Expand>
<ExpandedItem>second</ExpandedItem>
</Expand>
</Type>
</AutoVisualizer>

View file

@ -101,7 +101,7 @@ foreach(file ${files})
target_compile_definitions(${testcase} PRIVATE CATCH_CONFIG_FAST_COMPILE)
target_include_directories(${testcase} PRIVATE "thirdparty/catch")
target_link_libraries(${testcase} ${JSON_TARGET_NAME})
target_link_libraries(${testcase} ${NLOHMANN_JSON_TARGET_NAME})
if(NOT MSVC)
set_target_properties(${testcase} PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-float-equal")