Browse Source

Add FindHg module to find Mercurial

Also teach the CMakeOnly.AllFindModules to verify Hg version detection.
Brad King 13 years ago
parent
commit
ea5bfb1d25
2 changed files with 49 additions and 1 deletions
  1. 48 0
      Modules/FindHg.cmake
  2. 1 1
      Tests/CMakeOnly/AllFindModules/CMakeLists.txt

+ 48 - 0
Modules/FindHg.cmake

@@ -0,0 +1,48 @@
+# 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
+# Example usage:
+#   find_package(Hg)
+#   if(HG_FOUND)
+#     message("hg found: ${HG_EXECUTABLE}")
+#   endif()
+
+#=============================================================================
+# Copyright 2010-2012 Kitware, Inc.
+# Copyright 2012      Rolf Eike Beer <[email protected]>
+#
+# 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
+  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)
+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)

+ 1 - 1
Tests/CMakeOnly/AllFindModules/CMakeLists.txt

@@ -70,7 +70,7 @@ endmacro()
 # If any of these modules reported that it was found a version number should have been
 # reported.
 
-foreach(VTEST ALSA ARMADILLO BZIP2 CUPS CURL EXPAT FREETYPE GETTEXT GIT HSPELL
+foreach(VTEST ALSA ARMADILLO BZIP2 CUPS CURL EXPAT FREETYPE GETTEXT GIT HG HSPELL
         JASPER LIBLZMA LIBXML2 LIBXSLT PERL PKG_CONFIG PostgreSQL TIFF ZLIB)
     check_version_string(${VTEST} ${VTEST}_VERSION_STRING)
 endforeach()