How to generate Visual Studio Solutions for Multi-targetting via CMake? - c++

Visual Studio, as of VS2010, supports the concept of multi-targetting, where a solution can be configured for, and built with, the compiler, libraries and includes of preceding Visual Studio versions. For example, the 2010 IDE can be used to build with the v90 (2008) toolset; in 2012 IDE can be used to build with v90, v100, v110 and v110_xp toolchains, and so on.
The question is this; how to configure a CMake build system, already setup to generate solutions for Visual Studio N to build with the compiler etc of Visual Studio N, to permit building with Visual Studio N-M from within the IDE.
While toolset selection should work merely by -T toolset, the issue is that this then in turn provokes a failure in cmake-2.8/Modules/CMakeTestCXXCompiler.cmake , claiming that the cl.exe is not able to compile a simple program. This is not the case, however, in selecting a toolset within a Visual Studio version e.g. v110_xp in Visual Studio 2012. There seems to be some complication in toolsets across Visual Studio versions, as opposed to toolsets within Visual Studio versions.
Does anyone have concrete experience of CMake in this usecase, in generating solutions for toolsets from preceding versions for use in the IDE of the current version of Visual Studio?

That's covered by the CMake's command-line option -T (toolset selection), available since CMake 2.8.11. The syntax is simple:
cmake ... -T "the string VS uses to identify the toolset" ...
So, for example:
cmake ... -T v90 ...
Note that so far, this option does not have a dedicated widget in the GUI.

Related

CMake and multiple Visual Studio installations using the same compiler version

Scenario
A colleague set up a system a while back. They installed Visual Studio 15 Comminity Edition, merely to test the build process.
At some later point, another colleague was assigned to use that machine. Unbeknownst to them, there was Visual Studio 15 still installed on this machine, but since we have commercial licenses they installed Visual Studio 15 Professional in addition to the alrready installed Community Edition.
Behavior
It is of important note, that the Community Edition installation had the MFC toolset installed, while the Professional Edition installation had not.
Afterwards, the second colleague used our automated procedure to call CMake to first generate project files for Visual Studio, then used the standard command to execute the build pipeline:
cmake -G "Visual Studio 15 Win64" .
This resulted in compilation errors, because the Professional Edition did not have the MFC toolset available and thus the build pipeline failed. Yet within the IDE compilation was successful. After a short while was discovered, that opening "Visual Studio" via Windows start menu resulted in opening the Community Edition rather than the Professional Edition. Since the MFC toolset was then availale, IDE compilation was successful.
Question
Is the solution to this problem as obvious as it seems or does CMake have some way to determine which compiler to use?
Currently I have the following assumptions and would like to validate or refute them:
Each of the Visual Studio versions came with their own compiler for which the respective installers are able to enable/disable additional toolsets.
These two Visual Studio versions do not share the same comiler. (That they do not share toolsets does seem obvious)
CMake has no additional settings to declare which of the compilers of these distinct Visual Studio installations is to be used to execute the build pipeline.
The reason CMake utilized the Professional Edition compiler to execute the build pipeline is merely because the Professional version was installed second, likely overriding a path (registry entry?) CMake uses to find the compiler.
Is this assessment correct? Did something else happen here?

The build tools for Visual Studio 2008 (Platform Toolset = 'v90') cannot be found

I'm trying to build project c++ on vs2017 but there error appear:
"The build tools for Visual Studio 2008 (Platform Toolset = 'v90') cannot be found " after navigation, I must download VS 2008 I have installed it, but problem still exist .
any Suggestion ?
You need:
An MSVC 9.0 compiler toolchain
https://wiki.python.org/moin/WindowsCompilers lists the products that have it:
VS 2008, "Visual C++" feature and "x64 compilers and tools" subfeature
Express edition only has x86 compilers
Do install SP1 on top of VS2008 -- in vanilla VS2008 installer, installation for many features, including x64 compilers, is broken
WinSDK 6.1
WinSDK 7.0
"Visual C++ Compiler for Python 2.7" package
MsBuild 4.0 toolset configuration files for the above toolchain. (These are the directories c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\<arch>\PlatformToolsets\v90\ with .props and .targets files in them)
The only product I know that has this package is VS 2010 ("Visual C++" feature and "x64 compilers and tools" subfeature).
(WinSDK 7.1 technically has it, too, but its setup is riddled with bugs and broken on an x64 system.)
(You can bypass the buggy installer though if you install <GRMSDK_EN_DVD.iso>\Setup\vc_stdx86\vc_stdx86.msi directly. Despite the name, it has toolset files for all 3 platforms.)
"Visual C++ Compiler for Python 2.7" package is not supported by these toolset configuration files. So if you use it, you'll need to either manually specify its location in one of registry values specified in .props, or modify .props to also look in HKLM\Software\Microsoft\DevDiv\VCForPython.
The projects are targeting the v90 platform toolset. The solution is to either open the .sln file with VS2008 (i.e. use the right tool), or spend some time updating the projects to target the latest platform toolset (i.e. VS2017). To do that, just right click each project, and go to Properties, then look at General | Windows SDK Version. You may have to fix compilation / linker errors following the project upgrade.
It is possible to upgrade the project file from the command line without opening it in Visual Studio. I was running into the same issue, and found another solution in the Microsoft documentation for Visual Studio (https://learn.microsoft.com/en-us/visualstudio/ide/reference/upgrade-devenv-exe?view=vs-2017).
Here are the steps:
Open the developer command prompt for you version of Visual Studio, e.g. 'Developer Command Prompt for VS 2017'.
Navigate to the directory of your project file.
Execute the following command: devenv myproject.sln /upgrade

Visual Studio 2015: how to build ATL projects targeting Visual C++ v120

I am using Visual Studio 2015 Community Edition.
In VS2015 installer, selecting Common Tools and MFC Components under the Visual C++ node, I am able to build ATL based projects.
Selecting Tools and Windows SDKs, under Windows 8.1 and Windows Phone Tools node, I am able to build MFC projects based on Platform Toolset v120, that is Visual Studio 2013.
Now I would like to build an existing ATL project, relatively large, originally built in Visual Studio 2013.
When I set Platform Toolset = 'v120' in the ATL project, the compiler is unable to find the ATL headers.
Is it possible to install them?
Do I have to install both VS2013 and VS2015?
You do need to install the earlier version of Visual Studio if you want to use its compiler toolchain. You can also open a developer command prompt to select the compiler version and use msbuild to build the target using that specific compiler but you still need to have installed the compiler version you need.

What I need to install to compile for Platform Toolset v100 using Visual Studio 2013?

I've just formatted the PC and have Visual Studio 2013 installed. Now, I would like to compile a Visual Studio 2010 C++ solution without convert it and continue targeting v100 platform toolset.
I get the this error:
error MSB8020: The build tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, please install Visual Studio 2010 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Upgrade Solution...". C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets 64 5 TPC30004
and project properties I see that of course I miss the needed toolset.
I can't change the target because cannot force XP users to install the new C++ 2013 re-distributable so probably I should install Visual Studio 2010 to fix the problem, but if possible I would like to avoid it (small SSD at the moment and not much free space).
Are there other options available?
You will need to install the Visual Studio 2010 for that. There is no alternative.
You still can install to a different drive, to keep memory footprint on C: as low as possible.
There's also the option of installing the Windows SDK 7.1, which comes with the same VS2010 Platform Tools in it and is available for free. Unlike the VS2010 Express edition, it also includes the AMD64 (but not the Itanium) version of the tools.

How can I generate a Visual Studio 2012 project targeting Windows XP with CMake?

With Visual Studio 2012 Update 1 released, I am hoping to build a C++ project to support Windows XP. Is there a way to use CMake to generate a project that targets Windows XP? Basically CMake would need to generate a project file that uses Platform Toolset = Visual Studio 2012 - Windows XP (v110_xp).
According to http://www.cmake.org/Bug/view.php?id=10722 the answer is now (soon) yes.
Fixed in Version CMake 2.8.11
A new "generator toolset" feature has been added here:
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7dab9977 [^]
One may now run CMake from the command line with
-G "Visual Studio 10" -T "v90"
in order to build with a specific toolset. We've not yet added a
first-class interface to cmake-gui for this, but one may add the cache
entry "CMAKE_GENERATOR_TOOLSET" to contain the "-T" value before
configuring.
According to http://www.cmake.org/Bug/view.php?id=10722 the answer is no yes.
Update: The bug mentioned above has been resolved with the following comment:
Fixed in Version CMake 2.8.11
A new "generator toolset" feature has been added here:
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7dab9977 [^]
One may now run CMake from the command line with
-G "Visual Studio 10" -T "v90"
in order to build with a specific toolset. We've not yet added a
first-class interface to cmake-gui for this, but one may add the cache
entry "CMAKE_GENERATOR_TOOLSET" to contain the "-T" value before
configuring.
You might also look at the comments made to the other answers.
I think you can just generate a Solution for Visual Studio 2010/2012. Open this solution, open the solution/project in visual Studio, open the properties and reconfigure the Platform toolset to v110_xp.
Then you should be fine. But I'm still searching for the solution how to setupo the command line to build v110_xp programs...
I think the best way to address this problem is use CMake to build your project for Visual Studio 2010 and then open the project with Visual Studio 2012. When you do this the toolset used will be vs2010, which works for WinXP.