[CMake] Put svn revision into file on every "make install"

Jean-Pierre Bergamin james at ractive.ch
Mon Jun 15 10:05:19 EDT 2009


Eric Noulard schrieb:
> 2009/6/15 Jean-Pierre Bergamin <james at ractive.ch>:
>   
>> Hello Eric
>>
>>     
>>> 2009/6/15 Jean-Pierre Bergamin <james at ractive.ch>:
>>>       
>>>> Hello cmake users
>>>>
>>>> I want to put the current subversion revision into a script every time I run "make install".
>>>> Currently, I use configure_file() to replace a variable in the script, but this only updates the script when either the script or something in CMakeLists.txt changes. Is there a way to update the script every time I run "make install"?
>>>>         
>>> Did you try with
>>> install([[SCRIPT <file>] [CODE <code>]] [...])
>>>
>>> using this you may execute a CMake script at install time.
>>>       
>> Good idea. This may lead to what I'm looking for. My svn_revision.cmake
>> script now looks like this:
>>
>> find_package(Subversion)
>> if(Subversion_FOUND)
>>        Subversion_WC_INFO(${ER_SOURCE_DIR} ER)
>>        set(REVISION ${ER_WC_REVISION})
>>        configure_file(${ER_SOURCE_DIR}/scripts/version.sh.in
>> ${ER_SOURCE_DIR}/scripts/version.sh @ONLY)
>> endif(Subversion_FOUND)
>>
>> It is invoked in CMakeLists.txt with "install(SCRIPT svn_revision.cmake)".
>> The only problem I have now is that ${ER_SOURCE_DIR} is not defined in the
>> external script. Is there a way to pass arguments to this svn_revision.cmake
>> script?
>>     
>
> I don't know if you can pass arguments. But I personnally do it in another way
> using configure_file + install(script like this:
>
> CONFIGURE_FILE(svn_revision.cmake.in svn_revision.cmake @ONLY)
> INSTALL(SCRIPT ${CMAKE_BINARY_DIR}/svn_revision.cmake)
>
> Now the content of "svn_revision.cmake.in" should be something like:
>
> find_package(Subversion)
> if(Subversion_FOUND)
>         Subversion_WC_INFO(@ER_SOURCE_DIR@ ER)
>         set(REVISION @ER_WC_REVISION@)
>         configure_file(@ER_SOURCE_DIR@/scripts/version.sh.in
>                                  @ER_SOURCE_DIR@/scripts/version.sh @ONLY)
> endif(Subversion_FOUND)
>   
Ah great! I didn't think of the possibility to let cmake change a cmake 
skript on the fly. It works perfectly.


Thank you very much for your help

James


More information about the CMake mailing list