Add support for Visual Studio toolsets
See original GitHub issueThis is based on the following SO: How to specify Visual Studio compiler toolset with Conan for CMake?
Visual Studio offers the notion of toolsets, e.g. for Visual Studio 2015 and the optional “Windows XP Support for C++” package, there are the toolsets
v140
andv140_xp
. In case, someone added the “Clang with Microsoft CodeGen” package, there isv140_clang_c2
.With CMake, I can use the
-T
command line flag to specify the toolset to be used for the solution files generated with CMake, e.g.cmake -T v140_clang_c2
will generate the project solution file with “Visual Studio 2015 - Clang with Microsoft CodeGen (v140_clang_c2)” configured as the “Platform Toolset” for all targets.How can I tell Conan on Windows with an appropriate installed Visual Studio to use a specific toolset? Preferably for conanfiles using CMake as the generator.
The only way I could come up with is to add an additional option to all the projects/conanfile.py I’d like to use with different toolsets and add another package option (e.g. used as
-o toolset=v140_clang_c2
) to be added to the command line of the initial invocation of CMake.I’d expect that variability to be part of the package manager itself rather than the responsibility of the package writers.
SO user drodri suggested the following workaround:
No, conan does not provide this functionality out of the box.
If you want to use them now, conan could be customized to handle different toolsets, I’d do the following:
First, extend the current settings, to account for the toolsets. I wouldn’t use options if you are using different toolsets extensively. You could try to define them as global to Visual Studio:
compiler: ... Visual Studio: runtime: [MD, MT, MTd, MDd] version: ["8", "9", "10", "11", "12", "14", "15"] toolset: [None, v140, v140_xp]
Or if you want to be more specific, define them per version, something like:
compiler: ... Visual Studio: version: "12": toolset: [None, v120, v120_xp] "14": toolset: [None, v140, v140_xp]
Then, it is true that the responsibility to pass the option to cmake, is for the package creator. I would of course just add
"-T %s" % self.settings.compiler.toolset # or "-T %s" % self.settings.compiler.version.toolset
to the cmake command arguments.
What would be necessary to extend conan to support Visual Studio toolsets out-of-the-box without the need of users to alter the settings.yml
and without package managers to add the -T
parameter to the call to CMake manually?
I’d be happy to provide a PR in case this feature is something the conan maintainers are willing to integrate.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:19 (13 by maintainers)
v120 inside the VS2015 IDE/MSBuild will invoke the toolchain from 2013 exactly* the same as if you built from VS2013 IDE/MSBuild. The binaries built using v120 should be exactly identical regardless of which MSBuild they are built using.
You probably care only about the toolset version and not at all about the IDE version (except that you may need to invoke the MSBuild of >= the toolset version). Wherever you are saying “VS2012”, you probably really mean the v110 toolset, regardless of the IDE.
The point above about runtimes is that (until 2015/2017) each toolchain corresponds with a completely incompatible CRT, so you can’t mix and match. VS2017 has retained full binary compatibility with 2015, corresponding with a minor bump in the toolset version (
v140
->v141
).* There are a few very subtle MSBuild differences, but most projects shouldn’t notice.
I think the line:
should be used to directly define the clang compiler, not the MSVC compiler with the clang toolset. For that, I guess the line could be more like the one you defined:
I agree this would be useful, we should revise this.