Oscar Fuentes | ee99317 | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 1 | # Adds version control information to the variable VERS. For |
| 2 | # determining the Version Control System used (if any) it inspects the |
| 3 | # existence of certain subdirectories under CMAKE_CURRENT_SOURCE_DIR. |
| 4 | |
| 5 | function(add_version_info_from_vcs VERS) |
| 6 | set(result ${${VERS}}) |
| 7 | if( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.svn ) |
| 8 | set(result "${result}svn") |
| 9 | find_package(Subversion) |
| 10 | if( Subversion_FOUND ) |
| 11 | subversion_wc_info( ${CMAKE_CURRENT_SOURCE_DIR} Project ) |
| 12 | if( Project_WC_REVISION ) |
Michael J. Spencer | 3df9c6b | 2010-09-08 20:49:40 +0000 | [diff] [blame^] | 13 | set(result "${result}-r${Project_WC_REVISION}") |
Oscar Fuentes | ee99317 | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 14 | endif() |
| 15 | endif() |
| 16 | elseif( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git ) |
| 17 | set(result "${result}git") |
Oscar Fuentes | 59d5145 | 2010-08-05 02:22:51 +0000 | [diff] [blame] | 18 | # Try to get a ref-id |
| 19 | find_program(git_executable NAMES git git.exe git.cmd) |
| 20 | if( git_executable ) |
| 21 | execute_process(COMMAND ${git_executable} show-ref HEAD |
Michael J. Spencer | 3df9c6b | 2010-09-08 20:49:40 +0000 | [diff] [blame^] | 22 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 23 | TIMEOUT 5 |
| 24 | RESULT_VARIABLE git_result |
| 25 | OUTPUT_VARIABLE git_output) |
Oscar Fuentes | 59d5145 | 2010-08-05 02:22:51 +0000 | [diff] [blame] | 26 | if( git_result EQUAL 0 ) |
Michael J. Spencer | 3df9c6b | 2010-09-08 20:49:40 +0000 | [diff] [blame^] | 27 | string(SUBSTRING ${git_output} 0 7 git_ref_id) |
| 28 | set(result "${result}-${git_ref_id}") |
| 29 | else() |
| 30 | execute_process(COMMAND ${git_executable} svn log --limit=1 --oneline |
| 31 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 32 | TIMEOUT 5 |
| 33 | RESULT_VARIABLE git_result |
| 34 | OUTPUT_VARIABLE git_output) |
| 35 | if( git_result EQUAL 0 ) |
| 36 | string(REGEX MATCH r[0-9]+ git_svn_rev ${git_output}) |
| 37 | set(result "${result}-svn-${git_svn_rev}") |
| 38 | endif() |
Oscar Fuentes | 59d5145 | 2010-08-05 02:22:51 +0000 | [diff] [blame] | 39 | endif() |
| 40 | endif() |
Oscar Fuentes | ee99317 | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 41 | endif() |
| 42 | set(${VERS} ${result} PARENT_SCOPE) |
| 43 | endfunction(add_version_info_from_vcs) |