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 SOURCE_DIR (if provided as an
4 # extra argument, otherwise uses CMAKE_CURRENT_SOURCE_DIR).
6 function(add_version_info_from_vcs VERS)
7 SET(SOURCE_DIR ${ARGV1})
8 if("${SOURCE_DIR}" STREQUAL "")
9 SET(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
11 string(REPLACE "svn" "" result "${${VERS}}")
12 if( EXISTS "${SOURCE_DIR}/.svn" )
13 set(result "${result}svn")
14 # FindSubversion does not work with symlinks. See PR 8437
15 if( NOT IS_SYMLINK "${SOURCE_DIR}" )
16 find_package(Subversion)
18 if( Subversion_FOUND )
19 subversion_wc_info( ${SOURCE_DIR} Project )
20 if( Project_WC_REVISION )
21 set(SVN_REVISION ${Project_WC_REVISION} PARENT_SCOPE)
22 set(result "${result}-r${Project_WC_REVISION}")
25 set(LLVM_REPOSITORY ${Project_WC_URL} PARENT_SCOPE)
29 find_program(git_executable NAMES git git.exe git.cmd)
32 # Run from a subdirectory to force git to print an absoute path.
33 execute_process(COMMAND ${git_executable} rev-parse --git-dir
34 WORKING_DIRECTORY ${SOURCE_DIR}/cmake
35 RESULT_VARIABLE git_result
36 OUTPUT_VARIABLE git_dir
38 if(git_result EQUAL 0)
40 string(STRIP "${git_dir}" git_dir)
41 set(result "${result}git")
42 if( EXISTS ${git_dir}/svn )
43 # Get the repository URL
44 execute_process(COMMAND
45 ${git_executable} svn info
46 WORKING_DIRECTORY ${SOURCE_DIR}
48 RESULT_VARIABLE git_result
49 OUTPUT_VARIABLE git_output
51 if( git_result EQUAL 0 )
52 string(REGEX MATCH "URL: ([^ \n]*)" svn_url ${git_output})
54 set(LLVM_REPOSITORY ${CMAKE_MATCH_1} PARENT_SCOPE)
58 # Get the svn revision number for this git commit if one exists.
59 execute_process(COMMAND ${git_executable} svn find-rev HEAD
60 WORKING_DIRECTORY ${SOURCE_DIR}
62 RESULT_VARIABLE git_result
63 OUTPUT_VARIABLE git_head_svn_rev_number
64 OUTPUT_STRIP_TRAILING_WHITESPACE)
65 if( git_result EQUAL 0 AND git_output)
66 set(SVN_REVISION ${git_head_svn_rev_number} PARENT_SCOPE)
67 set(git_svn_rev "-svn-${git_head_svn_rev_number}")
74 execute_process(COMMAND
75 ${git_executable} rev-parse --short HEAD
76 WORKING_DIRECTORY ${SOURCE_DIR}
78 RESULT_VARIABLE git_result
79 OUTPUT_VARIABLE git_ref_id
80 OUTPUT_STRIP_TRAILING_WHITESPACE)
82 if( git_result EQUAL 0 )
83 set(GIT_COMMIT ${git_ref_id} PARENT_SCOPE)
84 set(result "${result}${git_svn_rev}-${git_ref_id}")
86 set(result "${result}${git_svn_rev}")
91 set(${VERS} ${result} PARENT_SCOPE)
92 endfunction(add_version_info_from_vcs)