Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve revision number in VS with qmake

My current workflow:

  1. hg update (or whatever one uses to check out a revision)
  2. MyProject.proqmakeMyProject.vcproj
  3. Open Visual Studio, edit files
  4. Build project

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.

like image 404
Andrew T Avatar asked Dec 29 '22 14:12

Andrew T


2 Answers

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.

like image 190
Lukáš Lalinský Avatar answered Jan 01 '23 04:01

Lukáš Lalinský


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
like image 33
Ton van den Heuvel Avatar answered Jan 01 '23 04:01

Ton van den Heuvel