cmake_modules/revinfo.cmake
branchhedgeroid
changeset 15515 7030706266df
parent 15454 6e09555b25b4
equal deleted inserted replaced
7861:bc7b6aa5d67a 15515:7030706266df
       
     1 #detect Mercurial revision and init rev/hash information
       
     2 find_program(HGCOMMAND hg)
       
     3 find_program(GITCOMMAND git)
       
     4 if(EXISTS ${CMAKE_SOURCE_DIR}/.hg AND HGCOMMAND AND NOT NOVERSIONINFOUPDATE)
       
     5     execute_process(COMMAND ${HGCOMMAND} identify -in
       
     6                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
       
     7                     OUTPUT_VARIABLE internal_version
       
     8                     ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
       
     9                     )
       
    10     #check local repo status
       
    11     string(REGEX REPLACE "[^+]" "" HGCHANGED ${internal_version})
       
    12     string(REGEX REPLACE "[0-9a-zA-Z]+(.*) ([0-9]+)(.*)" "\\2" HEDGEWARS_REVISION ${internal_version})
       
    13     string(REGEX REPLACE "([0-9a-zA-Z]+)(.*) [0-9]+(.*)" "\\1" HEDGEWARS_HASH ${internal_version})
       
    14 
       
    15     if(HGCHANGED)
       
    16         message("*** You have uncommitted changes in your repository ***")
       
    17     endif()
       
    18 
       
    19     #let's assume that if you have hg you might be interested in debugging
       
    20     set(default_build_type "Debug")
       
    21 
       
    22     #write down hash and rev for easy picking should hg be missing
       
    23     file(WRITE "${CMAKE_SOURCE_DIR}/share/version_info.txt" "Hedgewars versioning information, do not modify\nrev ${HEDGEWARS_REVISION}\nhash ${HEDGEWARS_HASH}\n")
       
    24 elseif(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GITCOMMAND AND NOT NOVERSIONINFOUPDATE)
       
    25     execute_process(COMMAND ${GITCOMMAND} rev-parse --short HEAD
       
    26                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
       
    27                     OUTPUT_VARIABLE HEDGEWARS_HASH
       
    28                     ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
       
    29                     )
       
    30     set(HEDGEWARS_REVISION "GIT")
       
    31 
       
    32     #let's assume that if you have git you might be interested in debugging
       
    33     set(default_build_type "Debug")
       
    34 
       
    35     #write down hash and rev for easy picking should hg be missing
       
    36     file(WRITE "${CMAKE_SOURCE_DIR}/share/version_info.txt" "Hedgewars versioning information, do not modify\nrev ${HEDGEWARS_REVISION}\nhash ${HEDGEWARS_HASH}\n")
       
    37 else()
       
    38     set(default_build_type "Release")
       
    39     # when compiling outside rev control, fetch revision and hash information from version_info.txt
       
    40     find_file(version_info version_info.txt PATH ${CMAKE_SOURCE_DIR}/share)
       
    41     if(version_info)
       
    42         file(STRINGS ${version_info} internal_version REGEX "rev")
       
    43         string(REGEX REPLACE "rev ([GIT0-9]*)" "\\1" HEDGEWARS_REVISION ${internal_version})
       
    44         file(STRINGS ${version_info} internal_version REGEX "hash")
       
    45         string(REGEX REPLACE "hash ([a-zA-Z0-9]*)" "\\1" HEDGEWARS_HASH ${internal_version})
       
    46     else()
       
    47         message(WARNING "${CMAKE_SOURCE_DIR}/share/version_info.txt not found, revision information "
       
    48                         "will be incorrect!!! Contact your source provider to fix this!")
       
    49         set(HEDGEWARS_REVISION "0000")
       
    50         set(HEDGEWARS_HASH "unknown")
       
    51     endif()
       
    52 endif()
       
    53 
       
    54