I am developping a library and I am facing problems trying to run a shell script each time the code is recompiled i.e. each time the binary is changed.
I am running Qt Creator 4.9.2(based on QT 5.12.4) on ubuntu with GCC 64bits
I have tried using the .commands and QMAKE_EXTRA_TARGETS
to run a custom target combined with POST_TARGETDEPS
though it does not work.
I also tried using QMAKE_POST_LINK
though same problem, the result is not the same as expected.
Currently, the script is only executed when I change the .pro file (and it is executed two times instead of one) and at the first compilation, then it remains untouched.
I don't know if this is relevant but my project is made of one library and one test code which I have made dependant using SUBDIRS
.
The architecture is a Global folder containing a .pro file and two sub-folders (library and test code),the library being compiled before the test app when I compile the global project.
I've already tried the solutions brought in these posts :
How to execute shell command after compile finished from .pro in QT?
QMake: execute script after build
https://www.qtcentre.org/threads/46285-How-to-add-the-auto-quot-build-number-quot-in-Qt-Application
The code I currently use is the following one :
mytarget.commands = @echo $$system($$PWD/build_number.sh)
mytarget.depends = FORCE
QMAKE_EXTRA_TARGETS += mytarget
POST_TARGETDEPS += mytarget
I expect the script to be run one time and one time only when the library is changed i.e. only when the code has been modified.
EDIT : The detailed structure of the project is the following one :
/TestProject
|--- testProject.pro
|--- API //this project creates a dynamic library which is exported in testApp project
|--- api.pro //where I am trying to run a script
|--- ... (source files of lib)
|--- testApp //uses the library previously generated by the API
|--- testApp.pro
|--- ... (source files of app)
The dependency between API and testApp is configured as followed in testProject.pro :
TEMPLATE = subdirs
SUBDIRS = \
Api \
testApp
Api.subdir = API
testApp.subdir = testApp
testApp.depends = Api
GITHUB of a blank project using the script :