Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkFunctionGetVersionDescription.cmake
Go to the documentation of this file.
1 #! \brief Extract the version description from a local working copy
2 #!
3 #! If the given repository is a git repository, the functions runs the
4 #! git rev-parse --exact-match HEAD command
5 #!
6 #! Information provided is stored in ${prefix}_REVISION_DESC an is
7 #! \ul
8 #! \li The exact tag if the HEAD of the source-tree has a tag
9 #! \li the 'git describe' output, which is <latest-reachable-tag>-<#Commits>-g<SHORT-HASH>
10 #! \lu
11 #! In case the working copy contains local changes, the ${prefix}_REVISION_DESC strings will contain
12 #! a suffix [local changes]
13 #!
14 #! \param source_dir The directory containing a working copy
15 #! \param prefix A prefix to prepent to the variables containing
16 #! the extracted information
17 #!
18 function(mitkFunctionGetVersionDescription source_dir prefix)
19 
20  if(NOT prefix)
21  message(FATAL_ERROR "prefix argument not specified")
22  endif()
23 
24  # initialize variable
25  set(_wc_description "NO TAG FOUND")
26  set(_dirty_repo_str " [local changes]")
27 
28  find_package(Git)
29  if(GIT_FOUND)
30 
31  GIT_IS_REPO(${source_dir} _is_git_repo)
32  if(_is_git_repo)
33  execute_process(COMMAND ${GIT_EXECUTABLE} describe --exact-match --dirty=${_dirty_repo_str}
34  WORKING_DIRECTORY ${source_dir}
35  OUTPUT_VARIABLE _project_git_tagname
36  RESULT_VARIABLE _proper_version
37  ERROR_VARIABLE _description_error )
38  if(_proper_version EQUAL 0 )
39  set(_wc_description ${_project_git_tagname})
40 
41  else(_proper_version EQUAL 0)
42  # the execution failed, i.e. the HEAD has no tag,
43  # for fallback string: execute again but without the --exact-match
44  execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty=${_dirty_repo_str}
45  WORKING_DIRECTORY ${source_dir}
46  OUTPUT_VARIABLE _wc_description
47  RESULT_VARIABLE _proper_version
48  ERROR_VARIABLE _description_error)
49  endif()
50 
51  # remove newline at and of the string
52  string(STRIP "${_wc_description}" _wc_description)
53 
54  endif()
55  endif()
56 
57  set(${prefix}_REVISION_DESC ${_wc_description} PARENT_SCOPE )
58 
59 endfunction()
mitkFunctionGetVersionDescription(source_dir, prefix)
Extract the version description from a local working copy.
GIT_IS_REPO(dir, result_var)