1 # - Extract information from a subversion working copy
\r
2 # The module defines the following variables:
\r
3 # Mercurial_HG_EXECUTABLE - path to hg command line client
\r
4 # Mercurial_VERSION_HG - version of hg command line client
\r
5 # Mercurial_FOUND - true if the command line client was found
\r
6 # MERCURIAL_FOUND - same as Mercurial_FOUND, set for compatiblity reasons
\r
8 # The minimum required version of Mercurial can be specified using the
\r
9 # standard syntax, e.g. FIND_PACKAGE(Mercurial 1.4)
\r
11 # If the command line client executable is found two macros are defined:
\r
12 # Mercurial_WC_INFO(<dir> <var-prefix>)
\r
13 # Mercurial_WC_LOG(<dir> <var-prefix>)
\r
14 # Mercurial_WC_INFO extracts information of a subversion working copy at
\r
15 # a given location. This macro defines the following variables:
\r
16 # <var-prefix>_WC_URL - url of the repository (at <dir>)
\r
17 # <var-prefix>_WC_ROOT - root url of the repository
\r
18 # <var-prefix>_WC_REVISION - current revision
\r
19 # <var-prefix>_WC_LAST_CHANGED_AUTHOR - author of last commit
\r
20 # <var-prefix>_WC_LAST_CHANGED_DATE - date of last commit
\r
21 # <var-prefix>_WC_LAST_CHANGED_REV - revision of last commit
\r
22 # <var-prefix>_WC_INFO - output of command `hg info <dir>'
\r
23 # Mercurial_WC_LOG retrieves the log message of the base revision of a
\r
24 # subversion working copy at a given location. This macro defines the
\r
26 # <var-prefix>_LAST_CHANGED_LOG - last log of base revision
\r
28 # FIND_PACKAGE(Mercurial)
\r
29 # IF(MERCURIAL_FOUND)
\r
30 # Mercurial_WC_INFO(${PROJECT_SOURCE_DIR} Project)
\r
31 # MESSAGE("Current revision is ${Project_WC_REVISION}")
\r
32 # Mercurial_WC_LOG(${PROJECT_SOURCE_DIR} Project)
\r
33 # MESSAGE("Last changed log is ${Project_LAST_CHANGED_LOG}")
\r
36 #=============================================================================
\r
37 # Copyright 2006-2009 Kitware, Inc.
\r
38 # Copyright 2006 Tristan Carel
\r
40 # Distributed under the OSI-approved BSD License (the "License");
\r
41 # see accompanying file Copyright.txt for details.
\r
43 # This software is distributed WITHOUT ANY WARRANTY; without even the
\r
44 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
\r
45 # See the License for more information.
\r
46 #=============================================================================
\r
47 # (To distribute this file outside of CMake, substitute the full
\r
48 # License text for the above reference.)
\r
50 FIND_PROGRAM(Mercurial_HG_EXECUTABLE hg
\r
51 DOC "mercurial command line client"
\r
54 "C:/Program Files/TortoiseHg"
\r
55 "C:/Program Files (x86)/TortoiseHg"
\r
57 MARK_AS_ADVANCED(Mercurial_HG_EXECUTABLE)
\r
59 IF(Mercurial_HG_EXECUTABLE)
\r
60 EXECUTE_PROCESS(COMMAND ${Mercurial_HG_EXECUTABLE} --version
\r
61 OUTPUT_VARIABLE Mercurial_VERSION_HG
\r
62 OUTPUT_STRIP_TRAILING_WHITESPACE)
\r
64 STRING(REGEX REPLACE ".*version ([\\.0-9]+).*"
\r
65 "\\1" Mercurial_VERSION_HG "${Mercurial_VERSION_HG}")
\r
67 MACRO(Mercurial_WC_INFO dir prefix)
\r
68 EXECUTE_PROCESS(COMMAND ${Mercurial_HG_EXECUTABLE} log -r . --template "{rev};{node};{tags};{author}"
\r
69 WORKING_DIRECTORY ${dir}
\r
70 OUTPUT_VARIABLE ${prefix}_WC_INFO
\r
71 ERROR_VARIABLE Mercurial_hg_info_error
\r
72 RESULT_VARIABLE Mercurial_hg_info_result
\r
73 OUTPUT_STRIP_TRAILING_WHITESPACE)
\r
75 IF(NOT ${Mercurial_hg_info_result} EQUAL 0)
\r
76 MESSAGE(SEND_ERROR "Command \"${Mercurial_HG_EXECUTABLE} log\" failed with output:\n${Mercurial_hg_info_error}")
\r
78 LIST(LENGTH ${prefix}_WC_INFO _COUNT)
\r
80 LIST(GET ${prefix}_WC_INFO 0 ${prefix}_WC_REVISION)
\r
81 LIST(GET ${prefix}_WC_INFO 1 ${prefix}_WC_CHANGESET)
\r
82 LIST(GET ${prefix}_WC_INFO 2 ${prefix}_WC_BRANCH)
\r
83 LIST(GET ${prefix}_WC_INFO 3 ${prefix}_WC_LAST_CHANGED_AUTHOR)
\r
85 MESSAGE(STATUS "Bad output from HG")
\r
86 SET(${prefix}_WC_REVISION "unknown")
\r
87 SET(${prefix}_WC_CHANGESET "unknown")
\r
88 SET(${prefix}_WC_BRANCH "unknown")
\r
94 MACRO(Mercurial_WC_LOG dir prefix)
\r
95 # This macro can block if the certificate is not signed:
\r
96 # hg ask you to accept the certificate and wait for your answer
\r
97 # This macro requires a hg server network access (Internet most of the time)
\r
98 # and can also be slow since it access the hg server
\r
99 EXECUTE_PROCESS(COMMAND
\r
100 ${Mercurial_HG_EXECUTABLE} --non-interactive log -r BASE ${dir}
\r
101 OUTPUT_VARIABLE ${prefix}_LAST_CHANGED_LOG
\r
102 ERROR_VARIABLE Mercurial_hg_log_error
\r
103 RESULT_VARIABLE Mercurial_hg_log_result
\r
104 OUTPUT_STRIP_TRAILING_WHITESPACE)
\r
106 IF(NOT ${Mercurial_hg_log_result} EQUAL 0)
\r
107 MESSAGE(SEND_ERROR "Command \"${Mercurial_HG_EXECUTABLE} log -r BASE ${dir}\" failed with output:\n${Mercurial_hg_log_error}")
\r
112 INCLUDE(FindPackageHandleStandardArgs)
\r
113 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Mercurial DEFAULT_MSG Mercurial_HG_EXECUTABLE)
\r