From QtCreator "projects - Add Building Step", one can specify added building steps. For example, the following setting will echo out a message when the project is built.
The added building step actually appears in the corresponding .pro.user file:
<value type="QString" key="ProjectExplorer.ProcessStep.Arguments">hello. This is my custom process step.</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Command">/usr/bin/echo</value>
My question is: is there a way adding the building step in the .pro file instead of using the GUI ("projects - Add Building Step") and actually adding settings to .pro.user file? (To me, the advantage is that .pro files can be easily batch-processed with shell scripts.)
I tried to put the step in the .pro file with QMAKE_EXTRA_TARGETS as
mystep.commands = echo 'hello. This is my custom process step'
QMAKE_EXTRA_TARGETS = mystep
However, with qmake; make
from command line, only the original building happens. Only after a further make mystep
, the echo happens. In another words, mystep
step does not happen with a normal make
- maybe I am misunderstanding QMAKE_EXTRA_TARGETS
?
CodePudding user response:
I'm glad you found an answer that works for you. I want to clarify the comment I made above, since I tried it and it worked fine for me. (And was much simpler looking than your solution.) I think the reason it didn't work for you was because I intended you to combine PRE_TARGETDEPS with the QMAKE_EXTRA_TARGETS you already had. This should be all you need.
mystep.commands = echo 'hello. This is my custom process step'
QMAKE_EXTRA_TARGETS = mystep
PRE_TARGETDEPS = mystep
CodePudding user response:
After digging around for a while, I found a solution - use QMAKE_EXTRA_COMPILERS.
# must use a variable as input
PHONY_DEPS = .
mystep.input = PHONY_DEPS
# use non-existing file here to execute every time
mystep.output = phony.txt
# the system call to the batch file
mystep.commands = echo 'hello. This is my custom process step'
# some name that displays during execution
mystep.name = running mystep...
# "no_link" tells qmake we don’t need to add the output to the object files for linking
# "no_clean" means there is no clean step for them.
# "target_predeps" tells qmake that the output of this needs to exist before we can do the rest of our compilation.
mystep.CONFIG = no_link no_clean target_predeps
# Add the compiler to the list of 'extra compilers'.
QMAKE_EXTRA_COMPILERS = mystep
For my real application, which is more than just an echo, I will be specifying output/CONFIG differently.
Reference: