[英]Add compiler flag for Visual Studio 2005 with CMake 2.8.1
Probably an easy beginners question: I want to add the compiler flag /EHsc
to my project and tried both可能是一个简单的初学者问题:我想将编译器标志/EHsc
添加到我的项目中并同时尝试
SET_TARGET_PROPERTIES(name_of_my_project PROPERTIES COMPILER_FLAGS "/EHsc")
and和
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
in my CMakeLists.txt.在我的 CMakeLists.txt 中。 With both, CMake generates a Visual Studio Solution without complaining.有了这两者,CMake 就可以毫无怨言地生成 Visual Studio 解决方案。
EDIT: initially I asked why both versions did not work.编辑:最初我问为什么两个版本都不起作用。 Well, because I am an idiot and made an error elsewhere so that none of the two lines where ever processed.好吧,因为我是个白痴,在其他地方犯了一个错误,所以这两行都没有处理过。 Still, I'm wondering if both versions are equivalent.不过,我想知道两个版本是否等效。
They are equivalent on a project that has just 1 target.它们等效于只有 1 个目标的项目。
SET_TARGET_PROPERTIES
sets the compiler flag for the named target (which in your case happens to also be the name of the project). SET_TARGET_PROPERTIES
为命名目标设置编译器标志(在您的情况下,它恰好也是项目的名称)。 If you have more than one target, then the other targets will not have the "/EHsc" flag set.如果您有多个目标,则其他目标将不会设置“/EHsc”标志。
Note that you want to use COMPILE_FLAGS
rather than COMPILER_FLAGS
, thus making the correct line:请注意,您要使用COMPILE_FLAGS
而不是COMPILER_FLAGS
,从而使正确的行:
SET_TARGET_PROPERTIES(name_of_my_project PROPERTIES COMPILE_FLAGS "/EHsc")
SET(CMAKE_CXX_FLAGS ...)
will set the C++ flags for all targets in the current directory, as well as in any sub-directories. SET(CMAKE_CXX_FLAGS ...)
将为当前目录以及任何子目录中的所有目标设置 C++ 标志。 So you can use this to set global C++ flags that apply to all of your targets, ie the libraries and executables defined in the project.因此,您可以使用它来设置适用于所有目标的全局 C++ 标志,即项目中定义的库和可执行文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.