Browse Source

Simplify the version parsing logic.

current HEAD                -> 1.8-ALPHA.11
tag 1.8-ALPHA               -> 1.8-ALPHA.0
one commit before 1.8-ALPHA -> 1.7.759
tag 1.7                     -> 1.7.0
one commit before 1.7       -> 1.6.1152
Yao Wei Tjong 姚伟忠 6 years ago
parent
commit
3ad625a459
1 changed files with 5 additions and 6 deletions
  1. 5 6
      CMake/Modules/GetUrhoRevision.cmake

+ 5 - 6
CMake/Modules/GetUrhoRevision.cmake

@@ -40,21 +40,20 @@ if (FILENAME)
     file (WRITE ${FILENAME} "const char* revision=\"${LIB_REVISION}\";\n")
     file (WRITE ${FILENAME} "const char* revision=\"${LIB_REVISION}\";\n")
 else ()
 else ()
     # Output just major.minor.patch number to stdout
     # Output just major.minor.patch number to stdout
-    string (REGEX MATCH "[^.]+\\.[^-]+" VERSION ${LIB_REVISION})                    # Assume release tag always has major.minor format with possible pre-release identifier
+    string (REGEX MATCH "[^.]+\\.[^-]+" VERSION ${LIB_REVISION})            # Assume release tag always has major.minor format with possible pre-release identifier
     if (VERSION)
     if (VERSION)
-        string (REGEX MATCH "${VERSION}(-[A-Z]+)" PRE_ID ${LIB_REVISION})            # Workaround as CMake's regex does not support look around
+        string (REGEX MATCH "${VERSION}-([A-Z]+)" PRE_ID ${LIB_REVISION})   # Workaround as CMake's regex does not support look around
         if (PRE_ID)
         if (PRE_ID)
-            set (PRE_ID ${CMAKE_MATCH_1})
+            set (VERSION ${VERSION}-${CMAKE_MATCH_1})
         endif ()
         endif ()
-        string (REGEX MATCH "${VERSION}${PRE_ID}-([^-]+)" PATCH ${LIB_REVISION})    # Subsequent commits count after a release tag is treated as patch number
+        string (REGEX MATCH "${VERSION}-([^-]+)" PATCH ${LIB_REVISION})     # Subsequent commits count after a release tag is treated as patch number
         if (PATCH)
         if (PATCH)
             set (VERSION ${VERSION}.${CMAKE_MATCH_1})
             set (VERSION ${VERSION}.${CMAKE_MATCH_1})
-            unset (PRE_ID)
         else ()
         else ()
             set (VERSION ${VERSION}.0)
             set (VERSION ${VERSION}.0)
         endif ()
         endif ()
     else ()
     else ()
         set (VERSION 0.0.0)
         set (VERSION 0.0.0)
     endif ()
     endif ()
-    execute_process (COMMAND ${CMAKE_COMMAND} -E echo ${VERSION}${PRE_ID})
+    execute_process (COMMAND ${CMAKE_COMMAND} -E echo ${VERSION})
 endif ()
 endif ()