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: SubWCRev
svn: svnversion
git: git-describe
Implementation
Compiler Define
Subversion
-D`svnversion`
Requires svn command line tools (not installed by default with TortoiseSVN).
Git
-D`git describe`
Keyword substitution
- An anti-pattern
- Unsuitable for VCSs 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\*/
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\*/
Git
No equivalent?
Problems
- No way to pre-process the variables in the build script.
- Windows platform only.
Generated Header
- Dependency problems