6

有没有办法为 qmake 中的不同目标指定单独的编译选项?

例如:

QMAKE_CXXFLAGS += -O 
SOURCES += file1.cpp    

QMAKE_CXXFLAGS += -std=gnu++0x -O 
SOURCES += file2.cpp

所以 file1.cpp 将仅使用 -O 选项编译,文件 file2.cpp 使用 -std=gnu++0x -O 选项编译。

4

1 回答 1

8

您可以创建和使用单独的“额外编译器”,如下所示:

# Use the built-in compiler for file1.cpp
QMAKE_CXXFLAGS += -O 
SOURCES += file1.cpp    

# Create a new compiler for file2.cpp
gnupp0x.input = SOURCES_GNUPP0X
gnupp0x.output = ${QMAKE_FILE_BASE}.o
gnupp0x.commands = g++ -std=gnu++0x $$QMAKE_CXXFLAGS ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}
QMAKE_EXTRA_COMPILERS += gnupp0x

# Use the new compiler for file2.cpp
SOURCES_GNUPP0X += file2.cpp
于 2013-01-30T16:01:27.067 回答