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
qmake is a utility that automates the generation of makefiles. Makefiles are used by the program make to build executable programs from source code; therefore qmake is a make-makefile tool, or makemake for short.
The qmake executable is installed in /usr/lib/<your_arch>/qt5/bin as qmake (no -qt5 suffix).
QMake is a build system that generates Makefiles for GNU Make or project build files for Microsoft Visual Studio. It is part of the Qt software framework by Trolltech. While it is commonly used to construct Qt-based software, any project can benefit from it.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With