[CMake] Building a Version Header

Clark Gaebel cg.wowus.cg at gmail.com
Wed Jul 7 23:21:38 EDT 2010


Thank you! That's perfect. I just KNEW there would be a command to do that!

On 07/07/10 23:10, John Drescher wrote:
> On Wed, Jul 7, 2010 at 11:04 PM, John Drescher <drescherjm at gmail.com> wrote:
>   
>> On Wed, Jul 7, 2010 at 10:59 PM, Clark Gaebel <cg.wowus.cg at gmail.com> wrote:
>>     
>>> Is there any way I can use the output from a command-line program (in
>>> this case, "git describe --dirty") instead of using FindGit?
>>>
>>>       
>> I believe
>> add_custom_command
>>
>> but I can not help with an example of that.
>>
>>     
> When looking at the source for FindSubversion.cmake this looks pretty
> easy to modify. I guess you can put the Macro code inside your
> CMakeLists.txt if you do not want to mess with Findgit.cmake.
>
> MACRO(Subversion_WC_INFO dir prefix)
>     # the subversion commands should be executed with the C locale, otherwise
>     # the message (which are parsed) may be translated, Alex
>     SET(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
>     SET(ENV{LC_ALL} C)
>
>     EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} --version
>       WORKING_DIRECTORY ${dir}
>       OUTPUT_VARIABLE Subversion_VERSION_SVN
>       OUTPUT_STRIP_TRAILING_WHITESPACE)
>
>     EXECUTE_PROCESS(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir}
>       OUTPUT_VARIABLE ${prefix}_WC_INFO
>       ERROR_VARIABLE Subversion_svn_info_error
>       RESULT_VARIABLE Subversion_svn_info_result
>       OUTPUT_STRIP_TRAILING_WHITESPACE)
>
>     IF(NOT ${Subversion_svn_info_result} EQUAL 0)
>       MESSAGE(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info
> ${dir}\" failed with output:\n${Subversion_svn_info_error}")
>     ELSE(NOT ${Subversion_svn_info_result} EQUAL 0)
>
>       STRING(REGEX REPLACE "^(.*\n)?svn, version ([.0-9]+).*"
>         "\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}")
>       STRING(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
>         "\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}")
>       STRING(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
>         "\\2" ${prefix}_WC_REVISION "${${prefix}_WC_INFO}")
>       STRING(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*"
>         "\\2" ${prefix}_WC_LAST_CHANGED_AUTHOR "${${prefix}_WC_INFO}")
>       STRING(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*"
>         "\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}")
>       STRING(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*"
>         "\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}")
>
>     ENDIF(NOT ${Subversion_svn_info_result} EQUAL 0)
>
>     # restore the previous LC_ALL
>     SET(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
>
>   ENDMACRO(Subversion_WC_INFO)
>
>
> All the work you need is in the EXECUTE_PROCESS. Replace the
> subversion commands with git commands and fixup the output.
>
> John
>   

-- 
Regards,
-Clark



More information about the CMake mailing list