I also struggled with getting a SVN revision into my source code. 
By the looks of this my solution can be improved :-)

> CMakeLists.txt:
> =============
> CONFIGURE_FILE(dump_svnversion.sh.in dump_svnversion.sh)
> ADD_CUSTOM_TARGET(OutputSvnVersion ALL
>         ${CMAKE_CURRENT_BINARY_DIR}/dump_svnversion.sh)
>
> # allow including the current_svnversion.h file which in this example is 
> generated in the binary directory
> INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
> SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/current_svnversion.h
>    PROPERTIES GENERATED true)
> ADD_EXECUTABLE(foo
>    foo.cc
>    ${CMAKE_CURRENT_BINARY_DIR}/current_svnversion.h)
>
> dump_svnversion.sh.in:
> =================
> #!/bin/sh
> [EMAIL PROTECTED]@/svnversion_tmp
>
> echo "#ifndef @[EMAIL PROTECTED]" >  $FILE
> echo "#define @[EMAIL PROTECTED]" >> $FILE
> echo "#define @[EMAIL PROTECTED] \"`svnversion @[EMAIL PROTECTED]"" >> $FILE
> echo "#endif" >> $FILE
>
> @CMAKE_COMMAND@ -E copy_if_different 
> @CMAKE_CURRENT_BINARY_DIR@/svnversion_tmp 
> @CMAKE_CURRENT_BINARY_DIR@/current_svnversion.h

This is verry unix like solution. I used a Python script with the PySvn 
plug-in. For me it works on both XP and Linux.

First I tried a CMake macro as in:
ADD_CUSTOM_TARGET(OutputSvnVersion ALL
         ${MY_SVN_MACRO})

Which obviously doesn't work. It should be a nice feature to have, in my 
opinion. That way there is no/less need for using external scripts.

Anyway: Could CMake provide some standard macro's to generate such files on 
build time? It seems to me that a lot of people would benefit from it. I mean 
this isn't the first post on the subject, is it?

Kind regards,
Sander.
_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to