2013-10-15 19:17:36 +04:00
|
|
|
#.rst:
|
|
|
|
# FindHg
|
|
|
|
# ------
|
|
|
|
#
|
2014-02-22 22:46:48 +04:00
|
|
|
# Extract information from a mercurial working copy.
|
2013-10-15 19:17:36 +04:00
|
|
|
#
|
2012-08-14 18:41:17 +04:00
|
|
|
# The module defines the following variables:
|
2013-10-15 19:17:36 +04:00
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
2014-02-22 22:46:48 +04:00
|
|
|
# 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
|
|
|
|
#
|
2012-08-14 18:41:17 +04:00
|
|
|
# Example usage:
|
2013-10-15 19:17:36 +04:00
|
|
|
#
|
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# find_package(Hg)
|
|
|
|
# if(HG_FOUND)
|
|
|
|
# message("hg found: ${HG_EXECUTABLE}")
|
2014-02-22 22:46:48 +04:00
|
|
|
# HG_WC_INFO(${PROJECT_SOURCE_DIR} Project)
|
|
|
|
# message("Current revision is ${Project_WC_REVISION}")
|
|
|
|
# message("Current changeset is ${Project_WC_CHANGESET}")
|
2013-10-15 19:17:36 +04:00
|
|
|
# endif()
|
2012-08-14 18:41:17 +04:00
|
|
|
|
|
|
|
#=============================================================================
|
|
|
|
# Copyright 2010-2012 Kitware, Inc.
|
|
|
|
# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
|
2014-02-22 22:46:48 +04:00
|
|
|
# Copyright 2014 Matthaeus G. Chajdas
|
2012-08-14 18:41:17 +04:00
|
|
|
#
|
|
|
|
# Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
# see accompanying file Copyright.txt for details.
|
|
|
|
#
|
|
|
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
# See the License for more information.
|
|
|
|
#=============================================================================
|
|
|
|
# (To distribute this file outside of CMake, substitute the full
|
|
|
|
# License text for the above reference.)
|
|
|
|
|
|
|
|
find_program(HG_EXECUTABLE
|
|
|
|
NAMES hg
|
2014-02-22 22:46:48 +04:00
|
|
|
PATHS
|
|
|
|
[HKEY_LOCAL_MACHINE\\Software\\TortoiseHG]
|
2012-08-14 18:41:17 +04:00
|
|
|
PATH_SUFFIXES Mercurial
|
|
|
|
DOC "hg command line client"
|
|
|
|
)
|
|
|
|
mark_as_advanced(HG_EXECUTABLE)
|
|
|
|
|
|
|
|
if(HG_EXECUTABLE)
|
|
|
|
execute_process(COMMAND ${HG_EXECUTABLE} --version
|
|
|
|
OUTPUT_VARIABLE hg_version
|
|
|
|
ERROR_QUIET
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
if(hg_version MATCHES "^Mercurial Distributed SCM \\(version ([0-9][^)]*)\\)")
|
|
|
|
set(HG_VERSION_STRING "${CMAKE_MATCH_1}")
|
|
|
|
endif()
|
|
|
|
unset(hg_version)
|
2014-02-22 22:46:48 +04:00
|
|
|
|
|
|
|
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)
|
2012-08-14 18:41:17 +04:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Handle the QUIETLY and REQUIRED arguments and set HG_FOUND to TRUE if
|
|
|
|
# all listed variables are TRUE
|
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
|
|
|
|
find_package_handle_standard_args(Hg
|
|
|
|
REQUIRED_VARS HG_EXECUTABLE
|
|
|
|
VERSION_VAR HG_VERSION_STRING)
|