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(get_source_info_svn path revision repository)
7 # If svn is a bat file, find_program(Subversion) doesn't find it.
8 # Explicitly search for that here; Subversion_SVN_EXECUTABLE will override
9 # the find_program call in FindSubversion.cmake.
10 find_program(Subversion_SVN_EXECUTABLE NAMES svn svn.bat)
11 find_package(Subversion)
13 # Subversion module does not work with symlinks, see PR8437.
14 get_filename_component(realpath ${path} REALPATH)
16 subversion_wc_info(${realpath} Project)
17 if(Project_WC_REVISION)
18 set(${revision} ${Project_WC_REVISION} PARENT_SCOPE)
21 set(${repository} ${Project_WC_URL} PARENT_SCOPE)
26 function(get_source_info_git path revision repository)
29 execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --git-dir
30 WORKING_DIRECTORY ${path}
31 RESULT_VARIABLE git_result
32 OUTPUT_VARIABLE git_output
34 if(git_result EQUAL 0)
35 string(STRIP "${git_output}" git_output)
36 get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path})
37 if(EXISTS "${git_dir}/svn/refs")
38 execute_process(COMMAND ${GIT_EXECUTABLE} svn info
39 WORKING_DIRECTORY ${path}
40 RESULT_VARIABLE git_result
41 OUTPUT_VARIABLE git_output)
42 if(git_result EQUAL 0)
43 string(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
44 "\\2" git_svn_rev "${git_output}")
45 set(${revision} ${git_svn_rev} PARENT_SCOPE)
46 string(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
47 "\\2" git_url "${git_output}")
48 set(${repository} ${git_url} PARENT_SCOPE)
51 execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
52 WORKING_DIRECTORY ${path}
53 RESULT_VARIABLE git_result
54 OUTPUT_VARIABLE git_output)
55 if(git_result EQUAL 0)
56 string(STRIP "${git_output}" git_output)
57 set(${revision} ${git_output} PARENT_SCOPE)
59 execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref --symbolic-full-name @{upstream}
60 WORKING_DIRECTORY ${path}
61 RESULT_VARIABLE git_result
62 OUTPUT_VARIABLE git_output
64 if(git_result EQUAL 0)
65 string(REPLACE "/" ";" branch ${git_output})
66 list(GET branch 0 remote)
70 execute_process(COMMAND ${GIT_EXECUTABLE} remote get-url ${remote}
71 WORKING_DIRECTORY ${path}
72 RESULT_VARIABLE git_result
73 OUTPUT_VARIABLE git_output
75 if(git_result EQUAL 0)
76 string(STRIP "${git_output}" git_output)
77 set(${repository} ${git_output} PARENT_SCOPE)
79 set(${repository} ${path} PARENT_SCOPE)
86 function(get_source_info path revision repository)
87 if(EXISTS "${path}/.svn")
88 get_source_info_svn("${path}" revision_info repository_info)
90 get_source_info_git("${path}" revision_info repository_info)
92 set(${repository} "${repository_info}" PARENT_SCOPE)
93 set(${revision} "${revision_info}" PARENT_SCOPE)