Conditional compiling according to VC++ compiler version

5.7k Views Asked by At

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?

3

There are 3 best solutions below

1
On BEST ANSWER

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.

1
On

Have you tried _MSC_VER. For Microsoft`s C++ compiler this will give the major and minor version number of the compiler. It could be used as the delimeter.

4
On

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