tags:

views:

909

answers:

2

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
+3  A: 

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)

Nico
In addition to this, you could separate the two parts by a config switch, and send a different config switch on the command line when you build the project using qmake.
Caleb Huitt - cjhuitt
+2  A: 

You can define multiple configuratiions for a .pro file:

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

TARGET = targetA
DEFINES += PARAMA
}

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

  TARGET = targetB
  DEFINES += PARAMB
}

You can use the CONFIG parameter while running qmake.

qmake x.pro CONFIG+=configA
alisami