6

Is there any way to specify separate compilation options for different targets in qmake ?

For example:

QMAKE_CXXFLAGS += -O 
SOURCES += file1.cpp    

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

So file1.cpp will be compiled only with -O option and file file2.cpp with -std=gnu++0x -O options.

smokris
  • 11,740
  • 2
  • 39
  • 59
andigor
  • 722
  • 6
  • 17

1 Answers1

8

You could create and use a separate "extra compiler", as follows:

# 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
smokris
  • 11,740
  • 2
  • 39
  • 59
  • I tried this and got lots of linker errors. Adding `-c` to the `gnupp0x.commands` line solved the problem. – following May 10 '15 at 14:16