Skip to content

Commit 7ef57ea

Browse files
committed
Добавлен natvis файл для MSVC отладчика.
1 parent 83871f3 commit 7ef57ea

3 files changed

Lines changed: 72 additions & 50 deletions

File tree

CMakeLists.txt

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
cmake_minimum_required (VERSION 3.20)
1+
cmake_minimum_required(VERSION 3.20)
22
include(cmake/prelude.cmake)
33
include(CMakeDependentOption)
44
include(FetchContent)
55

6-
project (
7-
simjson
6+
project(
7+
simjson
88
VERSION 1.0.0
99
DESCRIPTION "Very simple json library"
1010
HOMEPAGE_URL "https://github.com/orefkov/simjson"
@@ -14,12 +14,12 @@ project (
1414
include(cmake/project-is-top-level.cmake)
1515
include(cmake/variables.cmake)
1616

17-
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
18-
set (MSVC_COMPILER ON)
19-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /Zc:strictStrings")
20-
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
21-
set (CLANG_COMPILER ON)
22-
endif ()
17+
if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
18+
set(MSVC_COMPILER ON)
19+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /Zc:strictStrings")
20+
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
21+
set(CLANG_COMPILER ON)
22+
endif()
2323

2424
option(SIMJSON_BUILD_TESTS "Построить тесты" ON)
2525
option(SIMJSON_BENCHMARKS "Построить замеры производительности" OFF)
@@ -38,6 +38,11 @@ target_include_directories(
3838

3939
target_compile_features(simjson_simjson PUBLIC cxx_std_20)
4040

41+
# Для MSVC подключаем natvis файл для красивой отладки
42+
if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
43+
target_link_options(simjson_simjson PUBLIC "/natvis:${CMAKE_CURRENT_SOURCE_DIR}/for_debug/simjson.natvis")
44+
endif()
45+
4146
set_target_properties(
4247
simjson_simjson PROPERTIES
4348
CXX_VISIBILITY_PRESET hidden
@@ -48,39 +53,39 @@ set_target_properties(
4853
OUTPUT_NAME simjson
4954
)
5055

51-
function (Simstr)
52-
set (SIMSTR_BUILD_TESTS OFF)
53-
set (SIMSTR_BENCHMARKS OFF)
54-
if (SIMJSON_SHARED)
55-
set (SIMSTR_SHARED On)
56+
function(Simstr)
57+
set(SIMSTR_BUILD_TESTS OFF)
58+
set(SIMSTR_BENCHMARKS OFF)
59+
if(SIMJSON_SHARED)
60+
set(SIMSTR_SHARED On)
5661
endif()
57-
FetchContent_Declare(
58-
simstr
59-
GIT_REPOSITORY https://github.com/orefkov/simstr.git
60-
GIT_SHALLOW TRUE
61-
GIT_TAG rel.1.1.1
62-
FIND_PACKAGE_ARGS
63-
)
64-
FetchContent_MakeAvailable(simstr)
62+
FetchContent_Declare(
63+
simstr
64+
GIT_REPOSITORY https://github.com/orefkov/simstr.git
65+
GIT_SHALLOW TRUE
66+
GIT_TAG 04d253e
67+
FIND_PACKAGE_ARGS
68+
)
69+
FetchContent_MakeAvailable(simstr)
6570
endfunction()
6671

6772
Simstr()
68-
73+
6974
target_link_libraries(simjson_simjson PUBLIC simstr::simstr)
7075

71-
if (SIMJSON_SHARED)
76+
if(SIMJSON_SHARED)
7277
add_compile_definitions(SIMJSON_SHARED)
7378
target_compile_definitions(simjson_simjson PRIVATE SIMJSON_EXPORT)
7479
endif(SIMJSON_SHARED)
7580

76-
if (SIMJSON_BUILD_TESTS)
81+
if(SIMJSON_BUILD_TESTS)
7782
enable_testing()
78-
set (BUILD_TESTS ON)
83+
set(BUILD_TESTS ON)
7984
# Load and build GTest
8085
FetchContent_Declare(
81-
googletest
82-
# Specify the commit you depend on and update it regularly.
83-
URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip
86+
googletest
87+
# Specify the commit you depend on and update it regularly.
88+
URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip
8489
)
8590

8691
# For Windows: Prevent overriding the parent project's compiler/linker settings
@@ -89,46 +94,46 @@ if (SIMJSON_BUILD_TESTS)
8994
add_subdirectory(tests)
9095
endif()
9196

92-
function (GBencmark)
97+
function(GBencmark)
9398
# Load and build Google benchmarks
9499
include(FetchContent)
95100
FetchContent_Declare(
96-
googlebench
97-
# Specify the commit you depend on and update it regularly.
98-
URL https://github.com/google/benchmark/archive/refs/tags/v1.7.0.zip
101+
googlebench
102+
# Specify the commit you depend on and update it regularly.
103+
URL https://github.com/google/benchmark/archive/refs/tags/v1.7.0.zip
99104
)
100-
set (CMAKE_CXX_STANDARD 20)
101-
set (BENCHMARK_ENABLE_TESTING OFF)
102-
set (BENCHMARK_ENABLE_LTO OFF)
103-
set (BENCHMARK_ENABLE_INSTALL OFF)
104-
set (BENCHMARK_INSTALL_DOCS OFF)
105-
set (BENCHMARK_DOWNLOAD_DEPENDENCIES ON)
106-
set (BENCHMARK_ENABLE_GTEST_TESTS OFF)
105+
set(CMAKE_CXX_STANDARD 20)
106+
set(BENCHMARK_ENABLE_TESTING OFF)
107+
set(BENCHMARK_ENABLE_LTO OFF)
108+
set(BENCHMARK_ENABLE_INSTALL OFF)
109+
set(BENCHMARK_INSTALL_DOCS OFF)
110+
set(BENCHMARK_DOWNLOAD_DEPENDENCIES ON)
111+
set(BENCHMARK_ENABLE_GTEST_TESTS OFF)
107112
add_compile_definitions(BENCHMARK_STATIC_DEFINE)
108113
FetchContent_MakeAvailable(googlebench)
109114
endfunction()
110115

111-
if (SIMJSON_BENCHMARKS)# AND CMAKE_BUILD_TYPE STREQUAL Release)
112-
set (BUILD_BENCHMARKS ON)
116+
if(SIMJSON_BENCHMARKS) # AND CMAKE_BUILD_TYPE STREQUAL Release)
117+
set(BUILD_BENCHMARKS ON)
113118
GBencmark()
114119
add_subdirectory(bench)
115-
endif ()
120+
endif()
116121

117122
# ---- Install rules ----
118123

119124
if(NOT CMAKE_SKIP_INSTALL_RULES)
120-
include(cmake/install-rules.cmake)
125+
include(cmake/install-rules.cmake)
121126
endif()
122127

123128
# ---- Developer mode ----
124129

125130
if(NOT simjsons_DEVELOPER_MODE)
126-
return()
131+
return()
127132
elseif(NOT PROJECT_IS_TOP_LEVEL)
128-
message(
129-
AUTHOR_WARNING
130-
"Developer mode is intended for developers of simjson"
131-
)
133+
message(
134+
AUTHOR_WARNING
135+
"Developer mode is intended for developers of simjson"
136+
)
132137
endif()
133138

134139
include(cmake/dev-mode.cmake)

for_debug/simjson.natvis

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Файл с описанием визуализации simjson для Visual Studio -->
3+
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
4+
<Type Name="simjson::JsonValueTempl&lt;*&gt;">
5+
<DisplayString Condition="type_==Json::Type::Null">Null</DisplayString>
6+
<DisplayString Condition="type_==Json::Type::Boolean">bool: {val_.boolean}</DisplayString>
7+
<DisplayString Condition="type_==Json::Type::Text">text: {val_.text}</DisplayString>
8+
<DisplayString Condition="type_==Json::Type::Integer">int: {val_.integer}</DisplayString>
9+
<DisplayString Condition="type_==Json::Type::Real">real: {val_.real}</DisplayString>
10+
<DisplayString Condition="type_==Json::Type::Object">obj: {*val_.object}</DisplayString>
11+
<DisplayString Condition="type_==Json::Type::Array">arr: {*val_.array}</DisplayString>
12+
<DisplayString>[undefined]</DisplayString>
13+
<Expand>
14+
<ExpandedItem Condition="type_==Json::Type::Object">*val_.object</ExpandedItem>
15+
<ExpandedItem Condition="type_==Json::Type::Array">*val_.array</ExpandedItem>
16+
</Expand>
17+
</Type>
18+
</AutoVisualizer>

tests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# CMakeList.txt : CMake project for core_as, include source and define
22
# project specific logic here.
33
#
4-
54
add_executable(test_json test_json.cpp)
65
target_link_libraries(test_json simjson_simjson gtest_main)
76
add_test(NAME test_json COMMAND test_json)

0 commit comments

Comments
 (0)