How to change qmake release flags for gcc? (Change -O2 to -Os)

Johan picture Johan · Apr 19, 2011 · Viewed 14.2k times · Source

With qmake you can quite easy change so you build a debug version, or a release version. Just modify the CONFIG var and the compile flags change.

CONFIG += debug
CONFIG += release

When you use the debug you get -g and no optimization, and when you use release you get -O2 and no debug info (no -g).

But where is that specified?

Let's say that I would like my application to be build with optimization for size, -Os? How do I change what is behind "release"?

Thanks

Answer

Job picture Job · Apr 19, 2011

You can change global compiler flags by modifying QMAKE_CXXFLAGS. Compiler flags for debug and release builds can be set in QMAKE_CXXFLAGS_DEBUG and QMAKE_CXXFLAGS_RELEASE respectively.

For your concrete example, you should do something like this:

QMAKE_CXXFLAGS_RELEASE -= -O2
QMAKE_CXXFLAGS_RELEASE += -Os