question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for Visual Studio toolsets

See original GitHub issue

This 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 and v140_xp. In case, someone added the “Clang with Microsoft CodeGen” package, there is v140_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:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:19 (13 by maintainers)

github_iconTop GitHub Comments

6reactions
ras0219-msftcommented, Feb 13, 2017

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.

2reactions
memshardedcommented, Jun 20, 2017

I think the line:

$ conan install -s compiler="clang"

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:

$ conan install -s compiler="Visual Studio" -s compiler.version=15 -s compiler.toolset="LLVM-vs2014"

I agree this would be useful, we should revise this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio toolset setup - Microsoft Game Development Kit
Lists the required Visual Studio and Visual Studio Build Tools components for building without installing the Microsoft Game Development ...
Read more >
All of 'Platform Toolset' not installed. - Visual Studio Feedback
To build using the v150 build tools, please install v150 build tools. Alternatively, you may upgrade to the current Visual Studio tools by...
Read more >
How to install (v142) Build tools in Visual studio - Stack Overflow
Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting ...
Read more >
Specify a Base Platform Toolset - Intel
Support for Microsoft Visual Studio 2017 is deprecated as of the Intel® oneAPI 2022.1 release, and will be removed in a future release....
Read more >
Setting up the Microsoft Build Tools For Visual Studio 2019 for ...
The Build Tools component of the Microsoft Visual C++ Compiler is ... difficulties with these installations please contact Maplesoft Technical Support.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found