How to specify compiler flag to a single source fi

2019-04-08 22:06发布

While other source files use the default flags? Some of my source files need some extra C++ preprocessor defines. I use Qt 5. I only found QMAKE_CXXFLAGS is for global use in qmake projects.

1条回答
Animai°情兽
2楼-- · 2019-04-08 22:44

This is what used to be done in theory for GUI painting in the Qt source itself:

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

See also the advanced use in the documentation how to add a compiler:

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.

查看更多
登录 后发表回答