cmake_modules/revinfo.cmake
author Wuzzy <Wuzzy2@mail.ru>
Fri, 09 Mar 2018 19:05:59 +0100
changeset 13145 5083fb0a2992
parent 10025 ec966363adbe
child 15474 6e09555b25b4
permissions -rw-r--r--
A Classic Fairytale: Harden all missions against missing campaign variables in team file and assume default values This assumes the worst case in which the team file is missing all campaign variables except Progress. This has been successfully tested with all 10 missions and still generates a logical storyline. By default, the game assumes: - The cyborg's offer in mission 2 was refused - The traitor in mission 5 was killed As a consequence, missions 8 and 10 use the princessScene cut scene.
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)
9933
792ce11d1927 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
     3
find_program(GITCOMMAND git)
10025
ec966363adbe new cmake option NOVERSIONINFOUPDATE -- to be used if source is in a git/repo that is NOT the hedgewars repo
sheepluva
parents: 9937
diff changeset
     4
if(EXISTS ${CMAKE_SOURCE_DIR}/.hg AND HGCOMMAND AND NOT NOVERSIONINFOUPDATE)
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
9937
948f48b29360 fix git hash reporting
koda
parents: 9933
diff changeset
     8
                    ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
9933
792ce11d1927 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()
9933
792ce11d1927 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")
9933
792ce11d1927 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    21
792ce11d1927 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
792ce11d1927 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")
10025
ec966363adbe new cmake option NOVERSIONINFOUPDATE -- to be used if source is in a git/repo that is NOT the hedgewars repo
sheepluva
parents: 9937
diff changeset
    24
elseif(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GITCOMMAND AND NOT NOVERSIONINFOUPDATE)
9933
792ce11d1927 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    25
    execute_process(COMMAND ${GITCOMMAND} rev-parse --short HEAD
792ce11d1927 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    26
                    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
792ce11d1927 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    27
                    OUTPUT_VARIABLE HEDGEWARS_HASH
9937
948f48b29360 fix git hash reporting
koda
parents: 9933
diff changeset
    28
                    ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
9933
792ce11d1927 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    29
                    )
9937
948f48b29360 fix git hash reporting
koda
parents: 9933
diff changeset
    30
    set(HEDGEWARS_REVISION "GIT")
9933
792ce11d1927 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    31
792ce11d1927 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
792ce11d1927 have revinfo also try to pick up git hashes
koda
parents: 9151
diff changeset
    33
    set(default_build_type "DEBUG")
792ce11d1927 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")
9937
948f48b29360 fix git hash reporting
koda
parents: 9933
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