summaryrefslogtreecommitdiffstats
path: root/Modules/FindHg.cmake
blob: 8aa553e792654436aacde4b2c2f8d35a182be54e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

#.rst:
# FindHg
# ------
#
# Extract information from a mercurial working copy.
#
# The module defines the following variables:
#
# ::
#
#    HG_EXECUTABLE - path to mercurial command line client (hg)
#    HG_FOUND - true if the command line client was found
#    HG_VERSION_STRING - the version of mercurial found
#
# If the command line client executable is found the following macro is defined:
#
# ::
#
#   HG_WC_INFO(<dir> <var-prefix>)
#
# Hg_WC_INFO extracts information of a mercurial working copy
# at a given location.  This macro defines the following variables:
#
# ::
#
#   <var-prefix>_WC_CHANGESET - current changeset
#   <var-prefix>_WC_REVISION - current revision
#
# Example usage:
#
# ::
#
#    find_package(Hg)
#    if(HG_FOUND)
#      message("hg found: ${HG_EXECUTABLE}")
#      HG_WC_INFO(${PROJECT_SOURCE_DIR} Project)
#      message("Current revision is ${Project_WC_REVISION}")
#      message("Current changeset is ${Project_WC_CHANGESET}")
#    endif()

find_program(HG_EXECUTABLE
  NAMES hg
  PATHS
    [HKEY_LOCAL_MACHINE\\Software\\TortoiseHG]
  PATH_SUFFIXES Mercurial
  DOC "hg command line client"
  )
mark_as_advanced(HG_EXECUTABLE)

if(HG_EXECUTABLE)
  set(_saved_lc_all "$ENV{LC_ALL}")
  set(ENV{LC_ALL} "C")

  set(_saved_language "$ENV{LANGUAGE}")
  set(ENV{LANGUAGE})

  execute_process(COMMAND ${HG_EXECUTABLE} --version
                  OUTPUT_VARIABLE hg_version
                  ERROR_QUIET
                  RESULT_VARIABLE hg_result
                  OUTPUT_STRIP_TRAILING_WHITESPACE)

  set(ENV{LC_ALL} ${_saved_lc_all})
  set(ENV{LANGUAGE} ${_saved_language})

  if(hg_result MATCHES "is not a valid Win32 application")
    set_property(CACHE HG_EXECUTABLE PROPERTY VALUE "HG_EXECUTABLE-NOTFOUND")
  endif()
  if(hg_version MATCHES "^Mercurial Distributed SCM \\(version ([0-9][^)]*)\\)")
    set(HG_VERSION_STRING "${CMAKE_MATCH_1}")
  endif()
  unset(hg_version)

  macro(HG_WC_INFO dir prefix)
    execute_process(COMMAND ${HG_EXECUTABLE} id -i -n
      WORKING_DIRECTORY ${dir}
      RESULT_VARIABLE hg_id_result
      ERROR_VARIABLE hg_id_error
      OUTPUT_VARIABLE ${prefix}_WC_DATA
      OUTPUT_STRIP_TRAILING_WHITESPACE)
    if(NOT ${hg_id_result} EQUAL 0)
      message(SEND_ERROR "Command \"${HG_EXECUTBALE} id -n\" in directory ${dir} failed with output:\n${hg_id_error}")
    endif()

    string(REGEX REPLACE "([0-9a-f]+)\\+? [0-9]+\\+?" "\\1" ${prefix}_WC_CHANGESET ${${prefix}_WC_DATA})
    string(REGEX REPLACE "[0-9a-f]+\\+? ([0-9]+)\\+?" "\\1" ${prefix}_WC_REVISION ${${prefix}_WC_DATA})
  endmacro(HG_WC_INFO)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(Hg
                                  REQUIRED_VARS HG_EXECUTABLE
                                  VERSION_VAR HG_VERSION_STRING)
d>12-69/+84 * [svn-r11179] Purpose:James Laird2005-08-0111-65/+132 * [svn-r11144] Purpose:Quincey Koziol2005-07-231-1/+1 * [svn-r11115] Purpose:Fang Guo2005-07-222-3/+603 * [svn-r11114] Purpose:Fang Guo2005-07-221-0/+96 * [svn-r11113] Purpose:Fang Guo2005-07-221-3/+3 * [svn-r11112] Purpose:Fang Guo2005-07-222-32/+32 * [svn-r11111] Purpose:Fang Guo2005-07-221-53/+53 * [svn-r11110] Purpose:Fang Guo2005-07-221-13/+13 * [svn-r11109] Purpose:Fang Guo2005-07-221-12/+12 * [svn-r11095] Purpose:James Laird2005-07-2110-150/+529 * [svn-r11092] Purpose:MuQun Yang2005-07-201-1/+1 * [svn-r11091] Purpose:Pedro Vicente Nunes2005-07-202-21/+21 * [svn-r11042] Purpose:Quincey Koziol2005-07-0710-70/+70 * [svn-r11034] Purpose:Albert Cheng2005-07-0710-40/+20 * [svn-r11013] Purpose:James Laird2005-07-0110-70/+70 * [svn-r11008] Purpose:James Laird2005-06-3012-880/+816 * [svn-r10997] Purpose: Small bug fixElena Pourmal2005-06-282-2/+2 * [svn-r10986] Purpose: MaintenanceElena Pourmal2005-06-242-130/+130 * [svn-r10984] Elena Pourmal2005-06-241-1/+1 * [svn-r10977] Purpose: Bug fixElena Pourmal2005-06-2411-466/+522 * [svn-r10970] Purpose: New feature/bug #350 fixElena Pourmal2005-06-229-55/+209 * [svn-r10858] Purpose:Albert Cheng2005-06-0410-40/+150 * [svn-r10849] Purpose:Albert Cheng2005-06-0210-10/+30 * [svn-r10840] Purpose:James Laird2005-06-0210-60/+360 * [svn-r10801] Purpose:James Laird2005-05-251-1/+1 * [svn-r10748] Purpose:Pedro Vicente Nunes2005-05-161-2/+0 * [svn-r10747] Purpose:Pedro Vicente Nunes2005-05-1613-1186/+1742 * [svn-r10736] Purpose:Quincey Koziol2005-05-074-19/+5 * [svn-r10729] Purpose:James Laird2005-05-051-6/+7 * [svn-r10706] Purpose:MuQun Yang2005-05-021-0/+1 * [svn-r10668] Purpose:James Laird2005-04-261-221/+0 * [svn-r10667] Purpose:James Laird2005-04-262-2/+5 * [svn-r10628] Purpose:Quincey Koziol2005-04-18