CMake:如何指定Visual C ++的版本使用? [英] CMake: how to specify the version of Visual C++ to work with?

查看:4672
本文介绍了CMake:如何指定Visual C ++的版本使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个版本的Visual Studio安装(2010,2012,2015试用版)。



如何强制CMake为特定的VS版本生成makefiles?

解决方案

首先,您可以检查 generators 您的CMake版本支持(以及如何命名) p>

 > cmake.exe --help 
...
以下生成器可用于此平台:
...
Visual Studio 11 2012 [arch] =生成Visual Studio 2012项目文件。
可选[arch]可以是Win64或ARM。
...






给生成器


  1. cmake.exe -GVisual Studio 11..

  2. cmake.exe -GVisual Studio 11 2012..

我更喜欢后者,因为它的清晰。我通常在构建脚本包装器中有这个调用:

  @ECHO off 
IF NOT EXISTBuildDir\ * .sln(
cmake -H。-BBuildDir-GVisual Studio 11 2012

cmake --buildBuildDir--targetALL_BUILD --configRelease






传输到内部缓存的CMake变量名称 CMAKE_GENERATOR 。所以上面的调用相当于


  1. cmake -DCMAKE_GENERATOR =Visual Studio 11 2012 ..






如果你放置一个名为 PreLoad.cmake 的文件并行到你的主要 CMakeLists.txt 文件,你可以强制默认


  1. cmake.exe ..



    PreLoad.cmake

     code> if(NOT$ ENV {VS110COMNTOOLS}STREQUAL)
    设置(CMAKE_GENERATORVisual Studio 11 2012CACHE INTERNAL发电机名称)
    endif $ b







有时您可能还需要添加 -T< toolset-name> -A< platform-name> 选项:


  1. cmake.exe -GVisual Studio 10-Tv90 ..






真正只对编译器感兴趣


  1. \Program Files )\Microsoft Visual Studio 11.0 \VC\vcvarsall.bat



    cmake.exe -G NMake Makefiles..







<参考


I have multiple versions of Visual Studio installed (2010, 2012, 2015 trial).

How can I force CMake to generate the makefiles for a specific VS version? By default it generates for VS2015.

解决方案

First you can check what generators your CMake version does support (and how they are named):

> cmake.exe --help
...
The following generators are available on this platform:
...
  Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
                                 Optional [arch] can be "Win64" or "ARM".    
...


Then you can give the generator with

  1. cmake.exe -G "Visual Studio 11" .. (short name)
  2. cmake.exe -G "Visual Studio 11 2012" .. (full name)

I prefer the later, because of its clarity. And I normally have this call in a build script wrapper:

@ECHO off
IF NOT EXIST "BuildDir\*.sln" (
    cmake -H"." -B"BuildDir" -G"Visual Studio 11 2012"
)
cmake --build "BuildDir" --target "ALL_BUILD" --config "Release"


The full name is transferred to an internal cached CMake variable name CMAKE_GENERATOR. So the above calls are equivalent to

  1. cmake -DCMAKE_GENERATOR="Visual Studio 11 2012" ..


This gives us an interesting possibility. If you place a file called PreLoad.cmake parallel to your main CMakeLists.txt file you can force the default (if available) to take for your project there

  1. cmake.exe ..

    PreLoad.cmake

    if (NOT "$ENV{VS110COMNTOOLS}" STREQUAL "")
        set(CMAKE_GENERATOR "Visual Studio 11 2012" CACHE INTERNAL "Name of generator.")
    endif()
    


Sometimes you may need to add also -T <toolset-name> or -A <platform-name> option:

  1. cmake.exe -G "Visual Studio 10" -T "v90" ..


And last but not least if you are really only interested in the compiler

  1. "\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"

    cmake.exe -G "NMake Makefiles" ..


References

这篇关于CMake:如何指定Visual C ++的版本使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆