使用CMake将编译器标志附加到文件 [英] Appending compiler flags to a file with CMake

查看:92
本文介绍了使用CMake将编译器标志附加到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用cmake在单个翻译单元中添加编译器标志(我想附加它,而不是覆盖其他标志)?

How do I add a compiler flag (I want to APPEND it, not overwrite the others) to a single translation unit with cmake?

我尝试过

set_source_files_properties(MyFile.cpp PROPERTIES CMAKE_CXX_FLAGS "-msse4.1")

,但是它不起作用。.关于该操作的任何建议?

but it isn't working.. any advice on how to do that?

推荐答案

对于CMake 3.0或更高版本,请使用 COMPILE_OPTIONS 属性以将标志添加到单个翻译单元,即:

For CMake 3.0 or later, use the COMPILE_OPTIONS property to add a flag to a single translation unit, i.e.:

set_property(SOURCE MyFile.cpp APPEND PROPERTY COMPILE_FLAGS "-msse4.1")

对于较早版本的CMake,请使用 COMPILE_FLAGS 属性。 COMPILE_FLAGS 是字符串属性。因此,向其附加其他选项的正确方法是使用APPEND_STRING 变体command / set_property.html rel = nofollow noreferrer> set_property 命令:

For earlier versions of CMake, use the COMPILE_FLAGS property. COMPILE_FLAGS is a string property. Therefore the correct way to append additional options to it is to use the APPEND_STRING variant of the set_property command:

set_property(SOURCE MyFile.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -msse4.1 ")

这篇关于使用CMake将编译器标志附加到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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