tags:

views:

877

answers:

2

I'm writing a small qt app suite that consists of a set of small programs that work on the same set of files. They are organized like this:

/
  app1/
    main.cpp
  app2/
    main.cpp
  app3/
    main.cpp
  common/
    project.h
    project.cpp
    somemore.h
    somemore.cpp
  appsuite.pro

When I do qmake && make, I want the following binaries to be built:

  • app1/app1
  • app2/app2
  • app3/app3

How do I write appsuite.pro to work like this?
I have heard something about .pri files, but I could not figure out how to use them in my "situation".

Help appreciated,
jrh

+5  A: 

One way of doing it is to have a .pro file per subdirectory.

appsuite.pro:

TEMPLATE = subdirs
SUBDIRS = common app1 app2 app3
app1.depends = common
app2.depends = common
app3.depends = common

app1/app1.pro:

TARGET = app1
SOURCES = main.cpp
INCLUDEPATH += ../common
LIBS += -L../common -lcommon

The common.pro file should build a static library you can then link into the binaries. common/common.pro:

TEMPLATE = lib
CONFIG = staticlib
SOURCES = project.cpp more.cpp
HEADERS = project.h more.h
PiedPiper
A .pri file merely contains other qmake commands. Certainly they often list the files for inclusion in a project, but it isn't necessarily so. For example, at work we have one that defines a target so that we can do a "make depends" and have the makefiles regenerated.
Caleb Huitt - cjhuitt
+1 for pointing out that `common` should be a `lib`. Thanks!
Here Be Wolves
@cjhuitt .pri files weren't really relevant in this case so I've removed the reference.
PiedPiper
+1  A: 

One way is to create your global project appsuite.pro, like this:

TEMPLATE = subdirs
SUBDIRS = app1 app2 app3

The subprojects app1.pro and app2.pro should also be created for those applications alone, with a dependency regarding the common/ subdirectory

You can also specify other dependencies in appsuite.pro, for example if app1 depends on app2, as:

app1.depends = app2
RedGlyph
Looks like it was an almost simultaneous post...
RedGlyph