diff --git a/CMake/mitkFunctionGetVersionDescription.cmake b/CMake/mitkFunctionGetVersionDescription.cmake index 9e47452e93..a4140dd867 100644 --- a/CMake/mitkFunctionGetVersionDescription.cmake +++ b/CMake/mitkFunctionGetVersionDescription.cmake @@ -1,59 +1,65 @@ #! \brief Extract the version description from a local working copy #! #! If the given repository is a git repository, the functions runs the #! git rev-parse --exact-match HEAD command #! #! Information provided is stored in ${prefix}_REVISION_DESC an is #! \ul #! \li The exact tag if the HEAD of the source-tree has a tag #! \li the 'git describe' output, which is -<#Commits>-g #! \lu #! In case the working copy contains local changes, the ${prefix}_REVISION_DESC strings will contain #! a suffix [local changes] #! #! \param source_dir The directory containing a working copy #! \param prefix A prefix to prepent to the variables containing #! the extracted information #! function(mitkFunctionGetVersionDescription source_dir prefix) if(NOT prefix) message(FATAL_ERROR "prefix argument not specified") endif() # initialize variable - set(_wc_description "NO TAG FOUND") + set(_wc_description "unknown_version") set(_dirty_repo_str "-local_changes") find_package(Git) if(GIT_FOUND) GIT_IS_REPO(${source_dir} _is_git_repo) if(_is_git_repo) execute_process(COMMAND ${GIT_EXECUTABLE} describe --exact-match --dirty=${_dirty_repo_str} WORKING_DIRECTORY ${source_dir} OUTPUT_VARIABLE _project_git_tagname - RESULT_VARIABLE _proper_version - ERROR_VARIABLE _description_error ) - if(_proper_version EQUAL 0 ) + RESULT_VARIABLE _proper_version) + if(_proper_version EQUAL 0) set(_wc_description ${_project_git_tagname}) - else(_proper_version EQUAL 0) + else() # the execution failed, i.e. the HEAD has no tag, # for fallback string: execute again but without the --exact-match execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty=${_dirty_repo_str} WORKING_DIRECTORY ${source_dir} OUTPUT_VARIABLE _wc_description - RESULT_VARIABLE _proper_version - ERROR_VARIABLE _description_error) + RESULT_VARIABLE _proper_version) + + if(_proper_version EQUAL 0) + # last fallback, i.e. working copy is a shallow clone, at least use + # commit hash + execute_process(COMMAND ${GIT_EXECUTABLE} describe --always --dirty=${_dirty_repo_str} + WORKING_DIRECTORY ${source_dir} + OUTPUT_VARIABLE _wc_description) + endif() endif() # remove newline at and of the string string(STRIP "${_wc_description}" _wc_description) endif() endif() - set(${prefix}_REVISION_DESC ${_wc_description} PARENT_SCOPE ) + set(${prefix}_REVISION_DESC ${_wc_description} PARENT_SCOPE) endfunction()