TheMeaningfulEngineer
TheMeaningfulEngineer

Reputation: 16359

Include a .pro file in Qt?

I have a project which has lots of includepaths, source and header files. The project is run as a standalone application (it's not a library).

I would like to implement tests (Qt unit test framework) for new features for that application and for that, I require the includes, sources and header files of the (application) project to be available in the (testing) project.

I have tried putting the following in the testing project .pro file:

include(../application/app.pro)     #app.pro is the application project

However first it complains about main.cpp, and if I comment that out there is a parsing error. (commenting main.cpp is bad since I'm changing the main project just so that the testing will compile)

I can get the behavior I want by manually copying all the includepath's, source and header fields from the (application) project but am looking for a cleaner way.

What would be the optimal way to do this? Is it possible to painlessly include one .pro into another?

Upvotes: 0

Views: 1840

Answers (1)

Andrey Rogozhnikov
Andrey Rogozhnikov

Reputation: 170

You should perform two modifications:

  1. Separate out all header files and build-specific settings into a *.pri file. This is what you need instead of including a *.pro.
  2. Move all business logic into a library in order to be able to test it in a separate project.

E.g., you will have build.pri:

# build.pri
TOPDIR = $$PWD
INCLUDEPATH += . \
               $$TOPDIR/include

DEPENDPATH += $$TOPDIR

INCLUDEPATH += $$TOPDIR/additional/libararies

HEADERS += all.h \
           your.h \
           headers.h \
           of.h \
           interest.h

QT      += xml
# etc., etc.

and core.pro

# core.pro
TEMPLATE = lib

CONFIG  += dll thread create_prl
QT      += network xml xmlpatterns sql

include(../build.pri)

HEADERS  += \
            headers.h

SOURCES  += sources.cpp \
            many_of_them.cpp

TARGET     = core
# etc., etc.

(note the include(../build.pri)), and then make your main project app.pro as a subdirs project with core and gui as components of application, and test.pro with obligative core and as many tests as you want.

Upvotes: 3

Related Questions