I use CMake 3.2, ancient MS Visual Studio 2008 for building C++ projects. I've found CMake FindHg module which helps me detect revision and changeset; I set them as preprocessor definitions. But how can I avoid rerunning cmake utility after new commit in order to embed actual version to exe file? I've found solutions only for .NET projects (for example, Embedding mercurial revision information in Visual Studio c# projects automatically). But what about prebuild steps for C++ projects which will work fine in MS Visual Studio 2008 (and newer)? I won't mind against some plugin for this case too.
Asked
Active
Viewed 306 times
0
-
1I'd say using the general idea from the q&a that you link is how you do this. The exact steps may need to be subtly different, but basically "run mercurial tools to find the ID, generate source code from that, and use that source code in your project". It's a while, but I'm sure there still is a "pre-build step" in the build system in Visual Studio, where you can run some batch-file or executable, that generates/updates a file that your build-system then uses. [I used to do this to generate build numbers - read file, update, write back, in the 1990's] – Mats Petersson Mar 27 '15 at 08:24
1 Answers
1
I think the best would be a pre-build step in your Visual studio project. You call a .bat script that get the revision with hg, and dump that in a header file, something like #define HG_REVISION "12345", then you can include this .h in your code and have the revision or changeset you want.

Gerald
- 690
- 4
- 13