qmake pre-build step before ANY compilation

有些话、适合烂在心里 提交于 2019-11-27 07:50:29
smokris

Another option would be to start with the project file snippet in your original question, and also ensure that qmake is aware that versioning.h is a dependency for the other build targets in your project file —

  • Add the full path to versioning.h to your HEADERS variable.
  • Add the folder in which versioning.h resides to your DEPENDPATH variable.

(Caveat: if you run qmake when versioning.h doesn't exist, it will emit "WARNING: Failure to find: versioning.h" — the only workaround for that warning is to use the system() command, as I described in my other answer.)

Example

Create test.pro containing the 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 the following:

#include "../versioning.h"

Run qmake. It will output WARNING: Failure to find: ../versioning.h.

Run make -j9. It will run versionTarget.commands (which sleeps for 5 seconds to exaggerate any multiprocessing problems), and, after that is done, run the command to compile test.c.

(And if you examine the generated Makefile, you'll see that test.o depends on both test.c and ../versioning.h, so Make should correctly figure out that it can't run the command to compile test.c before the command to create/update ../versioning.h.)

Use the system() qmake command — it runs when you run qmake, which happens before make runs any build commands.

win32: PYTHON=python.exe
else:  PYTHON=python
system(cd $$PWD; $$PYTHON ./version_getter.py -p ../VersionData/versioning.h)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!