[CMake] Getting the svn revision number of our source.

Rolf Eike Beer eike at sf-mail.de
Wed Jul 2 03:31:07 EDT 2014


Am 02.07.2014 01:04, schrieb Rick McGuire:
> We like to include the SVN revision number in our build artifacts to 
> help
> keep track of what version people are working with.  I found the 
> following
> code on the mailing lists which appears to work fine:
> 
> # Get the SVN revision number of an svn command line client is
> # available.  This version will run at build time rather than only
> # at configuration generation time.
> FIND_PROGRAM(SVN_EXECUTABLE svn
>   DOC "subversion command line client")
> 
> # only do this if we have an svn client.
> if (SVN_EXECUTABLE)
>     MACRO(Subversion_GET_REVISION dir variable)
>       EXECUTE_PROCESS(COMMAND ${SVN_EXECUTABLE} info ${dir}
>         OUTPUT_VARIABLE ${variable}
>         OUTPUT_STRIP_TRAILING_WHITESPACE)
>       STRING(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
>         "\\2" ${variable} "${${variable}}")
>     ENDMACRO(Subversion_GET_REVISION)
> 
>     Subversion_GET_REVISION(${CMAKE_SOURCE_DIR} ORX_BLD_LVL)
> endif ()
> 
> message(STATUS "SVN Revision Number is ${ORX_BLD_LVL}")
> 
> 
> Unfortunately, the first person not in the core team who building was
> running a Spanish language version of SVN, so the ORX_BLD_LEVEL
> variable ended up with the entire output of the svn info command
> because it could not find the string REVISION.  This was not a good
> thing!
> 
> 
> Is there a better way to obtain the SVN revision number that does not
> suffer from this sort of problem?

cmake --help-module FindSubversion

This gives you an example of exactly this at the end (it also fetches 
the last commit message). And the macros in FindSubversion will already 
care for the language issue.

Eike


More information about the CMake mailing list