[CMake] How to get current visualstudio version?

Nils Gladitz nilsgladitz at gmail.com
Fri Dec 25 07:40:09 EST 2015


On 25.12.2015 10:36, Xi Shen wrote:
> Hi,
>
> I know I can check MSVC to determine if the Visual Studio generator is 
> used. But how do I find out which version is been used?

MSVC indicates that the Visual C++ compiler (or something compatible) is 
being used; which does not necessarily mean a Visual Studio generator.
If you do need to make that distinction you can check MSVC_IDE [1] instead.

>
> The reason I want to find the the version of VS being used, is because 
> I need to link to the Boost libraries. Boost create its libraries with 
> suffixes like "-vs120-mt", etc. and "vs120" indicates Visual Studio 2013.

Why aren't you using the Boost find module[2] included with CMake? It 
already accounts for Boost's library name mangling.

The module uses e.g. the MSVC12 [3] variable to detect "vc120".
But I am guessing CMAKE_<LANG>_COMPILER_VERSION [4] might work for this 
use case nowadays as well.

Nils

[1] https://cmake.org/cmake/help/v3.4/variable/MSVC_IDE.html
[2] https://cmake.org/cmake/help/v3.4/module/FindBoost.html
[3] https://cmake.org/cmake/help/v3.4/variable/MSVC12.html
[4] 
https://cmake.org/cmake/help/v3.4/variable/CMAKE_LANG_COMPILER_VERSION.html


More information about the CMake mailing list