Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional compiling according to VC++ compiler version

I am in the process of migrating our VC++ project from Visual Studio 2005 (VC8) to Visual Studio 2008 (VC9). Some of the projects in the solution have paths to third party libraries in their 'Additional Library Directories' field in the project settings. The paths look something like this:
..\SomeLibrary\Lib\vc9\x86

It would be really useful if I could use one of Visual Studio's "Property Page Macros" to substitute for the compiler version, in much the same way as I can use $(ConfigurationName) to substitue for "Debug" or "Release". Something like the following would be perfect:
..\SomeLibrary\Lib\$(CompilerVersion)\x86

Unfortunately, I can't find an appropriate macro.

Please note that when I say 'macro' I am refering to Visual Studio's "Property Page Macros", not C/C++ preprocessor macros. As far as I am aware you can't use preprocessor directives in the project settings.

Does anyone know of a way to do this?

like image 729
Hoppy Avatar asked Dec 30 '22 08:12

Hoppy


2 Answers

Use _MSC_VER:

#ifndef _MSC_VER
  // not VC++
#elif _MSC_VER < 1400
  // older than VC++ 2005
#elif _MSC_VER < 1500
  // VC++ 2005
#elif _MSC_VER < 1600
  // VC++ 2008
#elif _MSC_VER < 1700
  // VC++ 2010
#else
  // Future versions
#endif

For a more complicated example, see how boost is dealing with VC++ versions here

like image 51
KeatsPeeks Avatar answered Jan 05 '23 19:01

KeatsPeeks


You could use the property page macros $(PlatformToolsetVersion) or $(PlatformToolset) For vc++ 2012, for example, $(PlatformToolsetVersion) resolves to "110" and $(PlatformToolset) resolves to "v110". So adding "vc$(PlatformToolsetVersion)" to your path would add "vc110" under vc11 or "vc90" under vc9.

like image 26
myodo Avatar answered Jan 05 '23 17:01

myodo