There are several questions on SO regarding how to create a pre-build step for qmake
, I can do that with this in my .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, the problem is that this approach is not a build step per se but just another build target, so if I have the -j
flag configured for make
it runs my script in parallel with the other build jobs. This is very bad, because my script creates/updates a header file - having it change part way through the compilation is not acceptable.
So, is there anyway I can have this script executed before any compilation is ran? I know I can create another script and call the version_getter.py
and qmake
in sequence from that, but this is not desirable as I would have to compile from the command line rather than from within Qt Creator.
Update
The complete .pri
file that is included by every one of my sub-projects is 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 this still results in the same parallel behaviour. I thought it may have been due to my use of ccache
, but turning it off made no difference (other than being much slower of course).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…