而其他源文件使用默认标志?我的一些源文件需要一些额外的 C++ 预处理器定义。我使用 Qt 5。我只发现 QMAKE_CXXFLAGS 在 qmake 项目中是全局使用的。
最佳答案
这就是 Qt 源代码本身在理论上为 GUI 绘制所做的事情:
SOURCES_NOOPTIMIZE = somefile.cpp
nooptimize.name = nooptimize
nooptimize.input = SOURCES_NOOPTIMIZE
nooptimize.dependency_type = TYPE_C
nooptimize.variable_out = OBJECTS
nooptimize.output = ${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_IN_BASE}$${first(QMAKE_EXT_OBJ)}
nooptimize.commands = $${QMAKE_CXX} $(CXXFLAGS) -O0 $(INCPATH) -c ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT} # Note the -O0
QMAKE_EXTRA_COMPILERS += nooptimize
另见高级使用in the documentation如何添加编译器:
Custom compiler specifications support the following members:
Member Description
commands The commands used for for generating the output from the input.
CONFIG Specific configuration options for the custom compiler. See the CONFIG table for details.
depend_command Specifies a command used to generate the list of dependencies for the output.
dependency_type Specifies the type of file the output is. If it is a known type (such as TYPE_C, TYPE_UI, TYPE_QRC), it is handled as one of those type of files.
depends Specifies the dependencies of the output file.
input The variable that specifies the files that should be processed with the custom compiler.
name A description of what the custom compiler is doing. This is only used in some backends.
output The filename that is created from the custom compiler.
output_function Specifies a custom qmake function that is used to specify the filename to be created.
variables Indicates that the variables specified here are replaced with $(QMAKE_COMP_VARNAME) when referred to in the pro file as $(VARNAME).
variable_out The variable that the files created from the output should be added to.
关于c++ - 如何使用 qmake 为单个源文件指定编译器标志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27683777/