[英]Have CMake select MSVC platform toolset explicitly
Hi, I have a problem, that I have a C++ project that uses select C++11/14 features that for the MSVC compiler are at best only present in the CTP_Nov2013 compiler toolset. 嗨,我有一个问题,我有一个C ++项目,该项目使用select C ++ 11/14功能,这些功能最多只能在CTP_Nov2013编译器工具集中提供,而对于MSVC编译器而言。 I am aware that there is a very similar topic here , and that the most relevant answer was that the toolset must not be tinkered with from the script, as the end-user will want to tinker with it.
我知道有一个非常类似的话题在这里 ,和最相关的答复是,该工具包不能从脚本修修补补,为最终用户会想用它修补。
I have found a way to achieve what I wanted with the commands 我找到了一种方法来实现我想要的命令
set(CMAKE_GENERATOR_TOOLSET "CTP_Nov2013" CACHE STRING "Platform Toolset" FORCE)
set(CMAKE_VS_PLATFORM_TOOLSET "CTP_Nov2013" CACHE STRING "Platform Toolset" FORCE)
However the problem with this is that the script needs to be run twice in order for this to take effect. 但是,这样做的问题是脚本需要运行两次才能生效。 Since the cmake command-line is invoked using
由于cmake命令行是使用以下命令调用的
cmake -G"Visual Studio 12 2013 Win64"
There is already a toolset selected, but I immediately wish to override the toolset incorporated into the x64 Configuration of the selected generator. 已经选择了一个工具集,但是我立即希望覆盖合并到所选生成器的x64配置中的工具集。 Ultimately the user selects 32/64-bit builds from the command line as usual using the generator specification, but I wish to hide the incapabilities of the MSVC compiler from the "end-user" in case he/she has the CTP installed.
最终,用户可以像通常一样使用生成器规范从命令行中选择32/64位版本,但是如果他/她安装了CTP,我希望对“最终用户”隐藏MSVC编译器的功能。
How can I write the script and invoke it from the command line so it works for both the Visual Studio and NMake Makefiles generators and for the first invocation of CMake? 我如何编写脚本并从命令行调用它,使其对Visual Studio和NMake Makefiles生成器以及CMake的首次调用均起作用?
Using the reply of @Tanuki and set_target_properties , you can force the usage of the platform toolset in your target 使用@Tanuki和set_target_properties的回复,您可以在目标中强制使用平台工具集
if (CMAKE_VS_PLATFORM_TOOLSET MATCHES "CTP_Nov2013")
set_target_properties(${your_target}
PROPERTIES
PLATFORM_TOOLSET "${CMAKE_VS_PLATFORM_TOOLSET}")
endif()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.