I want to build two versions of my program, a "normal" version, and one in which the address sanitizer has been activated. As of now, I have this in my QSoas.pro
sanitizer {
message("Activating the address sanitizer code")
OBJECTS_DIR = build-snt
QMAKE_CXXFLAGS += -fno-omit-frame-pointer -fsanitize=address
LIBS += -fsanitize=address
TARGET = $$join(TARGET,,,-snt)
}
This way, I can do:
~ qmake
~ make
to get the normal version, and
~ qmake CONFIG+=sanitizer
~ make
to get the version with the address sanitizer.
This is fine, but a little cumbersome, especially since I need in fact many other configuration options on the qmake
command-line. Is there a way to have two targets, so that I could simply run
~ qmake
~ make
~ make my-sanitized-exe
The most natural way, IMO, is an out-of-source build. That is, create a subdirectory called "sanitizer", go into it, and build your Makefile(s) the same way you do it with cmake
, meson
etc.:
mkdir sanitizer
cd sanitizer
qmake CONFIG+=sanitizer ../Qsoas.pro
QMake natively supports out-of-source builds, so everything should be fine. However, if you need to distiguish between the source and build directories, you can use the variables $$PWD
and $$OUT_PWD
.
See also qmake's manual for shadowed() function to translate the paths automatically.