Imported Upstream version 1.4+222+hg5f9f7194267b
[deb_x265.git] / source / cmake / version.cmake
CommitLineData
72b9787e
JB
1if(CMAKE_VERSION VERSION_LESS "2.8.10")
2 find_program(HG_EXECUTABLE hg)
3else()
4 find_package(Hg QUIET)
5endif()
6find_package(Git QUIET) # present in 2.8.8
7
8# defaults, in case everything below fails
b53f7c52
JB
9set(X265_VERSION "1.4+222+hg5f9f7194267b")
10set(X265_LATEST_TAG "1.4")
11set(X265_TAG_DISTANCE "222")
72b9787e
JB
12
13if(EXISTS ${CMAKE_SOURCE_DIR}/../.hg_archival.txt)
14 # read the lines of the archive summary file to extract the version
15 file(READ ${CMAKE_SOURCE_DIR}/../.hg_archival.txt archive)
16 STRING(REGEX REPLACE "\n" ";" archive "${archive}")
17 foreach(f ${archive})
18 string(FIND "${f}" ": " pos)
19 string(SUBSTRING "${f}" 0 ${pos} key)
20 string(SUBSTRING "${f}" ${pos} -1 value)
21 string(SUBSTRING "${value}" 2 -1 value)
22 set(hg_${key} ${value})
23 endforeach()
24 if(DEFINED hg_tag)
b53f7c52 25 set(X265_VERSION ${hg_tag})
72b9787e 26 set(X265_LATEST_TAG ${hg_tag})
b53f7c52 27 set(X265_TAG_DISTANCE "222")
72b9787e
JB
28 elseif(DEFINED hg_node)
29 string(SUBSTRING "${hg_node}" 0 16 hg_id)
30 set(X265_VERSION "${hg_latesttag}+${hg_latesttagdistance}-${hg_id}")
31 endif()
32elseif(HG_EXECUTABLE AND EXISTS ${CMAKE_SOURCE_DIR}/../.hg)
33 if(EXISTS "${HG_EXECUTABLE}.bat")
34 # mercurial source installs on Windows require .bat extension
35 set(HG_EXECUTABLE "${HG_EXECUTABLE}.bat")
36 endif()
37 message(STATUS "hg found at ${HG_EXECUTABLE}")
38
39 execute_process(COMMAND
40 ${HG_EXECUTABLE} log -r. --template "{latesttag}"
41 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
42 OUTPUT_VARIABLE X265_LATEST_TAG
43 ERROR_QUIET
44 OUTPUT_STRIP_TRAILING_WHITESPACE
45 )
46 execute_process(COMMAND
47 ${HG_EXECUTABLE} log -r. --template "{latesttagdistance}"
48 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
49 OUTPUT_VARIABLE X265_TAG_DISTANCE
50 ERROR_QUIET
51 OUTPUT_STRIP_TRAILING_WHITESPACE
52 )
53 execute_process(
54 COMMAND
55 ${HG_EXECUTABLE} log -r. --template "{node|short}"
56 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
57 OUTPUT_VARIABLE HG_REVISION_ID
58 ERROR_QUIET
59 OUTPUT_STRIP_TRAILING_WHITESPACE
60 )
61
62 if(X265_LATEST_TAG MATCHES "^r")
63 string(SUBSTRING ${X265_LATEST_TAG} 1 -1 X265_LATEST_TAG)
64 endif()
65 if(X265_TAG_DISTANCE STREQUAL "0")
66 set(X265_VERSION "${X265_LATEST_TAG}")
67 else()
68 set(X265_VERSION "${X265_LATEST_TAG}+${X265_TAG_DISTANCE}-${HG_REVISION_ID}")
69 endif()
70elseif(GIT_EXECUTABLE AND EXISTS ${CMAKE_SOURCE_DIR}/../.git)
71 execute_process(
72 COMMAND
73 ${GIT_EXECUTABLE} describe --tags --abbrev=0
74 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
75 OUTPUT_VARIABLE X265_LATEST_TAG
76 ERROR_QUIET
77 OUTPUT_STRIP_TRAILING_WHITESPACE
78 )
79
80 execute_process(
81 COMMAND
82 ${GIT_EXECUTABLE} describe --tags
83 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
84 OUTPUT_VARIABLE X265_VERSION
85 ERROR_QUIET
86 OUTPUT_STRIP_TRAILING_WHITESPACE
87 )
88endif()
89
90message(STATUS "x265 version ${X265_VERSION}")