How to add custom targets in a qmake generated Mak

2019-01-15 13:22发布

问题:

Today when I play with Qt I use qmake to generate the Makefile, and that works quite well.

However sometimes I want to add more stuff to the generated Makefile, without having to edit the generated Makefile.

Let's say that we beside the source code have a Doxygen directory, and there I need to run some doxygen commands to generate the documentation. So it would be nice to have this as a target in the main Makefile. But as default qmake do not understand this type of extra stuff.

So can I add something to tell qmake to include a secondary Makefile in the "doxygen" dir, or maybe add "extra targets" directly in the qmake config?

Thanks Johan


Maybe something like:

  • http://doc.qt.digia.com/4.6/qmake-environment-reference.html#customizing-makefile-output

回答1:

I am working this same issue and so far I have had limited success using the QMAKE_EXTRA_TARGETS variable to build the docs target like so:

docs.depends = $(SOURCES)
docs.commands = (cat Doxyfile; echo "INPUT = $?") | doxygen -
QMAKE_EXTRA_TARGETS += docs

where Doxyfile has the basic doxygen config settings minus the INPUT symbol which I am appending via 'echo' to include only the unsatisfied Makefile dependencies in $(SOURCES).

This approach seems to work in that it only recreates documentation for source files that have changed which is good but I have encountered another problem in that my qmake project file is built with the debug_and_release CONFIG option so that it generates Makefile, Makefile.Debug, and Makefile.Release but SOURCES are only defined in the debug and release Makefiles forcing me to explicitly do a make -f Makefile.Debug docs instead of the more simple and intuitive make docs to build the docs.

Anybody ever tackled the problem from this QMAKE_EXTRA_TARGETS perspective before?



回答2:

This is an old question, but I'll add an answer anyway.

While there seems to be no general support for custom rules in qmake, there is a simple way to do it, assuming GNU make. Just create a file called makefile (all lower case):

include Makefile

re: clean
        $(MAKE) all

where the last two lines are my custom rule.

GNU make will use makefile, not Makefile, if both exist.

BTW, the re rule solves the problem with "make -j8 clean all". This command will start doing all before it has finished doing clean. The re rules guarantees sequentiality.



回答3:

What about the undocumented options mentioned here http://paulf.free.fr/undocumented_qmake.html Under Adding a doxygen target the following can be found:

# custom target 'doc' in *.pro file
dox.target = doc
dox.commands = doxygen Doxyfile; \
    test -d doxydoc/html/images || mkdir doxydoc/html/images; \
    cp documentation/images/* doxydoc/html/images
dox.depends =

...
# somewhere else in the *.pro file
QMAKE_EXTRA_UNIX_TARGETS += dox

Could this be a solution ?



回答4:

This Qt blog post answers the question of QMAKE_EXTRA_COMPILERS and QMAKE_EXTRA_TARGETS quite definitively.

Very soon we will be introduced to QBS.. the new Qt Build Suite coming from Digia and the Qt community.. hopefully it is being really well thought out (and well documented, for that matter).