20

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

Johan
  • 20,067
  • 28
  • 92
  • 110

2 Answers2

38

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
leyyin
  • 27
  • 1
  • 4
mtvec
  • 17,846
  • 5
  • 52
  • 83
3

In my case I tried everything I found everywhere and none worked. The only way for me was to hardcode flags inside qt5 installation directory! So just for record, I added these two lines:

QMAKE_CFLAGS_RELEASE = "-march=native -O3 -msse -msse2 -msse3 -mssse3 -fomit-frame-pointer -pipe"
QMAKE_CXXFLAGS_RELEASE = "-march=native -O3 -msse -msse2 -msse3 -mssse3 -fomit-frame-pointer -pipe"

To file:

/opt/qt5/mkspecs/linux-g++/qmake.conf

Please note that I had qt5 compiled and installed on my system in /opt/qt5 path. So you may search a folder named mkspecs in your system then a subfolder named linux-g++ and then a file named qmake.conf to add those two magic lines to it. It's up to you and the envirtonment you are in.

Aario
  • 31
  • 1