Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkFunctionGetVersion.cmake
Go to the documentation of this file.
1 #! \brief Extract version information from a local working copy
2 #!
3 #! If the source_dir variable points to a git repository, this function
4 #! extracts the current revision hash and branch/tag name.
5 #!
6 #! If the source_dir variable points to a subversion repository, this
7 #! function extracts the current svn revision.
8 #
9 #! The information is provided in
10 #! <ul>
11 #! <li> ${prefix}_REVISION_ID The git hash or svn revision value
12 #! <li> ${prefix}_REVISION_NAME The git branch/tag name or empty
13 #! <li> ${prefix}_WC_TYPE The working copy type, one of "local", "git", or "svn"
14 #! </ul>
15 #!
16 #! \param source_dir The directory containing a working copy
17 #! \param prefix A prefix to prepend to the variables containing
18 #! the extracted information.
19 #!
20 function(mitkFunctionGetVersion source_dir prefix)
21 
22  if(NOT prefix)
23  message(FATAL_ERROR "prefix argument not specified")
24  endif()
25 
26  # initialize variables
27  set(_wc_type "local")
28  set(_wc_id "")
29  set(_wc_name "")
30 
31 
32  find_package(Git)
33  if(GIT_FOUND)
34 
35  GIT_IS_REPO(${source_dir} _is_git_repo)
36  if(_is_git_repo)
37  set(_wc_type "git")
38  GIT_WC_INFO(${source_dir} ${prefix})
39 
40  set(_wc_id ${${prefix}_WC_REVISION_HASH})
41 
42  string(REPLACE " " ";" hash_name ${${prefix}_WC_REVISION_NAME})
43  list(GET hash_name 1 name)
44  if(name)
45  set(_wc_name ${name})
46  endif()
47  endif()
48  endif()
49 
50  # test for svn working copy
51  if(_wc_type STREQUAL "local")
52 
53  find_package(Subversion)
54  if(Subversion_FOUND)
55  execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} info
56  WORKING_DIRECTORY ${source_dir}
57  RESULT_VARIABLE _subversion_result
58  OUTPUT_QUIET
59  ERROR_QUIET)
60 
61  if(NOT _subversion_result)
62  set(_wc_type svn)
63  Subversion_WC_INFO(${source_dir} ${prefix})
64  set(_wc_id ${${prefix}_WC_REVISION})
65  endif()
66  endif()
67 
68  endif()
69 
70  set(${prefix}_WC_TYPE ${_wc_type} PARENT_SCOPE)
71  set(${prefix}_REVISION_ID ${_wc_id} PARENT_SCOPE)
72  set(_shortid ${_wc_id})
73  if(_wc_type STREQUAL "git")
74  string(SUBSTRING ${_shortid} 0 8 _shortid)
75  endif()
76  set(${prefix}_REVISION_SHORTID ${_shortid} PARENT_SCOPE)
77  set(${prefix}_REVISION_NAME ${_wc_name} PARENT_SCOPE)
78 
79  # For backwards compatibility
80  set(${prefix}_WC_REVISION_HASH ${_wc_id} PARENT_SCOPE)
81  set(${prefix}_WC_REVISION_NAME ${_wc_name} PARENT_SCOPE)
82 
83 endfunction()
mitkFunctionGetVersion(source_dir, prefix)
Extract version information from a local working copy.
GIT_WC_INFO(dir, prefix)
GIT_IS_REPO(dir, result_var)
static void info(const char *fmt,...)
Definition: svm.cpp:100