1 #detect Mercurial revision and init rev/hash information |
1 #detect Mercurial revision and init rev/hash information |
2 find_program(HGCOMMAND hg) |
2 find_program(HGCOMMAND hg) |
3 if(HGCOMMAND AND (EXISTS ${CMAKE_SOURCE_DIR}/.hg)) |
3 find_program(GITCOMMAND git) |
|
4 if(EXISTS ${CMAKE_SOURCE_DIR}/.hg AND HGCOMMAND) |
4 execute_process(COMMAND ${HGCOMMAND} identify -in |
5 execute_process(COMMAND ${HGCOMMAND} identify -in |
5 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
6 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
6 OUTPUT_VARIABLE internal_version |
7 OUTPUT_VARIABLE internal_version |
7 ERROR_QUIET |
8 ERROR_QUIET |
8 ) |
9 ) |
9 #check local repo status |
10 #check local repo status |
10 string(REGEX REPLACE "[^+]" "" HGCHANGED ${internal_version}) |
11 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]+)(.*)" "\\2" HEDGEWARS_REVISION ${internal_version}) |
12 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}) |
13 |
14 |
14 if(HGCHANGED) |
15 if(HGCHANGED) |
15 message("*** You have uncommitted changes in your repository ***") |
16 message("*** You have uncommitted changes in your repository ***") |
16 endif() |
17 endif() |
|
18 |
17 #let's assume that if you have hg you might be interested in debugging |
19 #let's assume that if you have hg you might be interested in debugging |
18 set(default_build_type "DEBUG") |
20 set(default_build_type "DEBUG") |
|
21 |
|
22 #write down hash and rev for easy picking should hg be missing |
|
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) |
|
25 execute_process(COMMAND ${GITCOMMAND} rev-parse --short HEAD |
|
26 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
|
27 OUTPUT_VARIABLE HEDGEWARS_HASH |
|
28 ERROR_QUIET |
|
29 ) |
|
30 set(HEDGEWARS_REVISION "git") |
|
31 |
|
32 #let's assume that if you have git you might be interested in debugging |
|
33 set(default_build_type "DEBUG") |
|
34 |
19 #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 |
20 file(WRITE "${CMAKE_SOURCE_DIR}/share/version_info.txt" "Hedgewars versioning information, do not modify\nrev ${HEDGEWARS_REVISION}\nhash ${HEDGEWARS_HASH}\n") |
36 file(WRITE "${CMAKE_SOURCE_DIR}/share/version_info.txt" "Hedgewars versioning information, do not modify\nrev ${HEDGEWARS_REVISION}\nhash ${HEDGEWARS_HASH}\n") |
21 else() |
37 else() |
22 set(default_build_type "RELEASE") |
38 set(default_build_type "RELEASE") |
23 # 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 |
24 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) |
25 if(version_info) |
41 if(version_info) |
26 file(STRINGS ${version_info} internal_version REGEX "rev") |
42 file(STRINGS ${version_info} internal_version REGEX "rev") |
27 string(REGEX REPLACE "rev ([0-9]*)" "\\1" HEDGEWARS_REVISION ${internal_version}) |
43 string(REGEX REPLACE "rev ([git0-9]*)" "\\1" HEDGEWARS_REVISION ${internal_version}) |
28 file(STRINGS ${version_info} internal_version REGEX "hash") |
44 file(STRINGS ${version_info} internal_version REGEX "hash") |
29 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}) |
30 else() |
46 else() |
31 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 " |
32 "will be incorrect!!! Contact your source provider to fix this!") |
48 "will be incorrect!!! Contact your source provider to fix this!") |