Retrieve revision number in VS with qmake

c++, mercurial, qmake, qt, visual-studio

Solution

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.

Problem

My current workflow: - `hg update` (or whatever one uses to check out a revision) - `MyProject.pro` → `qmake` → `MyProject.vcproj` - Open Visual Studio, edit files - 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.

Original source

Related problems