My current workflow:
hg update
(or whatever one uses to check out a revision)MyProject.pro
→ qmake
→ MyProject.vcproj
During the build step, how can I update my config.h
header file with information from version control system (e.g. hg id
)?
MyProject.vcproj
is generated by qmake
, so I shouldn't edit it by hand.
You can execute external commands from inside qmake. The easiest way to make the information available in your sources would be to use a define:
HGID = $$system(hg id)
DEFINES += HGID=\\\"$$HGID\\\"
I'm not sure if you can edit an external file from qmake. You could use an external tool, but on Windows you normally don't have things like sed
, so it might be a little more problematic.
You can accomplish that using a custom build target and the PRE_TARGETDEPS
keyword. Assuming config.h.in
has the folowing format:
#define HGID $HGID
You can define a custom build target that will process hgid.h.in
and output to hgid.h
prior to building your main target as follows:
hgid.target = hgid
hgid.commands = sed s/\\\$$HGID/`hg id`/ hgid.h.in > hgid.h
QMAKE_EXTRA_TARGETS += hgid
PRE_TARGETDEPS += hgid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With