diff --git a/CMakeLists.txt b/CMakeLists.txt index 6de26879cc..d50c92b954 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -526,16 +526,7 @@ set(OPENCV_EXTRA_MODULES_PATH "" CACHE PATH "Where to look for additional OpenCV find_host_package(Git QUIET) if(NOT DEFINED OPENCV_VCSVERSION AND GIT_FOUND) - execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags --always --dirty --match "[0-9].[0-9].[0-9]*" - WORKING_DIRECTORY "${OpenCV_SOURCE_DIR}" - OUTPUT_VARIABLE OPENCV_VCSVERSION - RESULT_VARIABLE GIT_RESULT - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - if(NOT GIT_RESULT EQUAL 0) - set(OPENCV_VCSVERSION "unknown") - endif() + ocv_git_describe(OPENCV_VCSVERSION "${OpenCV_SOURCE_DIR}") elseif(NOT DEFINED OPENCV_VCSVERSION) # We don't have git: set(OPENCV_VCSVERSION "unknown") @@ -931,19 +922,7 @@ if(OPENCV_EXTRA_MODULES_PATH AND NOT BUILD_INFO_SKIP_EXTRA_MODULES) else() status("") endif() - set(EXTRA_MODULES_VCSVERSION "unknown") - if(GIT_FOUND) - execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags --always --dirty --match "[0-9].[0-9].[0-9]*" - WORKING_DIRECTORY "${p}" - OUTPUT_VARIABLE EXTRA_MODULES_VCSVERSION - RESULT_VARIABLE GIT_RESULT - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - if(NOT GIT_RESULT EQUAL 0) - set(EXTRA_MODULES_VCSVERSION "unknown") - endif() - endif() + ocv_git_describe(EXTRA_MODULES_VCSVERSION "${p}") status(" Location (extra):" ${p}) status(" Version control (extra):" ${EXTRA_MODULES_VCSVERSION}) endif() diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index be79111423..65029ddbff 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -1620,3 +1620,40 @@ if(NOT CMAKE_VERSION VERSION_LESS 3.1) else() set(compatible_MESSAGE_NEVER "") endif() + + +macro(ocv_git_describe var_name path) + if(GIT_FOUND) + execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags --tags --exact-match --dirty + WORKING_DIRECTORY "${path}" + OUTPUT_VARIABLE ${var_name} + RESULT_VARIABLE GIT_RESULT + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT GIT_RESULT EQUAL 0) + execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags --always --dirty --match "[0-9].[0-9].[0-9]*" --exclude "[^-]*-cvsdk" + WORKING_DIRECTORY "${path}" + OUTPUT_VARIABLE ${var_name} + RESULT_VARIABLE GIT_RESULT + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT GIT_RESULT EQUAL 0) # --exclude is not supported by 'git' + # match only tags with complete OpenCV versions (ignores -alpha/-beta/-rc suffixes) + execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags --always --dirty --match "[0-9].[0-9]*[0-9]" + WORKING_DIRECTORY "${path}" + OUTPUT_VARIABLE ${var_name} + RESULT_VARIABLE GIT_RESULT + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT GIT_RESULT EQUAL 0) + set(${var_name} "unknown") + endif() + endif() + endif() + else() + set(${var_name} "unknown") + endif() +endmacro()