Skip to content

Install GSL.natvis#1112

Merged
dmitrykobets-msft merged 1 commit into
microsoft:mainfrom
jpr42:natvis
May 11, 2023
Merged

Install GSL.natvis#1112
dmitrykobets-msft merged 1 commit into
microsoft:mainfrom
jpr42:natvis

Conversation

@jpr42

@jpr42 jpr42 commented May 10, 2023

Copy link
Copy Markdown
Contributor

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 installing.

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

So my current solution is to just simplify the existing CMake code, and install the natvis so the user can decide.

closes #1084

Comment thread CMakeLists.txt

# Add natvis file
gsl_add_native_visualizer_support()
target_sources(GSL INTERFACE $<BUILD_INTERFACE:${GSL_SOURCE_DIR}/GSL.natvis>)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does nothing on all platforms except for when generating a visual studio project.

In which case you get the .natvis experience that doesn't affect the PDB.

Comment thread CMakeLists.txt

install(FILES ${gls_config_version} DESTINATION ${cmake_files_install_dir})

install(FILES GSL.natvis DESTINATION ${cmake_files_install_dir})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Installing the file at least gives find_package users a chance to decide what they want to do. Versus nothing which is what they currently get.

Comment thread cmake/gsl_functions.cmake
endif()

# add natvis file to the library so it will automatically be loaded into Visual Studio
if(GSL_VS_ADD_NATIVE_VISUALIZERS)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if statement isn't really needed. Just complicates the code IMO. I don't see a reason to keep it.

@dmitrykobets-msft
dmitrykobets-msft merged commit afaaa71 into microsoft:main May 11, 2023
@dmitrykobets-msft

Copy link
Copy Markdown
Member

@jpr42 Thanks a lot for looking into this! Unfortunate that natvis support is so limited, but the cleanup you've done to work around it looks good.

@jpr42
jpr42 deleted the natvis branch May 11, 2023 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cmake] GSL.natvis issues

2 participants