Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
868 views
in Technique[技术] by (71.8m points)

qt - How do I use qmake to build multiple binaries in a single project?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...