Skip to content

Commit afaaa71

Browse files
authored
Install GSL.natvis (microsoft#1112)
Turns out supporting GSL.natvis perfectly is quite difficult. There is no universal way to consume .natvis files that would satisfy everyone. I thought the solution was to use the /NATVIS linker option. But it turns out that actually embeds information into the PDB. So I'm not sure how to properly support the Ninja generator... That's not even accounting for the fact target_link_options doesn't play nicely with /NATVIS When you just add the file via target_sources the visual studio solution will just pick it up and recognize it without adding it to the PDB file. Which won't affect the binary and is what most devs want. This all comes down to the fact that /NATVIS files have native integration with visual studio that makes it difficult to use with non-visual studio solutions. /NATVIS almost works but embeds itself into the PDB which not everyone wants, and not everyone generates PDBs either. Docs for natvis files and /NATVIS - https://learn.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects?view=vs-2022 - https://learn.microsoft.com/en-us/cpp/build/reference/natvis-add-natvis-to-pdb?view=msvc-170 So my current solution is to just simplify the existing CMake code, and install the natvis so the user can decide. closes microsoft#1084
1 parent 4b5b5a1 commit afaaa71

File tree

3 files changed

+4
-27
lines changed

3 files changed

+4
-27
lines changed

CMakeLists.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
cmake_minimum_required(VERSION 3.14...3.16)
2-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
3-
include(gsl_functions)
42

53
project(GSL VERSION 4.0.0 LANGUAGES CXX)
64

@@ -19,8 +17,7 @@ target_compile_features(GSL INTERFACE "cxx_std_14")
1917
# Setup include directory
2018
add_subdirectory(include)
2119

22-
# Add natvis file
23-
gsl_add_native_visualizer_support()
20+
target_sources(GSL INTERFACE $<BUILD_INTERFACE:${GSL_SOURCE_DIR}/GSL.natvis>)
2421

2522
if (GSL_TEST)
2623
enable_testing()
@@ -46,4 +43,6 @@ if (GSL_INSTALL)
4643
write_basic_package_version_file(${gls_config_version} COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT)
4744

4845
install(FILES ${gls_config_version} DESTINATION ${cmake_files_install_dir})
46+
47+
install(FILES GSL.natvis DESTINATION ${cmake_files_install_dir})
4948
endif()

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,5 @@ target_link_libraries(foobar PRIVATE Microsoft.GSL::GSL)
214214
```
215215

216216
## Debugging visualization support
217-
For Visual Studio users, the file [GSL.natvis](./GSL.natvis) in the root directory of the repository can be added to your project if you would like more helpful visualization of GSL types in the Visual Studio debugger than would be offered by default.
218217

219-
If you are using CMake this will be done automatically for you.
220-
See `GSL_VS_ADD_NATIVE_VISUALIZERS`
218+
For Visual Studio users, the file [GSL.natvis](./GSL.natvis) in the root directory of the repository can be added to your project if you would like more helpful visualization of GSL types in the Visual Studio debugger than would be offered by default.

cmake/gsl_functions.cmake

-20
This file was deleted.

0 commit comments

Comments
 (0)