1 # - Find Perl libraries
2 # This module finds if PERL is installed and determines where the include files
3 # and libraries are. It also determines what the name of the library is. This
4 # code sets the following variables:
6 # PERLLIBS_FOUND = True if perl.h & libperl were found
7 # PERL_INCLUDE_PATH = path to where perl.h is found
8 # PERL_LIBRARY = path to libperl
9 # PERL_EXECUTABLE = full path to the perl binary
11 # The minimum required version of Perl can be specified using the
12 # standard syntax, e.g. find_package(PerlLibs 6.0)
14 # The following variables are also available if needed
15 # (introduced after CMake 2.6.4)
17 # PERL_SITESEARCH = path to the sitesearch install dir
18 # PERL_SITELIB = path to the sitelib install directory
19 # PERL_VENDORARCH = path to the vendor arch install directory
20 # PERL_VENDORLIB = path to the vendor lib install directory
21 # PERL_ARCHLIB = path to the arch lib install directory
22 # PERL_PRIVLIB = path to the priv lib install directory
23 # PERL_EXTRA_C_FLAGS = Compilation flags used to build perl
26 #=============================================================================
27 # Copyright 2004-2009 Kitware, Inc.
28 # Copyright 2008 Andreas Schneider <asn@cryptomilk.org>
30 # Distributed under the OSI-approved BSD License (the "License");
31 # see accompanying file Copyright.txt for details.
33 # This software is distributed WITHOUT ANY WARRANTY; without even the
34 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
35 # See the License for more information.
36 #=============================================================================
37 # (To distribute this file outside of CMake, substitute the full
38 # License text for the above reference.)
40 # find the perl executable
47 ${PERL_EXECUTABLE} -V:prefix
49 PERL_PREFIX_OUTPUT_VARIABLE
51 PERL_PREFIX_RESULT_VARIABLE
54 if (NOT PERL_PREFIX_RESULT_VARIABLE)
55 string(REGEX REPLACE "prefix='([^']+)'.*" "\\1" PERL_PREFIX ${PERL_PREFIX_OUTPUT_VARIABLE})
61 ${PERL_EXECUTABLE} -V:archname
63 PERL_ARCHNAME_OUTPUT_VARIABLE
65 PERL_ARCHNAME_RESULT_VARIABLE
67 if (NOT PERL_ARCHNAME_RESULT_VARIABLE)
68 string(REGEX REPLACE "archname='([^']+)'.*" "\\1" PERL_ARCHNAME ${PERL_ARCHNAME_OUTPUT_VARIABLE})
73 ### PERL_EXTRA_C_FLAGS
76 ${PERL_EXECUTABLE} -V:cppflags
78 PERL_CPPFLAGS_OUTPUT_VARIABLE
80 PERL_CPPFLAGS_RESULT_VARIABLE
82 if (NOT PERL_CPPFLAGS_RESULT_VARIABLE)
83 string(REGEX REPLACE "cppflags='([^']+)'.*" "\\1" PERL_EXTRA_C_FLAGS ${PERL_CPPFLAGS_OUTPUT_VARIABLE})
89 ${PERL_EXECUTABLE} -V:installsitesearch
91 PERL_SITESEARCH_OUTPUT_VARIABLE
93 PERL_SITESEARCH_RESULT_VARIABLE
95 if (NOT PERL_SITESEARCH_RESULT_VARIABLE)
96 string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_SITESEARCH ${PERL_SITESEARCH_OUTPUT_VARIABLE})
97 file(TO_CMAKE_PATH "${PERL_SITESEARCH}" PERL_SITESEARCH)
103 ${PERL_EXECUTABLE} -V:installsitelib
105 PERL_SITELIB_OUTPUT_VARIABLE
107 PERL_SITELIB_RESULT_VARIABLE
109 if (NOT PERL_SITELIB_RESULT_VARIABLE)
110 string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_SITELIB ${PERL_SITELIB_OUTPUT_VARIABLE})
111 file(TO_CMAKE_PATH "${PERL_SITELIB}" PERL_SITELIB)
117 ${PERL_EXECUTABLE} -V:installvendorarch
119 PERL_VENDORARCH_OUTPUT_VARIABLE
121 PERL_VENDORARCH_RESULT_VARIABLE
123 if (NOT PERL_VENDORARCH_RESULT_VARIABLE)
124 string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_VENDORARCH ${PERL_VENDORARCH_OUTPUT_VARIABLE})
125 file(TO_CMAKE_PATH "${PERL_VENDORARCH}" PERL_VENDORARCH)
131 ${PERL_EXECUTABLE} -V:installvendorlib
133 PERL_VENDORLIB_OUTPUT_VARIABLE
135 PERL_VENDORLIB_RESULT_VARIABLE
137 if (NOT PERL_VENDORLIB_RESULT_VARIABLE)
138 string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_VENDORLIB ${PERL_VENDORLIB_OUTPUT_VARIABLE})
139 file(TO_CMAKE_PATH "${PERL_VENDORLIB}" PERL_VENDORLIB)
142 macro(perl_adjust_darwin_lib_variable varname)
143 string( TOUPPER PERL_${varname} FINDPERL_VARNAME )
144 string( TOLOWER install${varname} PERL_VARNAME )
146 if (NOT PERL_MINUSV_OUTPUT_VARIABLE)
149 ${PERL_EXECUTABLE} -V
151 PERL_MINUSV_OUTPUT_VARIABLE
153 PERL_MINUSV_RESULT_VARIABLE
157 if (NOT PERL_MINUSV_RESULT_VARIABLE)
158 string(REGEX MATCH "(${PERL_VARNAME}.*points? to the Updates directory)"
159 PERL_NEEDS_ADJUSTMENT ${PERL_MINUSV_OUTPUT_VARIABLE})
161 if (PERL_NEEDS_ADJUSTMENT)
162 string(REGEX REPLACE "(.*)/Updates/" "/System/\\1/" ${FINDPERL_VARNAME} ${${FINDPERL_VARNAME}})
171 ${PERL_EXECUTABLE} -V:installarchlib
173 PERL_ARCHLIB_OUTPUT_VARIABLE
175 PERL_ARCHLIB_RESULT_VARIABLE
177 if (NOT PERL_ARCHLIB_RESULT_VARIABLE)
178 string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_ARCHLIB ${PERL_ARCHLIB_OUTPUT_VARIABLE})
179 perl_adjust_darwin_lib_variable( ARCHLIB )
180 file(TO_CMAKE_PATH "${PERL_ARCHLIB}" PERL_ARCHLIB)
186 ${PERL_EXECUTABLE} -V:installprivlib
188 PERL_PRIVLIB_OUTPUT_VARIABLE
190 PERL_PRIVLIB_RESULT_VARIABLE
192 if (NOT PERL_PRIVLIB_RESULT_VARIABLE)
193 string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_PRIVLIB ${PERL_PRIVLIB_OUTPUT_VARIABLE})
194 perl_adjust_darwin_lib_variable( PRIVLIB )
195 file(TO_CMAKE_PATH "${PERL_PRIVLIB}" PERL_PRIVLIB)
198 ### PERL_POSSIBLE_LIBRARY_NAMES
201 ${PERL_EXECUTABLE} -V:libperl
203 PERL_LIBRARY_OUTPUT_VARIABLE
205 PERL_LIBRARY_RESULT_VARIABLE
207 if (NOT PERL_LIBRARY_RESULT_VARIABLE)
208 string(REGEX REPLACE "libperl='([^']+)'.*" "\\1" PERL_POSSIBLE_LIBRARY_NAMES ${PERL_LIBRARY_OUTPUT_VARIABLE})
210 set(PERL_POSSIBLE_LIBRARY_NAMES perl${PERL_VERSION_STRING} perl)
213 ### PERL_INCLUDE_PATH
214 find_path(PERL_INCLUDE_PATH
219 /usr/lib/perl5/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
220 /usr/lib/perl/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
221 /usr/lib/perl5/${PERL_VERSION_STRING}/CORE
222 /usr/lib/perl/${PERL_VERSION_STRING}/CORE
226 find_library(PERL_LIBRARY
228 ${PERL_POSSIBLE_LIBRARY_NAMES}
231 /usr/lib/perl5/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
232 /usr/lib/perl/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
233 /usr/lib/perl5/${PERL_VERSION_STRING}/CORE
234 /usr/lib/perl/${PERL_VERSION_STRING}/CORE
239 # handle the QUIETLY and REQUIRED arguments and set PERLLIBS_FOUND to TRUE if
240 # all listed variables are TRUE
241 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
242 find_package_handle_standard_args(PerlLibs REQUIRED_VARS PERL_LIBRARY PERL_INCLUDE_PATH
243 VERSION_VAR PERL_VERSION_STRING)
245 # Introduced after CMake 2.6.4 to bring module into compliance
246 set(PERL_INCLUDE_DIR ${PERL_INCLUDE_PATH})
247 set(PERL_INCLUDE_DIRS ${PERL_INCLUDE_PATH})
248 set(PERL_LIBRARIES ${PERL_LIBRARY})
249 # For backward compatibility with CMake before 2.8.8
250 set(PERL_VERSION ${PERL_VERSION_STRING})