[Qt-interest] Handling files created by custom build targets

Constantin Makshin cmakshin at gmail.com
Thu Oct 28 21:08:16 CEST 2010


Hi!

QMake supports custom build targets (QMAKE_EXTRA_TARGETS) that can be used to generate various files. For example, to create an application shortcut file one can write something like this:

QMAKE_EXTRA_TARGETS += targetShortcut
targetShortcut.target = $$OUT_PWD/$${TARGET}.desktop
targetShortcut.depends = $$PWD/$${TARGET}.desktop.in
targetShortcut.commands = $$quote(sed -e \'s%@BINDIR@%$$BINDIR%g\' $$targetShortcut.depends >$$targetShortcut.target)

Then, to install this .desktop file, one can use something like this:

INSTALLS += shortcut
shortcut.path = $$SHORTCUTSDIR
shortcut.files = $$targetShortcut.target
shortcut.depends = $$shortcut.files

The problem is that if the .desktop file doesn't exist when Makefile is being generated, QMake doesn't add it as an installation component, i.e. doesn't create corresponding installation rule. To solve this problem the developer has to either:
1) run QMake to generate Makefile, create the .desktop file using the appropriate build target and then run QMake again to fix the installation rule;
2) create the .desktop file during initial Makefile generation by adding something like this to the .pro file:

!isEmpty(QMAKE_QMAKE):!exists($$targetShortcut.target) {
    system($$targetShortcut.commands)
}

("!isEmpty(QMAKE_QMAKE)" is needed to prevent lupdate/lrelease from complaining about unsupported "system()" function)

Both solutions are ugly, but I couldn't find other ways to solve the described problem. Is there anything I missed?

And how can I add the .desktop file to the "distclean" target?

Thank you.



More information about the Qt-interest-old mailing list