Methods

Compiler define: Set a preprocessor define passed to the compiler.

Keyword substitution: Provide a header with keywords into which substitutions are made.

Template header: Provide a template with keywords which are processed and output to a generated header.

Tools

[TortoiseSVN][1][?][1]: [SubWCRev][2][?][2]

svn: svnversion

git: git-describe

Implementation

Compiler Define

Subversion

-D`svnversion`

Requires svn command line tools (not installed by default with [TortoiseSVN][1][?][1]).

Git

-D`git describe`

Keyword substitution

  • An anti-pattern
  • Unsuitable for [VCSs][3][?][3] with no global version id (SVN).

Template Header

Subversion

Create a template header file "version.in" of the form:

ifndef VERSION_H

define VERSION_H

define VERSION_VCS_REV "$WCREV$"

define VERSION_BUILD_TIME "$WCNOW$"

define VERSION_VCS_PATH "$WCURL$"

define VERSION_LOCAL_MODS $WCMODS?1:0$

endif /*VERSION_H*/

 

$[Get Code]4

and in the build script run

SubWCRev . version.in version.h

The generated output looks like

ifndef VERSION_H

define VERSION_H

define VERSION_VCS_REV "120"

define VERSION_BUILD_TIME "2013/02/21 17:44:46"

define VERSION_VCS_PATH "http://path/to/repo/trunk"

define VERSION_LOCAL_MODS 1

endif /*VERSION_H*/

 

$[Get Code]5

Git

No equivalent?

Problems

  • No way to pre-process the variables in the build script.
  • Windows platform only.

Generated Header

  • Dependency problems

Links