Make ReactOS report the Git revision as output by "git describe".
[reactos.git] / sdk / include / reactos / version.cmake
index e5f0bb1..6c2247a 100644 (file)
@@ -1,63 +1,50 @@
-macro(inttohex INTVALUE OUTPUT_VARIABLE)
-    list(APPEND HEXLIST 0 1 2 3 4 5 6 7 8 9 a b c d e f)
-    list(GET HEXLIST ${INTVALUE} ${OUTPUT_VARIABLE})
-endmacro()
-
-macro(converttohex INTVALUE OUTPUT_VARIABLE)
-    set(${OUTPUT_VARIABLE} "")
-    set(REMAINING ${INTVALUE})
-    while(REMAINING)
-        math(EXPR REMAINDER "${REMAINING}%16")
-        inttohex(${REMAINDER} HEXCHAR)
-        math(EXPR REMAINING "${REMAINING}/16")
-        set(${OUTPUT_VARIABLE} "${HEXCHAR}${${OUTPUT_VARIABLE}}")
-    endwhile()
-endmacro()
-
 string(TIMESTAMP KERNEL_VERSION_BUILD %Y%m%d UTC)
 
 set(KERNEL_VERSION_MAJOR "0")
-set(KERNEL_VERSION_MINOR "5")
-set(KERNEL_VERSION_PATCH_LEVEL "0")
+set(KERNEL_VERSION_MINOR "4")
+set(KERNEL_VERSION_PATCH_LEVEL "7")
 set(COPYRIGHT_YEAR "2017")
 
-# KERNEL_VERSION_BUILD_TYPE is "SVN" or "" (for the release)
-set(KERNEL_VERSION_BUILD_TYPE "SVN")
+# KERNEL_VERSION_BUILD_TYPE is "dev" for Git builds
+# or "RC1", "RC2", "" for releases.
+set(KERNEL_VERSION_BUILD_TYPE "dev")
 
-# KERNEL_VERSION_RELEASE_TYPE is "RC1", "RC2" or "" (for the final one)
-set(KERNEL_VERSION_RELEASE_TYPE "")
-
-set(KERNEL_VERSION "${KERNEL_VERSION_MAJOR}.${KERNEL_VERSION_MINOR}")
-if(KERNEL_VERSION_PATCH_LEVEL)
-    set(KERNEL_VERSION "${KERNEL_VERSION}.${KERNEL_VERSION_PATCH_LEVEL}")
-endif()
-if(KERNEL_VERSION_BUILD_TYPE STREQUAL "SVN")
+set(KERNEL_VERSION "${KERNEL_VERSION_MAJOR}.${KERNEL_VERSION_MINOR}.${KERNEL_VERSION_PATCH_LEVEL}")
+if(NOT KERNEL_VERSION_BUILD_TYPE STREQUAL "")
     set(KERNEL_VERSION "${KERNEL_VERSION}-${KERNEL_VERSION_BUILD_TYPE}")
-elseif(NOT KERNEL_VERSION_RELEASE_TYPE STREQUAL "")
-    set(KERNEL_VERSION "${KERNEL_VERSION}-${KERNEL_VERSION_RELEASE_TYPE}")
 endif()
 
 math(EXPR REACTOS_DLL_VERSION_MAJOR "${KERNEL_VERSION_MAJOR}+42")
-set(DLL_VERSION_STR "${REACTOS_DLL_VERSION_MAJOR}.${KERNEL_VERSION_MINOR}")
-if(KERNEL_VERSION_PATCH_LEVEL)
-    set(DLL_VERSION_STR "${DLL_VERSION_STR}.${KERNEL_VERSION_PATCH_LEVEL}")
-endif()
-if(KERNEL_VERSION_BUILD_TYPE STREQUAL "SVN")
+set(DLL_VERSION_STR "${REACTOS_DLL_VERSION_MAJOR}.${KERNEL_VERSION_MINOR}.${KERNEL_VERSION_PATCH_LEVEL}")
+if(NOT KERNEL_VERSION_BUILD_TYPE STREQUAL "")
     set(DLL_VERSION_STR "${DLL_VERSION_STR}-${KERNEL_VERSION_BUILD_TYPE}")
-elseif(NOT KERNEL_VERSION_RELEASE_TYPE STREQUAL "")
-    set(DLL_VERSION_STR "${DLL_VERSION_STR}-${KERNEL_VERSION_RELEASE_TYPE}")
 endif()
 
-# get svn revision number
-set(REVISION "rUNKNOWN")
-set(KERNEL_VERSION_BUILD_HEX "0")
-if(EXISTS "${REACTOS_SOURCE_DIR}/.svn" OR EXISTS "${REACTOS_SOURCE_DIR}/../.svn")
-    find_package(Subversion)
-    if(Subversion_FOUND)
-        subversion_wc_info(${REACTOS_SOURCE_DIR} SVNINFO)
-        if(SVNINFO_WC_REVISION)
-            set(REVISION "r${SVNINFO_WC_REVISION}")
-            converttohex(${SVNINFO_WC_REVISION} KERNEL_VERSION_BUILD_HEX)
+# Get Git revision through "git describe"
+set(COMMIT_HASH "unknown-hash")
+set(REVISION "unknown-revision")
+
+if(EXISTS "${REACTOS_SOURCE_DIR}/.git")
+    find_package(Git)
+    if(GIT_FOUND)
+        execute_process(
+            COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD
+            OUTPUT_VARIABLE GIT_COMMIT_HASH
+            RESULT_VARIABLE GIT_CALL_RESULT
+            OUTPUT_STRIP_TRAILING_WHITESPACE
+        )
+        if(GIT_CALL_RESULT EQUAL 0)
+            set(COMMIT_HASH "${GIT_COMMIT_HASH}")
+        endif()
+
+        execute_process(
+            COMMAND "${GIT_EXECUTABLE}" describe
+            OUTPUT_VARIABLE GIT_DESCRIBE_REVISION
+            RESULT_VARIABLE GIT_CALL_RESULT
+            OUTPUT_STRIP_TRAILING_WHITESPACE
+        )
+        if(GIT_CALL_RESULT EQUAL 0)
+            set(REVISION "${GIT_DESCRIBE_REVISION}")
         endif()
     endif()
 endif()