cmake_modules/revinfo.cmake
author Periklis Ntanasis <pntanasis@gmail.com>
Thu, 12 Sep 2013 03:19:31 +0300
branchspacecampaign
changeset 9614 7fa70d381c75
parent 9151 1d2df388fcc6
child 9905 ec0d9f737449
permissions -rw-r--r--
added custom stats
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     1
#detect Mercurial revision and init rev/hash information
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     2
find_program(HGCOMMAND hg)
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     3
if(HGCOMMAND AND (EXISTS ${CMAKE_SOURCE_DIR}/.hg))
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     4
    execute_process(COMMAND ${HGCOMMAND} identify -in
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     5
                    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     6
                    OUTPUT_VARIABLE internal_version
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     7
                    ERROR_QUIET
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     8
                )
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     9
    #check local repo status
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    10
    string(REGEX REPLACE "[^+]" "" HGCHANGED ${internal_version})
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    11
    string(REGEX REPLACE "[0-9a-zA-Z]+(.*) ([0-9]+)(.*)" "\\2" HEDGEWARS_REVISION ${internal_version})
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    12
    string(REGEX REPLACE "([0-9a-zA-Z]+)(.*) [0-9]+(.*)" "\\1" HEDGEWARS_HASH ${internal_version})
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    13
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    14
    if(HGCHANGED)
9151
1d2df388fcc6 simplify cmake message syntax a little bit
koda
parents: 9150
diff changeset
    15
        message("*** You have uncommitted changes in your repository ***")
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    16
    endif()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    17
    #let's assume that if you have hg you might be interested in debugging
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    18
    set(default_build_type "DEBUG")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    19
    #write down hash and rev for easy picking should hg be missing
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    20
    file(WRITE "${CMAKE_SOURCE_DIR}/share/version_info.txt" "Hedgewars versioning information, do not modify\nrev ${HEDGEWARS_REVISION}\nhash ${HEDGEWARS_HASH}\n")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    21
else()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    22
    set(default_build_type "RELEASE")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    23
    # when compiling outside rev control, fetch revision and hash information from version_info.txt
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    24
    find_file(version_info version_info.txt PATH ${CMAKE_SOURCE_DIR}/share)
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    25
    if(version_info)
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    26
        file(STRINGS ${version_info} internal_version REGEX "rev")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    27
        string(REGEX REPLACE "rev ([0-9]*)" "\\1" HEDGEWARS_REVISION ${internal_version})
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    28
        file(STRINGS ${version_info} internal_version REGEX "hash")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    29
        string(REGEX REPLACE "hash ([a-zA-Z0-9]*)" "\\1" HEDGEWARS_HASH ${internal_version})
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    30
    else()
9151
1d2df388fcc6 simplify cmake message syntax a little bit
koda
parents: 9150
diff changeset
    31
        message(WARNING "${CMAKE_SOURCE_DIR}/share/version_info.txt not found, revision information "
1d2df388fcc6 simplify cmake message syntax a little bit
koda
parents: 9150
diff changeset
    32
                        "will be incorrect!!! Contact your source provider to fix this!")
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    33
        set(HEDGEWARS_REVISION "0000")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    34
        set(HEDGEWARS_HASH "unknown")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    35
    endif()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    36
endif()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    37
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    38