QMake 'subdirs' template - executing a target?
c++, qmake, qt
Solution
I posted a message on the Qt Interest mailing list about a 'pre build' step and it can be done using a combination of PRE_TARGETDEPS and QMAKE_EXTRA_TARGETS. Here is the response:
You can specify custom build steps, eg. this would call makemyversion.sh to create myversion.cpp every time before it builds something:
versiontarget.target = myversion.cpp
versiontarget.commands = ./makemyversion.sh
versiontarget.depends = FORCE
PRE_TARGETDEPS += myversion.cpp
QMAKE_EXTRA_TARGETS += versiontarget
I am now using something similar to this to generate my app's version number each time it is built.
Problem
I am putting together a build system for my Qt app using a qmake .pro file that uses the 'subdirs' template. This works fine, and allows me to specify the order that each target is built, so dependencies work nicely. However, I have now added a tool to the project that generates a version number (containing the build date, SVN revision, etc,) that is used by the main app - I can build this version tool first but when it is built I want to execute it before any more targets are built (it generates a header file containing the version number that the main app includes.) For example, my simple qmake file looks like something this: ``` TEMPLATE = subdirs CONFIG += ordered SUBDIRS = version \ lib \ tests \ mainapp ``` When 'version' is built I want to execute it (passing some arguments on the command-line) before 'lib' is built. Does anyone know if this is possible? I see that qmake has a 'system' command that can execute apps, but I don't know how I could leverage this. A related question concerns my unit tests. These live in the 'test' project and use the QTest framework. I want to execute the tests exe before building 'mainapp' and if the tests fail (i.e. the tests exe doesn't return zero) I want to quit the build process. I realise that qmake is designed to generate makefiles, so I may be wishing for a little too much here but if anyone can give me some pointers it would be very welcome.