FindPerl.cmake
Go to the documentation of this file.
1 ##############################################################################
2 # @file FindPerl.cmake
3 # @brief Find Perl interpreter.
4 #
5 # @par Output variables:
6 # <table border="0">
7 # <tr>
8 # @tp @b Perl_FOUND @endtp
9 # <td>Was the Python executable found.</td>
10 # </tr>
11 # <tr>
12 # @tp @b PERL_FOUND @endtp
13 # <td>Alias for @b Perl_FOUND for backwards compatibility.</td>
14 # </tr>
15 # <tr>
16 # @tp @b PERL_EXECUTABLE @endtp
17 # <td>Path to the Perl interpreter.</td>
18 # </tr>
19 # <tr>
20 # @tp @b Perl_DIR @endtp
21 # <td>Installation prefix of the Perl interpreter.</td>
22 # </tr>
23 # <tr>
24 # @tp @b PERL_VERSION_STRING @endtp
25 # <td>Perl version found e.g. 5.12.4.</td>
26 # </tr>
27 # <tr>
28 # @tp @b PERL_VERSION_MAJOR @endtp
29 # <td>Perl major version found e.g. 5.</td>
30 # </tr>
31 # <tr>
32 # @tp @b PERL_VERSION_MINOR @endtp
33 # <td>Perl minor version found e.g. 12.</td>
34 # </tr>
35 # <tr>
36 # @tp @b PERL_VERSION_PATCH @endtp
37 # <td>Perl patch version found e.g. 4.</td>
38 # </tr>
39 # </table>
40 #
41 # @note This module has been copied from CMake 2.8.5 and modified to also
42 # obtain the version information of the found Perl interpreter.
43 #
44 # @ingroup CMakeFindModules
45 ##############################################################################
46 
47 #=============================================================================
48 # Copyright 2001-2009 Kitware, Inc.
49 #
50 # Distributed under the OSI-approved BSD License (the "License");
51 # see accompanying file Copyright.txt for details.
52 #
53 # This software is distributed WITHOUT ANY WARRANTY; without even the
54 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
55 # See the License for more information.
56 #=============================================================================
57 # (To distribute this file outside of CMake, substitute the full
58 # License text for the above reference.)
59 
60 include ("${CMAKE_ROOT}/Modules/FindCygwin.cmake")
61 
62 set (PERL_POSSIBLE_BIN_PATHS "${CYGWIN_INSTALL_PATH}/bin")
63 if (WIN32)
64  get_filename_component (
65  ActivePerl_CurrentVersion
66  "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl;CurrentVersion]"
67  NAME
68  )
69  set (PERL_POSSIBLE_BIN_PATHS ${PERL_POSSIBLE_BIN_PATHS}
70  "C:/Perl/bin"
71  "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl\\${ActivePerl_CurrentVersion}]/bin"
72  )
73  unset (ActivePerl_CurrentVersion)
74 endif ()
75 
76 find_program (PERL_EXECUTABLE NAMES perl PATHS ${PERL_POSSIBLE_BIN_PATHS})
77 unset (PERL_POSSIBLE_BIN_PATHS)
78 
79 if (PERL_EXECUTABLE)
80  string (REGEX REPLACE "/bin/[pP]erl[^/]*" "" Perl_DIR "${PERL_EXECUTABLE}")
81  execute_process (COMMAND "${PERL_EXECUTABLE}" --version OUTPUT_VARIABLE _Perl_STDOUT ERROR_VARIABLE _Perl_STDERR)
82  if (_Perl_STDOUT MATCHES "[( ]v([0-9]+)\\.([0-9]+)\\.([0-9]+)[ )]")
83  set (PERL_VERSION_MAJOR "${CMAKE_MATCH_1}")
84  set (PERL_VERSION_MINOR "${CMAKE_MATCH_2}")
85  set (PERL_VERSION_PATCH "${CMAKE_MATCH_3}")
86  set (PERL_VERSION_STRING "${PERL_VERSION_MAJOR}.${PERL_VERSION_MINOR}.${PERL_VERSION_PATCH}")
87  else ()
88  message (WARNING "Failed to determine version of Perl interpreter (${PERL_EXECUTABLE})! Error:\n${_Perl_STDERR}")
89  endif ()
90  unset (_Perl_STDOUT)
91  unset (_Perl_STDERR)
92 endif ()
93 
94 include (FindPackageHandleStandardArgs)
95 
96 find_package_handle_standard_args (
97  Perl
98  REQUIRED_VARS
99  PERL_EXECUTABLE
100  VERSION_VAR
101  PERL_VERSION_STRING
102 )
103 
104 if (NOT DEFINED Perl_FOUND AND DEFINED PERL_FOUND)
105  set (Perl_FOUND "${PERL_FOUND}")
106 endif ()
107 
108 mark_as_advanced (PERL_EXECUTABLE)
cmake PERL_VERSION_MINOR
Definition: FindPerl.cmake:84
cmake PERL_VERSION_PATCH
Definition: FindPerl.cmake:85
cmake PERL_VERSION_MAJOR
Definition: FindPerl.cmake:83
cmake PERL_POSSIBLE_BIN_PATHS
Definition: FindPerl.cmake:47