How to set build order in Qt subdir project

themean picture themean · Jun 18, 2012 · Viewed 8k times · Source

I have a project with 5-6 libraries and one executable. The executable depends on the libraries, and some libraries depend on other libraries. How can I specify a build order so the dependencies are built before they are needed?

Answer

user23573 picture user23573 · Apr 28, 2015

Although this question has been answered and accepted a long time ago, I feel the need to add another answer; I honestly think that there is a better answer.

I consider CONFIG += ordered harmful and a bad habit. It is probably something that was a bit prematurely introduced by the qmake developers. And there are strong opponents to its use. The drawbacks are these:

  1. it does not define the dependencies, it just names a build order
  2. it hammers multicore build times
  1. it prevents Qt developers from implementing meaningful features

Therefore, I suggest to change your project file as follows:

TEMPLATE = subdirs

SUBDIRS += Utility GraphicModule PackingLib Core GameProto

GameProto.depends = Core
Core.depends = PackingLib
PackingLib.depends = GraphicModule
GraphicModule.depends = Utility

This way the dependencies are clearly defined. You can also think of other, more complicated dependency hierarchies which are possible this way and absolutely impossible with the build order.


Update: (June 21st, 2017)

Unfortunately, qmake is not the best tool when it comes to larger projects with deep sub-project hierarchies. Problems seen with larger projects are these:

  • it is not possible to define dependencies to sub-projects higher up in the hierarchy
  • Run qmake takes an extremely long time to execute
  • long compile time because the dependencies are not handled properly and too many unnecessary compile steps executed
  • sometimes qmake is not able to correctly calculate sub-project dependencies which makes it necessary to compile sub-projects separately

There mainly two ways to address these issues:

  • Rewrite your project to a flat hierarchy. All executables, static and dynamic libraries should be in the topmost level. Use two or more levels only for sub-projects where you absolutely cannot avoid it. (e.g. a dynamic library that comprises of static libraries) This will result in shorter qmake run times and shorter compilation times. However, even this approach may fail at times.
  • Change to a different make tool, like cmake. Seriously. Cmake is a mature product and the support from within Qt Creator is comparable to qmake.

Comment:

Because of the well known problems with qmake, the Qt Company has already decided to introduce a new make tool QBS. However, the use of this tool is not as simple as it may look on first impression. There is no easy transition from qmake to QBS, especially for more complex projects. The Javascript-like syntax of the QBS language is not easy to grasp and documentation is scarce.

There are IMHO only two other tools available that are of the caliber to replace qmake:

  • CMake, the well known build tool.
  • meson, an open source build system meant to be both extremely fast, and, even more importantly, as user friendly as possible.