cmake_modules/revinfo.cmake
author koda
Sat, 04 Jan 2014 02:18:57 +0100
branch0.9.20
changeset 9905 ec0d9f737449
parent 9151 1d2df388fcc6
child 9907 129614d78ae8
permissions -rw-r--r--
have revinfo also try to pick up git hashes
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)
9905
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
     3
find_program(GITCOMMAND git)
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
     4
if(EXISTS ${CMAKE_SOURCE_DIR}/.hg AND HGCOMMAND)
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     5
    execute_process(COMMAND ${HGCOMMAND} identify -in
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     6
                    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     7
                    OUTPUT_VARIABLE internal_version
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
     8
                    ERROR_QUIET
9905
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
     9
                    )
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    10
    #check local repo status
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    11
    string(REGEX REPLACE "[^+]" "" HGCHANGED ${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]+)(.*)" "\\2" HEDGEWARS_REVISION ${internal_version})
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    13
    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
    14
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    15
    if(HGCHANGED)
9151
1d2df388fcc6 simplify cmake message syntax a little bit
koda
parents: 9150
diff changeset
    16
        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
    17
    endif()
9905
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    18
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    19
    #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
    20
    set(default_build_type "DEBUG")
9905
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    21
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    22
    #write down hash and rev for easy picking should hg be missing
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    23
    file(WRITE "${CMAKE_SOURCE_DIR}/share/version_info.txt" "Hedgewars versioning information, do not modify\nrev ${HEDGEWARS_REVISION}\nhash ${HEDGEWARS_HASH}\n")
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    24
elseif(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GITCOMMAND)
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    25
    execute_process(COMMAND ${GITCOMMAND} rev-parse --short HEAD
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    26
                    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    27
                    OUTPUT_VARIABLE HEDGEWARS_HASH
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    28
                    ERROR_QUIET
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    29
                    )
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    30
    set(HEDGEWARS_REVISION "git")
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    31
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    32
    #let's assume that if you have git you might be interested in debugging
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    33
    set(default_build_type "DEBUG")
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    34
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    35
    #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
    36
    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
    37
else()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    38
    set(default_build_type "RELEASE")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    39
    # 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
    40
    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
    41
    if(version_info)
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    42
        file(STRINGS ${version_info} internal_version REGEX "rev")
9905
ec0d9f737449 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    43
        string(REGEX REPLACE "rev ([git0-9]*)" "\\1" HEDGEWARS_REVISION ${internal_version})
9150
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    44
        file(STRINGS ${version_info} internal_version REGEX "hash")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    45
        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
    46
    else()
9151
1d2df388fcc6 simplify cmake message syntax a little bit
koda
parents: 9150
diff changeset
    47
        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
    48
                        "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
    49
        set(HEDGEWARS_REVISION "0000")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    50
        set(HEDGEWARS_HASH "unknown")
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    51
    endif()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    52
endif()
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    53
79c58ff0d4b1 move platform specific and revision info code into separate cmake modules
koda
parents:
diff changeset
    54