Listing files in qmake projects

Inspired by a short discussion in the #Qt IRC channel on Freenode earlier this week, I ended up writing a simple generator that generates dummy qmake projects. The idea is to generate test projects with given amounts of headers and sources in order to measure the difference in qmake’s performance when using either of the following syntaxes:

HEADERS += foo.h \
           bar.h
SOURCES += foo.cpp \
           bar.cpp

vs.

HEADERS += foo.h
HEADERS += bar.h
SOURCES += foo.cpp
SOURCES += bar.cpp

Before getting bogged down into details, let me ask which syntax do YOU prefer?

Which syntax do you prefer?

View Results

Loading ... Loading ...

From what I’ve seen, the former syntax is much more popular, also used by the Qt project itself. But the thing is, the latter syntax is — in my humble opinion — much safer and a lot more convenient to maintain. It allows one to reorganize lines within a project file or to move lines from one file to another, without double checking for possible syntax errors that might cause weird build problems.

I could imagine the latter syntax being somewhat slower to parse, but I never really cared about it. However, the recent discussion raised a question in my head — how big is the difference? So I created six test projects to play with:

# syntax number of headers and sources
1. backslashes 100
2. backslashes 1000
3. backslashes 10000
4. assignments 100
5. assignments 1000
6. assignments 10000

I measured the average elapsed time when running qmake for ten times for each of the aforementioned test projects. Here are the results:

100-headers-and-sources 1000-headers-and-sources 10000-headers-and-sources

To me the difference looks quite marginal, considering how often one actually re-runs qmake when building a project…

One Response to “Listing files in qmake projects”

  1. Anonymous

    I would prefer this:

    HEADERS += foo.h
    SOURCES += foo.cpp

    HEADERS += bar.h
    SOURCES += bar.cpp

Leave a Reply