Solved Calling a shell file from .pro file
I'm trying to call a shell file from the .pro file using qmake.
According to the documentation (https://doc.qt.io/qt-5/qmake-advanced-usage.html#adding-custom-targets), adding my target to QMAKE_EXTRA_TARGETS should work, however, even if I call "@echo test" command on a fresh project, it doesn't seem to get executed.
What seems to work on windows, is adding my target not only to QMAKE_EXTRA_TARGETS , but also to PRE_TARGETDEPS or POST_TARGETDEPS.
However, if I add my target to PRE_TARGETDEPS or POST_TARGETDEPS on Mac, I get "No rule to make target" error.
What would be the appropriate way of calling a shell file from .pro file, since the one provided in the documentation doesn't seem to work?
I'm using MacOS Big Sur on a Mac Mini M1.
when do you want to call your command?
I successfully used the following (executed on every successful build):
QMAKE_POST_LINK += my_command $$shell_quote(arg1)
Hi @raven-worx, thank you for the suggestion!
I'd like to call the script at the start of the build, or atleast before the app launches.
I've tried out your suggestion, and yes, it seems to work, as long as I pass the command directly (in this case, Script.sh is in the project folder):
QMAKE_POST_LINK += $$_PRO_FILE_PWD_/Script.sh
But if I try to add the command to a define and then call it using your suggestion:
myCommand.commands = $$_PRO_FILE_PWD_/Script.sh QMAKE_POST_LINK += myCommand
and build with this code, I get this error:
make: myCommand: No such file or directory make: *** [TestProject.app/Contents/MacOS/TestProject] Error 1 15:57:30: The process "/usr/bin/make" exited with code 2. Error while building/deploying project TestProject (kit: 5.14.2) When executing step "Make"
Is anything wrong with my code, or am I using the defines incorrectly?
QMAKE_POST_LINKsimple executes the specified command after linking. and thus is executed only if linking happens due to code changes.
You might want to define custom targets: https://doc.qt.io/qt-5/qmake-advanced-usage.html#adding-custom-targets
Then try adding it to
PRE_TARGETDEPSvariable or executing it in QtCreator by adding the make call to the build sequence (in the project settings tab)
The suggestion you've mentioned is the one I was having trouble with, as mentioned before. However it is the correct one.
Turns out, my issue was that on windows, you can use '/' or '\' in your paths (for ex. customTarget.target value), while on Mac, only '/' works :)
Anyway, thank you for the help!