BASIS  r3148
FindPerl.cmake
Go to the documentation of this file.
00001 ##############################################################################
00002 # @file  FindPerl.cmake
00003 # @brief Find Perl interpreter.
00004 #
00005 # @par Output variables:
00006 # <table border="0">
00007 #   <tr>
00008 #     @tp @b Perl_FOUND @endtp
00009 #     <td>Was the Python executable found.</td>
00010 #   </tr>
00011 #   <tr>
00012 #     @tp @b PERL_FOUND @endtp
00013 #     <td>Alias for @b Perl_FOUND for backwards compatibility.</td>
00014 #   </tr>
00015 #   <tr>
00016 #     @tp @b PERL_EXECUTABLE @endtp
00017 #     <td>Path to the Perl interpreter.</td>
00018 #   </tr>
00019 #   <tr>
00020 #     @tp @b PERL_VERSION_STRING @endtp
00021 #     <td>Perl version found e.g. 5.12.4.</td>
00022 #   </tr>
00023 #   <tr>
00024 #     @tp @b PERL_VERSION_MAJOR @endtp
00025 #     <td>Perl major version found e.g. 5.</td>
00026 #   </tr>
00027 #   <tr>
00028 #     @tp @b PERL_VERSION_MINOR @endtp
00029 #     <td>Perl minor version found e.g. 12.</td>
00030 #   </tr>
00031 #   <tr>
00032 #     @tp @b PERL_VERSION_PATCH @endtp
00033 #     <td>Perl patch version found e.g. 4.</td>
00034 #   </tr>
00035 # </table>
00036 #
00037 # @note This module has been copied from CMake 2.8.5 and modified to also
00038 #       obtain the version information of the found Perl interpreter.
00039 #
00040 # @ingroup CMakeFindModules
00041 ##############################################################################
00042 
00043 #=============================================================================
00044 # Copyright 2001-2009 Kitware, Inc.
00045 #
00046 # Redistribution and use in source and binary forms, with or without
00047 # modification, are permitted provided that the following conditions
00048 # are met:
00049 #
00050 # * Redistributions of source code must retain the above copyright
00051 #   notice, this list of conditions and the following disclaimer.
00052 #
00053 # * Redistributions in binary form must reproduce the above copyright
00054 #   notice, this list of conditions and the following disclaimer in the
00055 #   documentation and/or other materials provided with the distribution.
00056 #
00057 # * Neither the names of Kitware, Inc., the Insight Software Consortium,
00058 #   nor the names of their contributors may be used to endorse or promote
00059 #   products derived from this software without specific prior written
00060 #   permission.
00061 #
00062 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00063 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00064 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00065 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00066 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00067 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00068 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00069 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00070 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00071 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00072 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00073 #=============================================================================
00074 
00075 include (FindCygwin)
00076 
00077 set (PERL_POSSIBLE_BIN_PATHS "${CYGWIN_INSTALL_PATH}/bin")
00078 
00079 if (WIN32)
00080   get_filename_component (
00081     ActivePerl_CurrentVersion 
00082       "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl;CurrentVersion]" 
00083     NAME
00084   )
00085   set (PERL_POSSIBLE_BIN_PATHS ${PERL_POSSIBLE_BIN_PATHS}
00086     "C:/Perl/bin" 
00087     "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl\\${ActivePerl_CurrentVersion}]/bin"
00088   )
00089 endif ()
00090 
00091 find_program (PERL_EXECUTABLE NAMES perl PATHS ${PERL_POSSIBLE_BIN_PATHS})
00092 
00093 if (PERL_EXECUTABLE)
00094   execute_process (COMMAND "${PERL_EXECUTABLE}" --version OUTPUT_VARIABLE _Perl_STDOUT ERROR_VARIABLE _Perl_STDERR)
00095   if (_Perl_STDOUT MATCHES "[( ]v([0-9]+)\\.([0-9]+)\\.([0-9]+)[ )]")
00096     set (PERL_VERSION_MAJOR "${CMAKE_MATCH_1}")
00097     set (PERL_VERSION_MINOR "${CMAKE_MATCH_2}")
00098     set (PERL_VERSION_PATCH "${CMAKE_MATCH_3}")
00099     set (PERL_VERSION_STRING "${PERL_VERSION_MAJOR}.${PERL_VERSION_MINOR}.${PERL_VERSION_PATCH}")
00100   else ()
00101     message (WARNING "Failed to determine version of Perl interpreter (${PERL_EXECUTABLE})! Error:\n${_Perl_STDERR}")
00102   endif ()
00103   unset (_Perl_STDOUT)
00104   unset (_Perl_STDERR)
00105 endif ()
00106 
00107 include (FindPackageHandleStandardArgs)
00108 FIND_PACKAGE_HANDLE_STANDARD_ARGS (Perl DEFAULT_MSG PERL_EXECUTABLE)
00109 
00110 mark_as_advanced (PERL_EXECUTABLE)