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}}) |
Oscar Fuentes | c54ca79 | 2010-10-22 17:16:26 +0000 | [diff] [blame] | 7 | if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn" ) |
Oscar Fuentes | ee99317 | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 8 | set(result "${result}svn") |
Oscar Fuentes | c54ca79 | 2010-10-22 17:16:26 +0000 | [diff] [blame] | 9 | # FindSubversion does not work with symlinks. See PR 8437 |
| 10 | if( NOT IS_SYMLINK "${CMAKE_CURRENT_SOURCE_DIR}" ) |
| 11 | find_package(Subversion) |
| 12 | endif() |
Oscar Fuentes | ee99317 | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 13 | if( Subversion_FOUND ) |
| 14 | subversion_wc_info( ${CMAKE_CURRENT_SOURCE_DIR} Project ) |
| 15 | if( Project_WC_REVISION ) |
Michael J. Spencer | 3df9c6b | 2010-09-08 20:49:40 +0000 | [diff] [blame] | 16 | set(result "${result}-r${Project_WC_REVISION}") |
Oscar Fuentes | ee99317 | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 17 | endif() |
| 18 | endif() |
| 19 | elseif( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git ) |
| 20 | set(result "${result}git") |
Oscar Fuentes | 59d5145 | 2010-08-05 02:22:51 +0000 | [diff] [blame] | 21 | # Try to get a ref-id |
| 22 | find_program(git_executable NAMES git git.exe git.cmd) |
| 23 | if( git_executable ) |
| 24 | execute_process(COMMAND ${git_executable} show-ref HEAD |
Michael J. Spencer | 3df9c6b | 2010-09-08 20:49:40 +0000 | [diff] [blame] | 25 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 26 | TIMEOUT 5 |
| 27 | RESULT_VARIABLE git_result |
| 28 | OUTPUT_VARIABLE git_output) |
Oscar Fuentes | 59d5145 | 2010-08-05 02:22:51 +0000 | [diff] [blame] | 29 | if( git_result EQUAL 0 ) |
Michael J. Spencer | 3df9c6b | 2010-09-08 20:49:40 +0000 | [diff] [blame] | 30 | string(SUBSTRING ${git_output} 0 7 git_ref_id) |
| 31 | set(result "${result}-${git_ref_id}") |
| 32 | else() |
| 33 | execute_process(COMMAND ${git_executable} svn log --limit=1 --oneline |
| 34 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 35 | TIMEOUT 5 |
| 36 | RESULT_VARIABLE git_result |
| 37 | OUTPUT_VARIABLE git_output) |
| 38 | if( git_result EQUAL 0 ) |
| 39 | string(REGEX MATCH r[0-9]+ git_svn_rev ${git_output}) |
| 40 | set(result "${result}-svn-${git_svn_rev}") |
| 41 | endif() |
Oscar Fuentes | 59d5145 | 2010-08-05 02:22:51 +0000 | [diff] [blame] | 42 | endif() |
| 43 | endif() |
Oscar Fuentes | ee99317 | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 44 | endif() |
| 45 | set(${VERS} ${result} PARENT_SCOPE) |
| 46 | endfunction(add_version_info_from_vcs) |