|
1 # |
|
2 # CMake build script to determine project version number. |
|
3 # |
|
4 # this will set PROJECT_VERSION to a string |
|
5 # |
|
6 FUNCTION (FindProjectVersion project_path) |
|
7 # XXX: only support mercurial for now |
|
8 |
|
9 MESSAGE (STATUS "project_path=${project_path}") |
|
10 |
|
11 # first, determine tag |
|
12 EXECUTE_PROCESS ( |
|
13 COMMAND hg identify --tag |
|
14 WORKING_DIRECTORY "${project_path}" |
|
15 RESULT_VARIABLE hg_error_code |
|
16 OUTPUT_VARIABLE hg_tag |
|
17 OUTPUT_STRIP_TRAILING_WHITESPACE |
|
18 ) |
|
19 |
|
20 if (hg_error_code) |
|
21 MESSAGE (FATAL_ERROR "`hg identify --tag` failed") |
|
22 endif (hg_error_code) |
|
23 |
|
24 # if tag is other than tip, use that |
|
25 if ("${hg_tag}" STREQUAL "tip") |
|
26 # use the revision hash |
|
27 EXECUTE_PROCESS ( |
|
28 COMMAND hg identify --id |
|
29 WORKING_DIRECTORY "${project_path}" |
|
30 RESULT_VARIABLE hg_error_code |
|
31 OUTPUT_VARIABLE hg_id |
|
32 OUTPUT_STRIP_TRAILING_WHITESPACE |
|
33 ) |
|
34 |
|
35 if (hg_error_code) |
|
36 MESSAGE (FATAL_ERROR "`hg identify --id` failed") |
|
37 endif (hg_error_code) |
|
38 |
|
39 SET (PROJECT_VERSION "${hg_id}" PARENT_SCOPE) |
|
40 MESSAGE (STATUS "Version: mercurial tip id: ${hg_id}") |
|
41 |
|
42 else ("${hg_tag}" STREQUAL "tip") |
|
43 SET (PROJECT_VERSION "${hg_tag}" PARENT_SCOPE) |
|
44 MESSAGE (STATUS "Version: mercurial tag: ${hg_tag}") |
|
45 |
|
46 endif ("${hg_tag}" STREQUAL "tip") |
|
47 |
|
48 ENDFUNCTION (FindProjectVersion) |