Oscar Fuentes | 052c23c | 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) |
Chandler Carruth | 667f217 | 2011-12-10 09:41:13 +0000 | [diff] [blame] | 6 | string(REPLACE "svn" "" result "${${VERS}}") |
Oscar Fuentes | 26b1d20 | 2010-10-22 17:16:26 +0000 | [diff] [blame] | 7 | if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn" ) |
Oscar Fuentes | 052c23c | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 8 | set(result "${result}svn") |
Oscar Fuentes | 26b1d20 | 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 | 052c23c | 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 ) |
Chandler Carruth | 7514da9 | 2011-12-10 10:04:38 +0000 | [diff] [blame] | 16 | set(SVN_REVISION ${Project_WC_REVISION} PARENT_SCOPE) |
Michael J. Spencer | ad39c92 | 2010-09-08 20:49:40 +0000 | [diff] [blame] | 17 | set(result "${result}-r${Project_WC_REVISION}") |
Oscar Fuentes | 052c23c | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 18 | endif() |
Chris Bieneman | 6bfebb7 | 2016-01-14 22:44:29 +0000 | [diff] [blame] | 19 | if( Project_WC_URL ) |
| 20 | set(LLVM_REPOSITORY ${Project_WC_URL} PARENT_SCOPE) |
| 21 | endif() |
Oscar Fuentes | 052c23c | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 22 | endif() |
| 23 | elseif( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git ) |
| 24 | set(result "${result}git") |
Oscar Fuentes | fc21c3a | 2010-08-05 02:22:51 +0000 | [diff] [blame] | 25 | # Try to get a ref-id |
Jim Grosbach | f7cbcf2 | 2012-12-10 19:03:37 +0000 | [diff] [blame] | 26 | if( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/svn ) |
| 27 | find_program(git_executable NAMES git git.exe git.cmd) |
| 28 | if( git_executable ) |
| 29 | set(is_git_svn_rev_exact false) |
Geoff Berry | 5c6e076 | 2016-01-19 17:36:02 +0000 | [diff] [blame^] | 30 | execute_process(COMMAND |
| 31 | ${git_executable} svn info |
Jim Grosbach | f7cbcf2 | 2012-12-10 19:03:37 +0000 | [diff] [blame] | 32 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 33 | TIMEOUT 5 |
| 34 | RESULT_VARIABLE git_result |
| 35 | OUTPUT_VARIABLE git_output) |
Michael J. Spencer | ad39c92 | 2010-09-08 20:49:40 +0000 | [diff] [blame] | 36 | if( git_result EQUAL 0 ) |
Geoff Berry | 5c6e076 | 2016-01-19 17:36:02 +0000 | [diff] [blame^] | 37 | string(REGEX MATCH "URL: ([^ \n]*)" svn_url ${git_output}) |
| 38 | if(svn_url) |
| 39 | set(LLVM_REPOSITORY ${CMAKE_MATCH_1} PARENT_SCOPE) |
| 40 | endif() |
| 41 | |
| 42 | string(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*" |
| 43 | "\\2" git_svn_rev_number "${git_output}") |
Jim Grosbach | f7cbcf2 | 2012-12-10 19:03:37 +0000 | [diff] [blame] | 44 | set(SVN_REVISION ${git_svn_rev_number} PARENT_SCOPE) |
| 45 | set(git_svn_rev "-svn-${git_svn_rev}") |
| 46 | |
| 47 | # Determine if the HEAD points directly at a subversion revision. |
| 48 | execute_process(COMMAND ${git_executable} svn find-rev HEAD |
| 49 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 50 | TIMEOUT 5 |
| 51 | RESULT_VARIABLE git_result |
| 52 | OUTPUT_VARIABLE git_output) |
| 53 | if( git_result EQUAL 0 ) |
| 54 | string(STRIP "${git_output}" git_head_svn_rev_number) |
| 55 | if( git_head_svn_rev_number EQUAL git_svn_rev_number ) |
| 56 | set(is_git_svn_rev_exact true) |
| 57 | endif() |
Chandler Carruth | 667f217 | 2011-12-10 09:41:13 +0000 | [diff] [blame] | 58 | endif() |
Jim Grosbach | f7cbcf2 | 2012-12-10 19:03:37 +0000 | [diff] [blame] | 59 | else() |
| 60 | set(git_svn_rev "") |
Michael J. Spencer | ad39c92 | 2010-09-08 20:49:40 +0000 | [diff] [blame] | 61 | endif() |
Jim Grosbach | f7cbcf2 | 2012-12-10 19:03:37 +0000 | [diff] [blame] | 62 | execute_process(COMMAND |
| 63 | ${git_executable} rev-parse --short HEAD |
| 64 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 65 | TIMEOUT 5 |
| 66 | RESULT_VARIABLE git_result |
| 67 | OUTPUT_VARIABLE git_output) |
| 68 | if( git_result EQUAL 0 AND NOT is_git_svn_rev_exact ) |
| 69 | string(STRIP "${git_output}" git_ref_id) |
| 70 | set(GIT_COMMIT ${git_ref_id} PARENT_SCOPE) |
| 71 | set(result "${result}${git_svn_rev}-${git_ref_id}") |
| 72 | else() |
| 73 | set(result "${result}${git_svn_rev}") |
| 74 | endif() |
Chris Bieneman | 6bfebb7 | 2016-01-14 22:44:29 +0000 | [diff] [blame] | 75 | |
Oscar Fuentes | fc21c3a | 2010-08-05 02:22:51 +0000 | [diff] [blame] | 76 | endif() |
| 77 | endif() |
Oscar Fuentes | 052c23c | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 78 | endif() |
| 79 | set(${VERS} ${result} PARENT_SCOPE) |
| 80 | endfunction(add_version_info_from_vcs) |