Construire des cibles multiples dans Qt / Qmake
Question
Comment pourrais-je spécifier plusieurs cibles avec des configurations différentes dans Qt? Est-il possible de le faire dans un seul fichier .pro?
Par exemple, je voudrais construire les 2 fichiers .pro suivants (sans avoir à changer manuellement le fichier .pro à chaque fois):
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
La solution
Vous pouvez définir plusieurs configuratiions pour un fichier .pro:
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
}
Vous pouvez utiliser le paramètre CONFIG lors de l'exécution qmake.
qmake x.pro CONFIG+=configA
Autres conseils
Vous pouvez déplacer les pièces les deux fichiers ont en commun pour séparer le fichier .pri. Ensuite, le fichier commun peut être référencé dans les fichiers cibles en utilisant la fonction comprennent: include (common.pri)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow