have revinfo also try to pick up git hashes
authorkoda
Fri, 03 Jan 2014 17:14:19 +0100
changeset 9933 792ce11d1927
parent 9931 409d991a59e8
child 9935 491f661a4e57
have revinfo also try to pick up git hashes
cmake_modules/revinfo.cmake
--- a/cmake_modules/revinfo.cmake	Fri Jan 03 07:50:42 2014 -0800
+++ b/cmake_modules/revinfo.cmake	Fri Jan 03 17:14:19 2014 +0100
@@ -1,11 +1,12 @@
 #detect Mercurial revision and init rev/hash information
 find_program(HGCOMMAND hg)
-if(HGCOMMAND AND (EXISTS ${CMAKE_SOURCE_DIR}/.hg))
+find_program(GITCOMMAND git)
+if(EXISTS ${CMAKE_SOURCE_DIR}/.hg AND HGCOMMAND)
     execute_process(COMMAND ${HGCOMMAND} identify -in
                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
                     OUTPUT_VARIABLE internal_version
                     ERROR_QUIET
-                )
+                    )
     #check local repo status
     string(REGEX REPLACE "[^+]" "" HGCHANGED ${internal_version})
     string(REGEX REPLACE "[0-9a-zA-Z]+(.*) ([0-9]+)(.*)" "\\2" HEDGEWARS_REVISION ${internal_version})
@@ -14,8 +15,23 @@
     if(HGCHANGED)
         message("*** You have uncommitted changes in your repository ***")
     endif()
+
     #let's assume that if you have hg you might be interested in debugging
     set(default_build_type "DEBUG")
+
+    #write down hash and rev for easy picking should hg be missing
+    file(WRITE "${CMAKE_SOURCE_DIR}/share/version_info.txt" "Hedgewars versioning information, do not modify\nrev ${HEDGEWARS_REVISION}\nhash ${HEDGEWARS_HASH}\n")
+elseif(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GITCOMMAND)
+    execute_process(COMMAND ${GITCOMMAND} rev-parse --short HEAD
+                    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+                    OUTPUT_VARIABLE HEDGEWARS_HASH
+                    ERROR_QUIET
+                    )
+    set(HEDGEWARS_REVISION "git")
+
+    #let's assume that if you have git you might be interested in debugging
+    set(default_build_type "DEBUG")
+
     #write down hash and rev for easy picking should hg be missing
     file(WRITE "${CMAKE_SOURCE_DIR}/share/version_info.txt" "Hedgewars versioning information, do not modify\nrev ${HEDGEWARS_REVISION}\nhash ${HEDGEWARS_HASH}\n")
 else()
@@ -24,7 +40,7 @@
     find_file(version_info version_info.txt PATH ${CMAKE_SOURCE_DIR}/share)
     if(version_info)
         file(STRINGS ${version_info} internal_version REGEX "rev")
-        string(REGEX REPLACE "rev ([0-9]*)" "\\1" HEDGEWARS_REVISION ${internal_version})
+        string(REGEX REPLACE "rev ([git0-9]*)" "\\1" HEDGEWARS_REVISION ${internal_version})
         file(STRINGS ${version_info} internal_version REGEX "hash")
         string(REGEX REPLACE "hash ([a-zA-Z0-9]*)" "\\1" HEDGEWARS_HASH ${internal_version})
     else()