Subversion keyword substitution is a nice concept, but the revision number refers to the revision the file was last changed, not the current version of the file. If you have for example a project with several files (e.g. main.c
, pol.c
, mol.s
) and in main.c
you have code that should render the current version of the program (like printf("Revision: $Revision$");
). That revision keyword in main.c
will not be expanded if you change and commit pol.c
or mol.c
, so the rendered revision will be wrong in that case.
With the Subversion tool svnversion
it is possible to get more usable version information about your working copy. With this trick involving some Makefile magick it is possible to use it in your source code.
It got even messier when I tried to do this within Kdevelop. It involved a lot of trial and error, but I obtained a solution.
-
Add the following line to the file
Makefile.am
of each directory where you want to use the svn version string:SVNREV = $(shell svnversion -n $(srcdir))
This will create a variable
$SVNREV
with as value the current revision of the src directory at build (make) time. -
This variable has to be available to the compile command as compiler flag
-DSVNREV="$SVNREV"
. Go toMenu "Project" > "Project options" > "Configure options",
and add under the "C" and "C++" tab the following compiler flag (Those extra escape thingies are needed to counter string parsing/expanding during the
configure
stage.)-DSVNREV=\\\"\$(SVNREV)\\\"
Like so:
-
Use the svn version string in your code. e.g.:
#ifdef SVNREV cout << "Version: " << SVNREV << endl; #endif
Fhew.