Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building multiple targets in Qt / Qmake

Tags:

qt

qmake

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
like image 876
Switch Avatar asked Feb 13 '10 21:02

Switch


2 Answers

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
like image 112
2 revs Avatar answered Sep 23 '22 08:09

2 revs


You can move the parts both files have in common to separate .pri file. Afterwards the common file can be referenced in the target files using the include-function: include(common.pri)

like image 41
Nico Avatar answered Sep 22 '22 08:09

Nico