The SUBDIRS ability of qmake can be used to compile a set of libraries, each of which depend on another. The example below is slightly convoluted to show variations with the SUBDIRS ability.
Directory Structure
Some of the following files will be omitted in the interest of brevity. They can be assumed to be the format as non-subdir examples.
project_dir/
-project.pro
-common.pri
-build.pro
-main.cpp
-logic/
----logic.pro
----some logic files
-gui/
----gui.pro
----gui files
project.pro
This is the main file that enables the example. This is also the file that would be called with qmake on the command line (see below).
TEMPLATE = subdirs # This changes to the subdirs function. You can't combine
# compiling code and the subdirs function in the same .pro
# file.
# By default, you assign a directory to the SUBDIRS variable, and qmake looks
# inside that directory for a <dirname>.pro file.
SUBDIRS = logic
# You can append as many items as desired. You can also specify the .pro file
# directly if need be.
SUBDIRS += gui/gui.pro
# You can also create a target that isn't a subdirectory, or that refers to a
# different file(*).
SUBDIRS += build
build.file = build.pro # This specifies the .pro file to use
# You can also use this to specify dependencies. In this case, we don't want
# the build target to run until after the logic and gui targets are complete.
build.depends = logic gui/gui.pro
(*) See The reference documentation for the other options for a subdirs target.
common.pri
#Includes common configuration for all subdirectory .pro files.
INCLUDEPATH += . ..
WARNINGS += -Wall
TEMPLATE = lib
# The following keeps the generated files at least somewhat separate
# from the source files.
UI_DIR = uics
MOC_DIR = mocs
OBJECTS_DIR = objs
logic/logic.pro
# Check if the config file exists
! include( ../common.pri ) {
error( "Couldn't find the common.pri file!" )
}
HEADERS += logic.h
SOURCES += logic.cpp
# By default, TARGET is the same as the directory, so it will make
# liblogic.so (in linux). Uncomment to override.
# TARGET = target
gui/gui.pro
! include( ../common.pri ) {
error( "Couldn't find the common.pri file!" )
}
FORMS += gui.ui
HEADERS += gui.h
SOURCES += gui.cpp
# By default, TARGET is the same as the directory, so it will make
# libgui.so (in linux). Uncomment to override.
# TARGET = target
build.pro
TEMPLATE = app
SOURCES += main.cpp
LIBS += -Llogic -Lgui -llogic -lgui
# This renames the resulting executable
TARGET = project
Command Line
# Assumes you are in the project_dir directory
> qmake project.pro # specific the .pro file since there are multiple here.
> make -n2 # This makes logic and gui concurrently, then the build Makefile.
> ./project # Run the resulting executable.