]> git.treefish.org Git - cmake-modules/cmake-getgitversion.git/commitdiff
various improvements
authorAlexander Schmidt <alex@treefish.org>
Sun, 25 Oct 2015 19:48:56 +0000 (20:48 +0100)
committerAlexander Schmidt <alex@treefish.org>
Sun, 25 Oct 2015 19:48:56 +0000 (20:48 +0100)
GetGitVersion.cmake

index 202fbf3ed80f6015793a7324677c1aede4e22ffe..8f679d39138e56577cf5129a32b174113d7ebd70 100644 (file)
@@ -3,8 +3,8 @@
 # Obtain version string from git tags via git_describe and parse result into
 # convenient version variables.
 #
-# Tags have to be in the format .*([0-9]+)\.([0-9]+)\.([0-9]+)-(.*), as in
-# v1.2.3-rc5, where the expressions in parentheses are interpreted as major,
+# Tags have to match the regex ^[^0-9]*([0-9]+)\.([0-9]+)\.([0-9]+)-([0-9a-zA-Z]+),
+# as in v1.2.3-rc5, where the expressions in parentheses are interpreted as major,
 # minor, patch and extra (package release) version numbers.
 #
 # Usage:
@@ -33,17 +33,28 @@ function(get_git_version _gitversionprefix)
     string(REGEX REPLACE
            "^[^0-9]*[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_DESCRIPTION}")
     string(REGEX REPLACE
-           "^[^0-9]*[0-9]+\\.[0-9]+\\.[0-9]+-(.*)" "\\1" VERSION_EXTRA "${GIT_DESCRIPTION}")
+           "^[^0-9]*[0-9]+\\.[0-9]+\\.[0-9]+-([0-9a-zA-Z-]+).*" "\\1" VERSION_EXTRA "${GIT_DESCRIPTION}")
     string(REGEX REPLACE
            "([^-]*-g)" "r\\1" VERSION_EXTRA "${VERSION_EXTRA}")
     string(REGEX REPLACE
            "-" "." VERSION_EXTRA "${VERSION_EXTRA}")
+          
+    set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_EXTRA}")
 
+    if(NOT "${VERSION}" MATCHES
+       "^[0-9]+\\.[0-9]+\\.[0-9]+-[0-9a-zA-Z]+\\.?r?[0-9]*\\.?g?[0-9a-zA-Z]*$")
+
+        message(FATAL_ERROR 
+                "\nCOULD NOT EXTRACT VALID VERSION STRING FROM git_describe!"
+                "\n git_describe returned: \"${GIT_DESCRIPTION}\""
+                "\n Extracted invalid version string: \"${VERSION}\"\n")
+
+    endif(NOT "${VERSION}" MATCHES
+          "^[0-9]+\\.[0-9]+\\.[0-9]+-[0-9a-zA-Z]+\\.?r?[0-9]*\\.?g?[0-9a-zA-Z]*$")
+
+    set(${_gitversionprefix}       "${VERSION}"       PARENT_SCOPE)
     set(${_gitversionprefix}_MAJOR "${VERSION_MAJOR}" PARENT_SCOPE)
     set(${_gitversionprefix}_MINOR "${VERSION_MINOR}" PARENT_SCOPE)
     set(${_gitversionprefix}_PATCH "${VERSION_PATCH}" PARENT_SCOPE)
     set(${_gitversionprefix}_EXTRA "${VERSION_EXTRA}" PARENT_SCOPE)
-
-    set(${_gitversionprefix}
-       "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_EXTRA}" PARENT_SCOPE)
 endfunction()