[英]Set “treat warnings as errors” for all files except one in qmake
I want to specify the "treat warnings as errors" flag for all files except one. 我想为除一个文件外的所有文件指定“将警告作为错误处理”标志。 For example if I have a.cpp, b.cpp and c.cpp, this would do it for all 3:
例如,如果我有a.cpp,b.cpp和c.cpp,则将对所有3个对象执行此操作:
SOURCES += a.cpp \
b.cpp \
c.cpp
QMAKE_CXXFLAGS += /WX
But how do I do it so that only a.cpp and b.cpp have that flag but c.cpp doesn't? 但是我该怎么做,以便只有a.cpp和b.cpp具有该标志,而c.cpp没有? For example I tried this (but it doesn't work):
例如,我尝试了此操作(但不起作用):
SOURCES += a.cpp \
b.cpp \
c.cpp
QMAKE_CXXFLAGS += /WX
c.cpp: QMAKE_CXXFLAGS -= /WX
Edit: I see there is How to specify separate compilation options for different targets in qmake? 编辑:我看到有如何为qmake中的不同目标指定单独的编译选项? and http://permalink.gmane.org/gmane.comp.lib.qt.general/10945 .
和http://permalink.gmane.org/gmane.comp.lib.qt.general/10945 。 However I need to unspecify a flag for a certain file (the opposite), so I'm not sure if this works for me.
但是,我需要为某个文件(相反)取消指定标志,所以我不确定这是否对我有用。 Also the provided solution is for GCC (and I'm not MSVC).
同样,提供的解决方案适用于GCC(我不是MSVC)。
Edit 2: Would it be possible to unset /WX
with a #pragma
from inside the source file itself? 编辑2:是否可以从源文件本身内部使用
#pragma
取消设置/WX
?
From the top of my head I think of two ways to deal with your situation: 从我的头上,我想到了两种处理您的情况的方法:
Split your list of source files into several (disjoint) lists. 将源文件列表拆分为几个(不相交)列表。 For each sub-list of source files compile a temporary static lib with all compiler flags that you want.
对于源文件的每个子列表,使用所需的所有编译器标志编译一个临时的静态库。 Then link your final application/library to all of the temporary static libraries.
然后将您的最终应用程序/库链接到所有临时静态库。 Rather cumbersome!
相当麻烦!
Use #pragma
statements to instruct your compiler to ignore certain warnings. 使用
#pragma
语句来指示编译器忽略某些警告。 These depend on your compiler. 这些取决于您的编译器。 For the GCC see
对于GCC,请参见
and for the Microsoft compiler this could be a good start: 对于Microsoft编译器,这可能是一个不错的开始:
There doesn't seem to be a good solution. 似乎没有一个好的解决方案。 Here is what I did in the end:
这是我最后所做的:
I put QMAKE_CXXFLAGS += /WX
in the .pro file, and then I put #pragma warning(push, 0)
at the beginning of each .cpp file I wanted to exclude. 我将
QMAKE_CXXFLAGS += /WX
放在.pro文件中,然后将#pragma warning(push, 0)
放在要排除的每个.cpp文件的开头。
This doesn't disable the "treat warnings as errors" flag, it simply disables warnings, but since usually we want to exclude third-party code anyway, it's a good enough solution. 这不会禁用“将警告作为错误处理”标志,而只是禁用警告,但是由于通常我们无论如何都希望排除第三方代码,因此这是一个很好的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.