Vincent Fourmond
Vincent Fourmond

Reputation: 3288

Build multiple versions of a binary with qmake

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

Upvotes: 1

Views: 265

Answers (2)

Matt
Matt

Reputation: 15206

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.

Upvotes: 1

vahancho
vahancho

Reputation: 21258

This is my proposal on how you can achieve the desired behavior. The idea is using two (or more) different Makefiles that will tell the make tool what to do. To create a set of Makefiles I would do this (roughly):

~ qmake -o ./normal/Makefile

to create a normal version, and:

~ qmake CONFIG+=sanitizer -o ./sanitizer/Makefile

to create a Makefile for sanitizer. Now, if I want to build a normal version I call:

~ make -f ./normal/Makefile

and

~ make -f ./sanitizer/Makefile

to build an alternative version. Hopefully this will work.

Upvotes: 1

Related Questions