Quick fix for CMake broken Visual Studio 11 .sln

Current CMake 2.8.6 generates broken .sln files for Visual Studio 11 Developer Preview. The bug has been fixed already in CMake upstream.

Meanwhile, I have become annoyed by manually fixing the solution files. Here is quick .bat script I call from my cmake-{project}.bat proxy scripts I maintain for every project configured with CMake. So the fix is applied automatically every time I run CMake:

@echo off
REM Fix broken Visual Studio 11 .sln generated by CMake 2.8.6 (or earlier)
set SED="C:\Program Files (x86)\GnuWin32\bin\sed.exe"
set SLN=%1
copy %SLN% %SLN%.copy
%SED% "s/Studio 2011/Studio 11/g" %SLN%.copy > %SLN%
del /Q %SLN%.copy

Modular visualizers in Visual Studio 11

Previously, I talked about the new debugger visualizers in Visual Studio 11 (Developer Preview) based on XML. By the way, I haven’t any luck trying to figure out where does the file type .NATVIS come from.

In previous versions of the Visual Studio, all templates of debugger visualizers have to be saved in single file: %VSINSTALLDIR%\Common7\Packages\Debugger\autoexp.dat. In case one wants to extend or improve the templates definition, maintaining everything in one system-wide file is neither practical nor safe.

The visualizers in Visual Studio 11 seem to solve the maintenance hassle by allowing more modular approach. First nice feature is that custom templates can be defined without touching any of the installed Visual Studio files and can be put in %USERPROFILE%\Documents\Visual Studio 11\Visualizers. Second nice feature I’ve just discovered is that definitions of visualizers can be split into several separate .natvis files. It is especially useful if one wants to maintain visualizers grouped according to libraries (e.g. Loki, Boost, POCO).

Basically, %USERPROFILE%\Documents\Visual Studio 11\Visualizers works like a package of custom visualizers now:

vs11-user-natvis

Having the visualizers diagnostics enabled, whole process of parsing and loading .natvis files will be traced in Visual Studio 11 output window:

vs11-modular-natvis

No more copying and pasting debugger visualizers for Boost and others into big muddy autoexp.dat.

BTW, who knows where does NATVIS come from, hmm? :-)

Setting EnableNatvisDiagnostics in Visual Studio 11

Previously, I posted about the new XML-style debugger visualizers I discovered in Visual Studio 11. I mentioned that one of reasons the feature has been redesigned is to enable debugging of the visualizers templates defined in default or user-defined .natvis files. So, it looks there is something more to discover: how to actually make use of the diagnostics capability.

Unfortunately, it seems the new debugger visualizers have not been documented anywhere. At the time of writing this blog, Google reports one link about defaultvis.natvis, it is the brief post on Visual C++ forum.

Luckily, there is a short manual included as comment in header of the %ProgramFiles%\Microsoft Visual Studio 11.0\Common7\Packages\Debugger\Visualizers\defaultvis.natvis file. It says:

1) give better diagnostic reporting.
a) Set the name-value entry under the Debugger registry key: EnableNatvisDiagnostics which is a REG_DWORD to a value of 1 this will output each expression string that is evaluated under the native visualizer into the output window and is good for debugging type definition typos in .natvis files.

The first thing is to figure out where to set the EnableNatvisDiagnostics flag. The Visual Studio 11 installer does not put it into the registry. Also, there are several Debugger keys. However, a few experiments proved the flag should be set under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\11.0\Debugger:

vs11-visualizers-enable-natvis-diagnostics

Once it is set, every time Visual Studio 11 debugger is launched and use of visualized types is determined, the .natvis files are parsed and evaluated templates validated. The process is reported in the Output window:

vs11-evaluating-visualizer-1

If anything goes wrong, a type definition template is incorrect and its evaluation fails, it is also reported in the Output window:

vs11-evaluating-visualizer-2-validation

It will be a very useful feature especially when defining visualizers of complex types. Previous versions of Visual Studio used old format of templates defined in autoexp.dat file which stated its own DSL based on regular expressions, so the syntax was complex and fragile, and as Andy Pennel has confessed, not documented. (Here kudos to Avery Lee who did great job reverse-engineering the autoexp.dat syntax.)

At least, this time folks get the XML Schema for the Visual Studio debugger visualizers.

Debugger visualizers in Visual Sudio 11 Developer Preview

Visual Studio 11 Developer Preview introduces new style debugger visualizers. The autoexp.dat definition of templates in previous versions of the Visual Studio debugger is being replaced with new style definitions based on XML and stored in defaultvis.natvis file.

Microsoft explains the motivation behind redesigning the native type visualization mechanism is to give better diagnostic reporting (visualizer expressions can be now evaluated and displayed in the output window to help debugging .natvis file), provide XSD schema defining type definition, support of multiple files for type definition: system-wide in %ProgramFiles%\Microsoft Visual Studio 11.0\Common7\Packages\Debugger\Visualizers\defaultvis.natvis and user-defined in %USERPROFILE%\My Documents\Visual Studio Dev11\Visualizers\xxx.natvis.

It sounds really good and has a great usability potential for programmers who uses C++ generative programming capabilities, defines complex C++ types, heavily uses C++ Standard Library and Boost C++ Libraries.

Here is example of new style visualizer defined in XML copied from the defaultvis.natvis:

  <!--std::unique_ptr from <memory>-->
  <Type Name="std::unique_ptr<*>">
    <DisplayString Condition="_Myptr == 0">empty</DisplayString>
    <DisplayString>unique_ptr {*_Myptr}</DisplayString>
    <Expand>
      <Item Name="[ptr]" Condition="_Myptr != 0">_Myptr</Item>
    </Expand>
  </Type>

For most types from C++ Standard Library and Windows SDK, the new visualizers work very well. However, the currently available Visual Studio 11 Developer Preview (Version 11.0.40825.2 PREREL) is shipped with incorrect definitions in the defaultvis.natvis. The C++TR1 definitions introduced in Visual Studio 2008 are only forwarded (aliased) from std:tr1:: to std:: in Visual Studio 2010. In Visual Studio 11, they have completely moved from std::tr1:: to std:: to align with C++11 standard. But, the new visualizers in defaultvis.natvis define templates are still referring to the C++11 types in std::tr1:: namespace.

This prevents the correct visualization for types like std::shared_ptr:

vs11-visualizers-broken-2

There is an easy workaround possible:

  1. Make private copy of defaultvis.natvis in %USERPROFILE%\My Documents\Visual Studio Dev11\Visualizers\xxx.natvis where xxx is your preferred name.
  2. Open xxx.natvis in a text editor.
  3. Find std::tr1:: and replace with std::.
  4. Save the changes and relaunch the Visual Studio 11.
  5. You should see objects of the C++11 types correctly visualized.

vs11-visualizers-fixed-3

I have reported this issue to Microsoft Connect in Incorrect Type Name references in defaultvis.natvis visualizers for standard library ticket.

File version is not supported by the launcher

UPDATE: This bug (see below) has been fixed a few days ago. The fix is available in CMake git repo and should be release in the upcoming CMake 2.8.7 release.

What is the difference between these two Visual Studio solution (.sln) files?

vs11-cmake-sln-version-compare

They both have been generated using CMake 2.8.6. However, having Visual Studio 11 Developer Preview installed, every time I try to launch the Hello2011.sln I’m getting mysterious error message: File version is not supported by the launcher.

Quick look at what CMake actually outputs in to .sln confirms there is a bug. CMake generates .sln file signature which does not match release version/name of the Visual Studio 11. In Hello2011.sln CMake generated:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2011

but correct version of the output, fixed in Hello11.sln, is this:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 11

Bug report submitted to CMake developers.

By the way, I have to admit different icons displayed for correct and incorrect .sln file are quite useful.

FindBoost.cmake patched for Visual Studio 11

My patch updating CMake module FindBoost.cmake for Boost C++ Libraries lookup has been accepted and committed to the CMake Git repository. Thanks to Brad King for quick review.

The patch adds most recent versions of Boost 1.47 and 1.48 to the lookup table and uses correct toolset tag vc110 (see Library Naming) when checking for libraries built using Visual Studio 11.

OSGeo Charter Nomination for Martin Daly

This month, OSGeo Foundation is conducting annual election of new OSGeo Charter Members.

I have nominated Martin Daly (CTO of Cadcorp) for Charter Member of the OSGeo Foundation.

Martin has long-standing experience in development of geospatial software and development, and adoption of open standards for geospatial under his belt.

Martin has used and supported numerous open source software projects. Martin led Cadcorp to offer first implementation of PostGIS by a GIS vendor, to become a GDAL/OGR Silver Sponsor, to contribute funds and time of Cadcorp development team to make the wheels of PostGIS Raster project (aka WKT Raster) spinning. Improvements in PostgreSQL are also on not-a-short list of contributions to the Free and Open Source Software projects, as is GEOS.

Martin was one of the original members of the OGC Architecture Board (OAB). He was also the main author of the OpenGIS Coordinate Transformation Services Specification as well as participated in developing several other OpenGIS specifications. Martin is one of authors of the GeoJSON Format Specification and actively participates in future development of GeoJSON.

Martin is a member of the Advisory Board of the Open Source Geospatial Lab (OSGL) at the University of Nottingham Centre for Geospatial Science.

Martin also participates and leads Cadcorp involvement in the annual FOSS4G WMS Benchmark.

I believe Martin Daly’s experience and contributions make him a valuable candidate for the OSGeo Charter Member.