[CMake] CMake 3.7.0-r2 Open Project sometimes picks wrong version of Visual Studio

Taylor Braun-Jones taylor at braun-jones.org
Tue Nov 8 10:13:59 EST 2016


On Fri, Nov 4, 2016 at 2:55 PM, Brad King <brad.king at kitware.com> wrote:
>
> On 11/03/2016 06:04 PM, John Drescher wrote:
> > I opened a project in cmake-gui using the open project button from a
> > vc 2010 build of a project. The open project opened the project in
> > Visual Studio 2010. Later I opened the same project but a different
> > build tree for Visual Studio 2013 CMake-gui had all of the correct
> > information for the Visual Studio 2013 build but open project tried to
> > open the Visual Studio 2013 solution in Visual Studio 2010 instead of
> > the expected Visual Studio 2013.

I'm guessing you established MSVS2010 as the default application for
opening .sln files the first time you used the open project button.
What happens if you double click on that MSVS2013 .sln file?

> The feature is new in 3.7 and was contributed here:
>
>  cmake-gui: Add button to open the generated project
>  https://gitlab.kitware.com/cmake/cmake/commit/1ca2d5d1
>
> I'm not particularly familiar with how it works, but from a quick
> glance at the code it may be using file associations.

Yes, it's just using Windows file file associations, but it shouldn't.
Since it's possible (and fairly common) to have more than one version
of Visual Studio installed on a system the Open Project button should
be smarter and use ${CMAKE_VS_DEVENV_COMMAND} to open the .sln file.
It should be something like this:

MSVS2015: %VS140COMNTOOLS%..\IDE\devenv.com
MSVS2013: %VS120COMNTOOLS%..\IDE\devenv.com
MSVS2012: %VS110COMNTOOLS%..\IDE\devenv.com
MSVS2010: %VS100COMNTOOLS%..\IDE\devenv.com

If the correct devenv.exe path does not exist or can't be determined
for some reason, then I guess it makes sense to fall back to using
`QDesktopServices::openUrl` to try to open the .sln file with the
Windows file associations.

Taylor


More information about the CMake mailing list