Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 #! The revision description can be overridden by a ${prefix}_CUSTOM_REVISION_DESC variable.
15 #!
16 #! \param source_dir The directory containing a working copy
17 #! \param prefix A prefix to prepent to the variables containing
18 #! the extracted information
19 #!
20 function(mitkFunctionGetVersionDescription source_dir prefix)
21 
22  if(NOT prefix)
23  message(FATAL_ERROR "prefix argument not specified")
24  endif()
25 
26  if(${prefix}_CUSTOM_REVISION_DESC)
27  set(_wc_description ${${prefix}_CUSTOM_REVISION_DESC})
28  else()
29  # initialize variable
30  set(_wc_description "NO TAG FOUND")
31  set(_dirty_repo_str " [local changes]")
32 
33  find_package(Git)
34 
35  if(GIT_FOUND)
36  GIT_IS_REPO(${source_dir} _is_git_repo)
37  if(_is_git_repo)
38  execute_process(COMMAND ${GIT_EXECUTABLE} describe --exact-match --dirty=${_dirty_repo_str}
39  WORKING_DIRECTORY ${source_dir}
40  OUTPUT_VARIABLE _project_git_tagname
41  RESULT_VARIABLE _proper_version
42  ERROR_VARIABLE _description_error )
43  if(_proper_version EQUAL 0 )
44  set(_wc_description ${_project_git_tagname})
45  else(_proper_version EQUAL 0)
46  # the execution failed, i.e. the HEAD has no tag,
47  # for fallback string: execute again but without the --exact-match
48  execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty=${_dirty_repo_str}
49  WORKING_DIRECTORY ${source_dir}
50  OUTPUT_VARIABLE _wc_description
51  RESULT_VARIABLE _proper_version
52  ERROR_VARIABLE _description_error)
53  endif()
54  # remove newline at and of the string
55  string(STRIP "${_wc_description}" _wc_description)
56  endif()
57  endif()
58  endif()
59 
60  set(${prefix}_REVISION_DESC ${_wc_description} PARENT_SCOPE )
61 
62 endfunction()
mitkFunctionGetVersionDescription(source_dir, prefix)
Extract the version description from a local working copy.
GIT_IS_REPO(dir, result_var)