Adding custom target in qmake

2020-07-25 10:04发布

I want to build my resources with qmake as follows [Qt 5.5]:

imageTarget.target = images.rcc
imageTarget.depends = $$PWD/images.qrc
imageTarget.commands = rcc -binary -no-compress $$PWD/images.qrc -o $$OUT_PWD/images.rcc
QMAKE_EXTRA_TARGETS += imageTarget

When I run qmake for my .pro file, it generates the make rule for target images.rcc target as expected:

images.rcc: /path/to/images.qrc
rcc -binary -no-compress /path/to/images.qrc -o /output/path/to/images.rcc

So far so good.

However, what I would expect is that running qmake would also generate the output file images.rcc and it does not.

But when I go into the makefile directory and type in the command "make images.rcc", then the images.rcc is generated. Am I missing a point? How can I make target in the qmake step without the need of extra make?

1条回答
欢心
2楼-- · 2020-07-25 10:39

With

QMAKE_EXTRA_TARGETS += imageTarget

you just define a new target - but it is not automatically built when running make.

Try to add

PRE_TARGETDEPS += images.rcc

This should automatically build a new images.rcc when running make if images.qrc has changed.

查看更多
登录 后发表回答