cmake_modules/revinfo.cmake
changeset 9150 79c58ff0d4b1
child 9151 1d2df388fcc6
equal deleted inserted replaced
9149:6790f1938cd9 9150:79c58ff0d4b1
       
     1 #detect Mercurial revision and init rev/hash information
       
     2 find_program(HGCOMMAND hg)
       
     3 if(HGCOMMAND AND (EXISTS ${CMAKE_SOURCE_DIR}/.hg))
       
     4     execute_process(COMMAND ${HGCOMMAND} identify -in
       
     5                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
       
     6                     OUTPUT_VARIABLE internal_version
       
     7                     ERROR_QUIET
       
     8                 )
       
     9     #check local repo status
       
    10     string(REGEX REPLACE "[^+]" "" HGCHANGED ${internal_version})
       
    11     string(REGEX REPLACE "[0-9a-zA-Z]+(.*) ([0-9]+)(.*)" "\\2" HEDGEWARS_REVISION ${internal_version})
       
    12     string(REGEX REPLACE "([0-9a-zA-Z]+)(.*) [0-9]+(.*)" "\\1" HEDGEWARS_HASH ${internal_version})
       
    13 
       
    14     if(HGCHANGED)
       
    15         message(${WARNING} "You have uncommitted changes in your repository!")
       
    16     endif()
       
    17     #let's assume that if you have hg you might be interested in debugging
       
    18     set(default_build_type "DEBUG")
       
    19     #write down hash and rev for easy picking should hg be missing
       
    20     file(WRITE "${CMAKE_SOURCE_DIR}/share/version_info.txt" "Hedgewars versioning information, do not modify\nrev ${HEDGEWARS_REVISION}\nhash ${HEDGEWARS_HASH}\n")
       
    21 else()
       
    22     set(default_build_type "RELEASE")
       
    23     # when compiling outside rev control, fetch revision and hash information from version_info.txt
       
    24     find_file(version_info version_info.txt PATH ${CMAKE_SOURCE_DIR}/share)
       
    25     if(version_info)
       
    26         file(STRINGS ${version_info} internal_version REGEX "rev")
       
    27         string(REGEX REPLACE "rev ([0-9]*)" "\\1" HEDGEWARS_REVISION ${internal_version})
       
    28         file(STRINGS ${version_info} internal_version REGEX "hash")
       
    29         string(REGEX REPLACE "hash ([a-zA-Z0-9]*)" "\\1" HEDGEWARS_HASH ${internal_version})
       
    30     else()
       
    31         message(${WARNING} "${CMAKE_SOURCE_DIR}/share/version_info.txt not found, revision information "
       
    32                            "will be incorrect!!! Contact your source provider to fix this!")
       
    33         set(HEDGEWARS_REVISION "0000")
       
    34         set(HEDGEWARS_HASH "unknown")
       
    35     endif()
       
    36 endif()
       
    37 
       
    38