c++ - 如何使用 qmake 为单个源文件指定编译器标志?

标签 c++ qt qt5 qmake qtcore

而其他源文件使用默认标志?我的一些源文件需要一些额外的 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/

相关文章:

c++ - Qt 异步 Action 序列

c++ - qDebug - 如何以位输出数据(二进制格式)

c++ - 在 header 中定义并包含在两个源代码中的结构仅在一个源代码中定义

c++ - 一个xml阅读器的设计

c++ - all_of 函数检查数组部分所有元素的条件

c++ - 如果我在 C++ 中将(指向类 A 的指针)转换为(指向其子类 B 的指针)会发生什么

python - 在 Retina 显示器上优化 Python QT 应用程序

c++ - 多个 qml 窗口在 linux 上不能正确刷新

c++ - Qt 从 QTextStream 读取

c++ - QObject::moveToThread:小部件不能移动到新线程