From afaaa71bcee45d9c90c21f8bd3ba2b12902242e9 Mon Sep 17 00:00:00 2001 From: jpr42 <109434725+jpr42@users.noreply.github.com> Date: Wed, 10 May 2023 18:02:44 -0600 Subject: [PATCH] Install GSL.natvis (#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 #1084 --- CMakeLists.txt | 7 +++---- README.md | 4 +--- cmake/gsl_functions.cmake | 20 -------------------- 3 files changed, 4 insertions(+), 27 deletions(-) delete mode 100644 cmake/gsl_functions.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index bc1f38c..71bb997 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,4 @@ cmake_minimum_required(VERSION 3.14...3.16) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") -include(gsl_functions) project(GSL VERSION 4.0.0 LANGUAGES CXX) @@ -19,8 +17,7 @@ target_compile_features(GSL INTERFACE "cxx_std_14") # Setup include directory add_subdirectory(include) -# Add natvis file -gsl_add_native_visualizer_support() +target_sources(GSL INTERFACE $) if (GSL_TEST) enable_testing() @@ -46,4 +43,6 @@ if (GSL_INSTALL) write_basic_package_version_file(${gls_config_version} COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT) install(FILES ${gls_config_version} DESTINATION ${cmake_files_install_dir}) + + install(FILES GSL.natvis DESTINATION ${cmake_files_install_dir}) endif() diff --git a/README.md b/README.md index a498637..725bf66 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,5 @@ target_link_libraries(foobar PRIVATE Microsoft.GSL::GSL) ``` ## Debugging visualization support -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. -If you are using CMake this will be done automatically for you. -See `GSL_VS_ADD_NATIVE_VISUALIZERS` +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. diff --git a/cmake/gsl_functions.cmake b/cmake/gsl_functions.cmake deleted file mode 100644 index e01c44a..0000000 --- a/cmake/gsl_functions.cmake +++ /dev/null @@ -1,20 +0,0 @@ -# This cmake module is meant to hold helper functions/macros -# that make maintaining the cmake build system much easier. -# This is especially helpful since gsl needs to provide coverage -# for multiple versions of cmake. -# -# Any functions/macros should have a gsl_* prefix to avoid problems - -# Adding the GSL.natvis files improves the debugging experience for users of this library. -function(gsl_add_native_visualizer_support) - if (MSVC_IDE) - option(GSL_VS_ADD_NATIVE_VISUALIZERS "Configure project to use Visual Studio native visualizers" TRUE) - else() - set(GSL_VS_ADD_NATIVE_VISUALIZERS FALSE CACHE INTERNAL "Native visualizers are Visual Studio extension" FORCE) - endif() - - # add natvis file to the library so it will automatically be loaded into Visual Studio - if(GSL_VS_ADD_NATIVE_VISUALIZERS) - target_sources(GSL INTERFACE $) - endif() -endfunction()