FindPerl.cmake 2.91 KB
Newer Older
1 2 3 4 5 6
#.rst:
# FindPerl
# --------
#
# Find perl
#
7 8
# this module looks for Perl
#
9 10 11 12 13
# ::
#
#   PERL_EXECUTABLE     - the full path to perl
#   PERL_FOUND          - If false, don't attempt to use perl.
#   PERL_VERSION_STRING - version of perl found (since CMake 2.8.8)
14

15 16 17 18 19 20 21 22 23 24
#=============================================================================
# Copyright 2001-2009 Kitware, Inc.
#
# 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.
#=============================================================================
25
# (To distribute this file outside of CMake, substitute the full
26 27
#  License text for the above reference.)

28
include(${CMAKE_CURRENT_LIST_DIR}/FindCygwin.cmake)
29

30
set(PERL_POSSIBLE_BIN_PATHS
31
  ${CYGWIN_INSTALL_PATH}/bin
32
  )
33

34 35
if(WIN32)
  get_filename_component(
36 37
    ActivePerl_CurrentVersion
    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl;CurrentVersion]"
38
    NAME)
39
  set(PERL_POSSIBLE_BIN_PATHS ${PERL_POSSIBLE_BIN_PATHS}
40
    "C:/Perl/bin"
41 42
    [HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl\\${ActivePerl_CurrentVersion}]/bin
    )
43
endif()
44

45
find_program(PERL_EXECUTABLE
46 47 48
  NAMES perl
  PATHS ${PERL_POSSIBLE_BIN_PATHS}
  )
Ian Scott's avatar
Ian Scott committed
49

50
if(PERL_EXECUTABLE)
51
  ### PERL_VERSION
52
  execute_process(
53 54 55 56 57 58 59 60 61
    COMMAND
      ${PERL_EXECUTABLE} -V:version
      OUTPUT_VARIABLE
        PERL_VERSION_OUTPUT_VARIABLE
      RESULT_VARIABLE
        PERL_VERSION_RESULT_VARIABLE
      ERROR_QUIET
      OUTPUT_STRIP_TRAILING_WHITESPACE
  )
62 63 64 65
  if(NOT PERL_VERSION_RESULT_VARIABLE AND NOT PERL_VERSION_OUTPUT_VARIABLE MATCHES "^version='UNKNOWN'")
    string(REGEX REPLACE "version='([^']+)'.*" "\\1" PERL_VERSION_STRING ${PERL_VERSION_OUTPUT_VARIABLE})
  else()
    execute_process(
66 67 68 69 70 71
      COMMAND ${PERL_EXECUTABLE} -v
      OUTPUT_VARIABLE PERL_VERSION_OUTPUT_VARIABLE
      RESULT_VARIABLE PERL_VERSION_RESULT_VARIABLE
      ERROR_QUIET
      OUTPUT_STRIP_TRAILING_WHITESPACE
    )
72
    if(NOT PERL_VERSION_RESULT_VARIABLE AND PERL_VERSION_OUTPUT_VARIABLE MATCHES "This is perl.*[ \\(]v([0-9\\._]+)[ \\)]")
73
      set(PERL_VERSION_STRING "${CMAKE_MATCH_1}")
74
    elseif(NOT PERL_VERSION_RESULT_VARIABLE AND PERL_VERSION_OUTPUT_VARIABLE MATCHES "This is perl, version ([0-9\\._]+) +")
75
      set(PERL_VERSION_STRING "${CMAKE_MATCH_1}")
76 77
    endif()
  endif()
78
endif()
79

80
# Deprecated settings for compatibility with CMake1.4
81
set(PERL ${PERL_EXECUTABLE})
Ian Scott's avatar
Ian Scott committed
82

83
# handle the QUIETLY and REQUIRED arguments and set PERL_FOUND to TRUE if
84
# all listed variables are TRUE
85
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
86 87 88
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Perl
                                  REQUIRED_VARS PERL_EXECUTABLE
                                  VERSION_VAR PERL_VERSION_STRING)
89

90
mark_as_advanced(PERL_EXECUTABLE)