qt - qmake pre-build step before ANY compilation -
there several questions on regarding how create pre-build step qmake, can in .pro file:
versiontarget.target = ../versiondata/versioning.h versiontarget.depends = force win32: versiontarget.commands = cd $$pwd; python.exe ./version_getter.py -p $$target else: versiontarget.commands = cd $$pwd; python ./version_getter.py -p $$target pre_targetdeps += ../versiondata/versioning.h qmake_extra_targets += versiontarget now, problem approach not build step per se build target, if have -j flag configured make runs script in parallel other build jobs. bad, because script creates/updates header file - having change part way through compilation not acceptable.
so, there anyway can have script executed before any compilation ran? know can create script , call version_getter.py , qmake in sequence that, not desirable have compile command line rather within qt creator.
update
the complete .pri file included every 1 of sub-projects below:
config += thread qt += core \ gui versiontarget.target = ../versiondata/versioning.h versiontarget.depends = force win32: versiontarget.commands = cd $$pwd; python.exe ./version_getter.py -p $$target else: versiontarget.commands = cd $$pwd; python ./version_getter.py -p $$target pre_targetdeps += ../versiondata/versioning.h qmake_extra_targets += versiontarget dependpath += ../versiondata includepath += ../versiondata headers += ../versiondata/versioning.h ui_headers_dir = $${_pro_file_pwd_}/include/qui destdir = $(syren_path) !win32-msvc { qmake_cxxflags += -std=c++0x } but still results in same parallel behaviour. thought may have been due use of ccache, turning off made no difference (other being slower of course).
another option start project file snippet in original question, , ensure qmake aware versioning.h dependency other build targets in project file —
- add full path
versioning.hheadersvariable. - add folder in
versioning.hresidesdependpathvariable.
(caveat: if run qmake when versioning.h doesn't exist, emit "warning: failure find: versioning.h" — the workaround warning use system() command, described in other answer.)
example
create test.pro containing following:
versiontarget.target = ../versioning.h versiontarget.depends = force versiontarget.commands = sleep 5s ; touch ../versioning.h pre_targetdeps += ../versioning.h qmake_extra_targets += versiontarget sources = test.c headers = ../versioning.h dependpath = .. create test.c containing following:
#include "../versioning.h" run qmake. output warning: failure find: ../versioning.h.
run make -j9. run versiontarget.commands (which sleeps 5 seconds exaggerate multiprocessing problems), and, after done, run command compile test.c.
(and if examine generated makefile, you'll see test.o depends on both test.c , ../versioning.h, make should correctly figure out can't run command compile test.c before command create/update ../versioning.h.)
Comments
Post a Comment