As of Visual Studio 2015, natvis files can be included as part of individual projects, a much better method than manually copying the file to an specific directory in %USERPROFILE%.
I think it should be included in one of the CMakeLists.txt files, does anybody know how I can add it?
So, I’ve investigated this a bit more, and I see that adding a debug visualizer to a (simple test) project adds the following text to the vcxproj file:
(This was an unrelated test project, hence the many path components)
…right after the main.cpp file:
…so that the vcxproj file looks like this:
My question, then, is how can I get CMake to emit the “<Natvis Include=” element when generating the vcxproj files? Any CMake experts?
If CMake CANNOT yet do this, I’ll just file a bug for it.
CMake cannot yet do this. You will need to change the Visual Studio 2015 generator to support the nativs tag. I’m not a CMake developer, but a 5 minutes look at the CMake source code suggests this might be very easy. If you look at cmVisualStudio10TargetGenerator::WriteAllSources(), you’ll see that it calls GetLanguage() on the source file, and depending on which language is set, it uses a different tool. Either ClCompile, MASM, ResourceCompile, etc. It sounds like all you need to do is add another language type, called Natvis, and put it behind a check on the version of the generator to make sure this language is only recognized when VS Version >= 2015.
If it were me, I would whip up a 10 line patch that did exactly this, post it on the CMake dev list, and see what kind of feedback I got.
Assuming you did it that way, the way you would trigger this in CMake is to to add the .natvis file just like any other file, and then after you do:
set_source_file_properties(foo.natvis LANGUAGE natvis)
I haven’t gotten around to this yet because I have some annoying issue with my installation of git (CMake uses git), but I love the idea of whipping up a 10 line patch, and hope to get around to it soon!