cmake_modules/revinfo.cmake
changeset 9937 948f48b29360
parent 9933 792ce11d1927
child 10025 ec966363adbe
equal deleted inserted replaced
9936:a9fe8db625d0 9937:948f48b29360
     3 find_program(GITCOMMAND git)
     3 find_program(GITCOMMAND git)
     4 if(EXISTS ${CMAKE_SOURCE_DIR}/.hg AND HGCOMMAND)
     4 if(EXISTS ${CMAKE_SOURCE_DIR}/.hg AND HGCOMMAND)
     5     execute_process(COMMAND ${HGCOMMAND} identify -in
     5     execute_process(COMMAND ${HGCOMMAND} identify -in
     6                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
     6                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
     7                     OUTPUT_VARIABLE internal_version
     7                     OUTPUT_VARIABLE internal_version
     8                     ERROR_QUIET
     8                     ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
     9                     )
     9                     )
    10     #check local repo status
    10     #check local repo status
    11     string(REGEX REPLACE "[^+]" "" HGCHANGED ${internal_version})
    11     string(REGEX REPLACE "[^+]" "" HGCHANGED ${internal_version})
    12     string(REGEX REPLACE "[0-9a-zA-Z]+(.*) ([0-9]+)(.*)" "\\2" HEDGEWARS_REVISION ${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})
    13     string(REGEX REPLACE "([0-9a-zA-Z]+)(.*) [0-9]+(.*)" "\\1" HEDGEWARS_HASH ${internal_version})
    23     file(WRITE "${CMAKE_SOURCE_DIR}/share/version_info.txt" "Hedgewars versioning information, do not modify\nrev ${HEDGEWARS_REVISION}\nhash ${HEDGEWARS_HASH}\n")
    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)
    24 elseif(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GITCOMMAND)
    25     execute_process(COMMAND ${GITCOMMAND} rev-parse --short HEAD
    25     execute_process(COMMAND ${GITCOMMAND} rev-parse --short HEAD
    26                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    26                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    27                     OUTPUT_VARIABLE HEDGEWARS_HASH
    27                     OUTPUT_VARIABLE HEDGEWARS_HASH
    28                     ERROR_QUIET
    28                     ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
    29                     )
    29                     )
    30     set(HEDGEWARS_REVISION "git")
    30     set(HEDGEWARS_REVISION "GIT")
    31 
    31 
    32     #let's assume that if you have git you might be interested in debugging
    32     #let's assume that if you have git you might be interested in debugging
    33     set(default_build_type "DEBUG")
    33     set(default_build_type "DEBUG")
    34 
    34 
    35     #write down hash and rev for easy picking should hg be missing
    35     #write down hash and rev for easy picking should hg be missing
    38     set(default_build_type "RELEASE")
    38     set(default_build_type "RELEASE")
    39     # when compiling outside rev control, fetch revision and hash information from version_info.txt
    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)
    40     find_file(version_info version_info.txt PATH ${CMAKE_SOURCE_DIR}/share)
    41     if(version_info)
    41     if(version_info)
    42         file(STRINGS ${version_info} internal_version REGEX "rev")
    42         file(STRINGS ${version_info} internal_version REGEX "rev")
    43         string(REGEX REPLACE "rev ([git0-9]*)" "\\1" HEDGEWARS_REVISION ${internal_version})
    43         string(REGEX REPLACE "rev ([GIT0-9]*)" "\\1" HEDGEWARS_REVISION ${internal_version})
    44         file(STRINGS ${version_info} internal_version REGEX "hash")
    44         file(STRINGS ${version_info} internal_version REGEX "hash")
    45         string(REGEX REPLACE "hash ([a-zA-Z0-9]*)" "\\1" HEDGEWARS_HASH ${internal_version})
    45         string(REGEX REPLACE "hash ([a-zA-Z0-9]*)" "\\1" HEDGEWARS_HASH ${internal_version})
    46     else()
    46     else()
    47         message(WARNING "${CMAKE_SOURCE_DIR}/share/version_info.txt not found, revision information "
    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!")
    48                         "will be incorrect!!! Contact your source provider to fix this!")