about software and freediving

Shadow Building 'Dynamic' Projects With Qt Creator

Today I started integrating my beat detection library into QLC. Since QLC is entirely written in Qt, I’m using the great Qt Creator IDE. Qt Creator has a cool feature named “Shadow Build” which boils down to qmake being called from inside another directory to keep your source tree clean and seperated from the actual build process.

A typical Makefile created by qmake using “Shadow Build” looks like this
SOURCES       = ../ProjectA/main.cpp \
OBJECTS        =  main.o \
main.o: ../ProjectA/main.cpp ../ProjectA/bar.h
foo.o:  ../ProjectA/foo.cpp  ../ProjectA/foo.h                                                                                

So all sources/headers point to the source directory whereas the object files will be created in the build directory.

Some projects have a build system where apart from {q,c}make routines other scripts (perl, shell, python etc.) are being called. These scripts have very different purposes - one could be to create a header file dynamically at compile time with information on the build system, like git/svn revision, uname -a, date etc.

With no precautions, these headers files will perhaps be created in the build directory and therefore not be found by the compiler.

Unfortunately this is the case with QLC.
There is however an easy (though dirty) fix for this:
Enable Shadow-Build in your Project Settings and set the build directory to something meaningful like /home/yourname/Projects/yourProjectA-build-desktop

Copy the resulting qmake command - this can be something like this:
qmake /home/yourname/Projects/yourProjectA/ -r -spec linux-g++-64

Delete your existing qmake build step and create a Custom Step with the following settings.

Command: rsync
Working Directory: not important
Arguments: -a --exclude .git /home/yourname/Projects/yourProjectA/* /home/yourname/Projects/yourProjectA-build-desktop

This will copy the entire directory except the .git directory (you can replace .git with .svn or any other directory residing in your source directory)
Now create again a Custom Step, this time with the following settings

Command: qmake
Working Directory: %{buildDir}
Arguments: /home/yourname/Projects/yourProjectA-build-desktop/ -r -spec linux-g++-64

Replace the Arguments with the ones you’ve copied in the second step. Also replace yourProjectA/ with yourProjectA-build-desktop/

Make sure have them in the right order (rsync, qmake, make).

Happy shadow building!