Building multiple targets in Qt / Qmake

Switch picture Switch · Feb 13, 2010 · Viewed 15.6k times · Source

How could I specify multiple targets with different configurations in Qt? Is there a way to do it in one .pro file?

For example, I would want to build the following 2 .pro files (without having to manually change the .pro file each time):

targetA:

QT += network
TEMPLATE = app
SOURCES += main.cpp \
    mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
RESOURCES += resource.qrc

TARGET = targetA
DEFINES += PARAMA

targetB:

  QT += network
  TEMPLATE = app
  SOURCES += main.cpp \
      mainwindow.cpp
  HEADERS += mainwindow.h
  FORMS += mainwindow.ui
  RESOURCES += resource.qrc

  TARGET = targetB
  DEFINES += PARAMB

Answer

alisami picture alisami · Feb 15, 2010

You can define multiple configuratiions for a .pro file:

QT += network
TEMPLATE = app
SOURCES += main.cpp \
    mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
RESOURCES += resource.qrc

configA {
TARGET = targetA
DEFINES += PARAMA
}

configB {
  TARGET = targetB
  DEFINES += PARAMB
}

You can use the CONFIG parameter while running qmake.

qmake x.pro CONFIG+=configA