Building multiple targets in Qt / Qmake

后端 未结 2 1769
灰色年华
灰色年华 2020-12-13 07:44

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条回答
  • 2020-12-13 08:08

    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
    
    0 讨论(0)
  • 2020-12-13 08:09

    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)

    0 讨论(0)
提交回复
热议问题