CMake(忍者后端)使用/ MT进行编译 [英] CMake (Ninja back-end) compile with /MT
问题描述
我与此 CMake使用/ MT而不是/ MD ,但有一些区别:
I have a similar problem to this CMake compile with /MT instead of /MD but with some differences:
我正在使用Visual Studio 2017使用CMake和Ninja生成器来构建库。 Visual Studio给了我一些选择(配置),例如x86-Debug等。还有一个CMakeSettings.json文件,看来我可以通过它操纵Visual Studio的默认配置。但是我不知道该怎么做!
I'm using Visual Studio 2017 to build a library using CMake and Ninja generator. Visual Studio gives me some choices (configurations) like x86-Debug, etc. There is also a CMakeSettings.json file that seems I can manipulate Visual Studio's default configurations through it. But I don't know how!
我想用/ MT编译我的库,但是我不想像这样在CMakeLists.txt文件中对其进行硬编码。以上职位。这意味着我想根据用户的选择通过配置来编译我的库。
I want to compile my library with /MT but I don't want to hard code it inside the CMakeLists.txt file like in the above post. That mean I want to compile my library based on the user choice through the configurations.
CMakeSettings.json文件中是否有任何变量可以帮助我定义/ MT编译器开关?库的静态/动态构建又如何呢?
Is there any variable in CMakeSettings.json file that helps me to define /MT compiler switch? What about static/dynamic building of the library? Are there any help available about this file?
推荐答案
几周前我遇到了同样的问题,我使用CMakeSettings解决了该问题。 json文件。我解释了定义MT的解决方案和静态/动态方法是相同的。
I had the same problem a few weeks ago and I solved it using CMakeSettings.json file. I explain the solution for defining MT and the method for static/dynamic is the same.
在CMakeSettings.json中使用cmakeCommandArgs变量发送想要的任何内容作为cmake参数。可能是这样的:
Use cmakeCommandArgs variable inside CMakeSettings.json to send whatever you want as cmake arguments. It can be something like:
"cmakeCommandArgs": "-DLINK_TYPE=Static"
然后在CMakeLists.txt文件中,您只需根据定义的参数进行决定即可。
Then in CMakeLists.txt you must simply decide based on the argument you've defined.It can be in the following form:
if ("${LINK_TYPE}" STREQUAL "Static")
add_compile_options(/MT$<$<CONFIG:Debug>:d>)
endif()
这篇关于CMake(忍者后端)使用/ MT进行编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!