Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: How to use platform toolset as preprocessor directive?

I have two platform toolsets: v110 and v110_xp for my project, and depending on the chosen platform I want to include/exclude part of the code to be compiled.

_MSC_FULL_VER and $(PlatformToolsetVersion) have exactly the same value for both of these platform toolsets. Alternatively, I tried to use $(PlatformToolset) as follows:

_MSC_PLATFORM_TOOLSET=$(PlatformToolset)

but the problem is that $(PlatformToolset) is non-numeric. Was wondering how can I use this non-numeric value as a preprocessor directive?

Trying several solutions I figured out that

_MSC_PLATFORM_TOOLSET='$(PlatformToolset)'

and then

#if (_MSC_PLATFORM_TOOLSET=='v110')
  [Something]
#endif

works fine but

#if(_MSC_PLATFORM_TOOLSET == 'v110_xp')
  [SomethingElse]
#endif

results in "too many character in character constant" error.

For the context please see this similar question: Visual Studio: how to check used C++ platform toolset programmatically

like image 607
hagh Avatar asked Apr 24 '14 20:04

hagh


People also ask

How do I change the platform toolset in Visual Studio?

To change the platform toolsetIn the properties page, select Platform Toolset and then select the toolset you want from the drop-down list. For example, if you've installed the Visual Studio 2010 toolset, select Visual Studio 2010 (v100) to use it for your project. Choose the OK button to save your changes.

How to define_ MSc_ ver?

_MSC_VER Defined as an integer literal that encodes the major and minor number elements of the compiler's version number. The major number is the first element of the period-delimited version number and the minor number is the second element. For example, if the version number of the Microsoft C/C++ compiler is 17.00.

How do I find my platform toolset?

Select and hold (or right-click) the driver project in Solution Explorer and select Properties. In the property pages for the driver project, select Configuration Properties and then select General. Select the Platform Toolset property for the project from the drop-down list.

How do I know which version of Visual Studio toolset I have?

The Visual Studio version number is displayed in the "About" dialog. For instance, for VS2012 I see "Version 11.0. 60610.01", so the major version number is "11". Build tools like bakefile or CMake will create solution files targeted at a Visual Studio major version.


2 Answers

Go to project properties -> C/C++ -> Preprocessor and add the following to Preprocessor Definitions:

_MSC_PLATFORM_TOOLSET_$(PlatformToolset)

Then you can write something like this:

#ifdef _MSC_PLATFORM_TOOLSET_v110
   [Something]
#endif

#ifdef _MSC_PLATFORM_TOOLSET_v110_xp
   [SomethingElse]
#endif

This works for me in VS2010.

like image 113
Kirinyale Avatar answered Oct 11 '22 16:10

Kirinyale


For VS 2012/2013, if you use backwards-compatibility toolset, _USING_V110_SDK71_ will be available for you to use. VS2013 will define same name, regardless of platform toolset name, which is v120_xp.

#if (_MSC_VER >= 1700) && defined(_USING_V110_SDK71_)
    // working in XP-compatibility mode
#endif
like image 24
hydrechan Avatar answered Oct 11 '22 16:10

hydrechan