[CMake] Addition to FindGit

Thomas Petazzoni thomas.petazzoni at free-electrons.com
Tue Jul 12 02:52:35 EDT 2011


Hello,

Le Sun, 05 Jun 2011 11:02:00 +0200,
Quintus <sutniuq at gmx.net> a écrit :

> I'm working on a git-versioned project that I'd like to display it's
> version number for development versions like this:
> 
> 1.2.3-dev (commit abc1234 on devel, 12/4/10)

For  similar need I did something like :

execute_process(COMMAND sh ../getlocalversion OUTPUT_VARIABLE MYPROG_VERSION)
add_definitions(-DMYPROG_VERSION="${MYPROG_VERSION}")

where getlocalversion is a shell script that does :

printf "%s%s" $(git rev-parse --verify --short HEAD) $(if test `git
diff-index --name-only HEAD | wc -l` -ne 0 ; then echo "-dirty"; fi)

However, I am not very happy with this, because the version is
determined at configuration time, and not at compile time. Therefore,
if I make some changes and commit them to the Git repository without
re-doing the CMake configuration step, the program version isn't
changed. Any idea on how to make sure that the version of the program
is updated at every compilation ?

Thanks,

Thomas
-- 
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com


More information about the CMake mailing list