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

Marcel Loose loose at astron.nl
Wed Jul 2 03:30:39 EDT 2014


Hi,

The command

    SET(ENV{LC_ALL} C)

somewhere inside your cmake macro will do the trick. If you really care
about the original contents of LC_ALL you should save it first and
restore once your done.

BTW: you might consider using the Subversion_WC_INFO() macro in the
FindSubversion module.

Cheers,
Marcel Loose.


On 02/07/14 09:04, Eric Noulard wrote:
> May be you can avoid localized output by setting LANG env var to "C".
>
>
> Or you can ask svn for xml output which may not be localized e.g.
>
> # 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} --xml info ${dir}
>         OUTPUT_VARIABLE ${variable}
>         OUTPUT_STRIP_TRAILING_WHITESPACE)
>       STRING(REGEX REPLACE ".*entry.*revision=\"([0-9]+)\"\n.*kind.*"
>         "\\1" ${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}")
>
>
>
>
> 2014-07-02 1:04 GMT+02:00 Rick McGuire <object.rexx at gmail.com
> <mailto:object.rexx at gmail.com>>:
>
>     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?
>
>     Rick
>
>
>     --
>
>     Powered by www.kitware.com <http://www.kitware.com>
>
>     Please keep messages on-topic and check the CMake FAQ at:
>     http://www.cmake.org/Wiki/CMake_FAQ
>
>     Kitware offers various services to support the CMake community.
>     For more information on each offering, please visit:
>
>     CMake Support: http://cmake.org/cmake/help/support.html
>     CMake Consulting: http://cmake.org/cmake/help/consulting.html
>     CMake Training Courses: http://cmake.org/cmake/help/training.html
>
>     Visit other Kitware open-source projects at
>     http://www.kitware.com/opensource/opensource.html
>
>     Follow this link to subscribe/unsubscribe:
>     http://public.kitware.com/mailman/listinfo/cmake
>
>
>
>
> -- 
> Erk
> L'élection n'est pas la démocratie -- http://www.le-message.org
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140702/ce1b9daf/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: loose.vcf
Type: text/x-vcard
Size: 292 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140702/ce1b9daf/attachment.vcf>


More information about the CMake mailing list