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 following variables are also available if needed
12 # (introduced after CMake 2.6.4)
14 # PERL_SITESEARCH = path to the sitesearch install dir
15 # PERL_SITELIB = path to the sitelib install directory
16 # PERL_VENDORARCH = path to the vendor arch install directory
17 # PERL_VENDORLIB = path to the vendor lib install directory
18 # PERL_ARCHLIB = path to the arch lib install directory
19 # PERL_PRIVLIB = path to the priv lib install directory
20 # PERL_EXTRA_C_FLAGS = Compilation flags used to build perl
23 # find the perl executable
30 ${PERL_EXECUTABLE} -V:prefix
32 PERL_PREFIX_OUTPUT_VARIABLE
34 PERL_PREFIX_RESULT_VARIABLE
37 if (NOT PERL_PREFIX_RESULT_VARIABLE)
38 string(REGEX REPLACE "prefix='([^']+)'.*" "\\1" PERL_PREFIX ${PERL_PREFIX_OUTPUT_VARIABLE})
39 endif (NOT PERL_PREFIX_RESULT_VARIABLE)
44 ${PERL_EXECUTABLE} -V:version
46 PERL_VERSION_OUTPUT_VARIABLE
48 PERL_VERSION_RESULT_VARIABLE
50 if (NOT PERL_VERSION_RESULT_VARIABLE)
51 string(REGEX REPLACE "version='([^']+)'.*" "\\1" PERL_VERSION ${PERL_VERSION_OUTPUT_VARIABLE})
52 endif (NOT PERL_VERSION_RESULT_VARIABLE)
57 ${PERL_EXECUTABLE} -V:archname
59 PERL_ARCHNAME_OUTPUT_VARIABLE
61 PERL_ARCHNAME_RESULT_VARIABLE
63 if (NOT PERL_ARCHNAME_RESULT_VARIABLE)
64 string(REGEX REPLACE "archname='([^']+)'.*" "\\1" PERL_ARCHNAME ${PERL_ARCHNAME_OUTPUT_VARIABLE})
65 endif (NOT PERL_ARCHNAME_RESULT_VARIABLE)
69 ### PERL_EXTRA_C_FLAGS
72 ${PERL_EXECUTABLE} -V:cppflags
74 PERL_CPPFLAGS_OUTPUT_VARIABLE
76 PERL_CPPFLAGS_RESULT_VARIABLE
78 if (NOT PERL_CPPFLAGS_RESULT_VARIABLE)
79 string(REGEX REPLACE "cppflags='([^']+)'.*" "\\1" PERL_EXTRA_C_FLAGS ${PERL_CPPFLAGS_OUTPUT_VARIABLE})
80 endif (NOT PERL_CPPFLAGS_RESULT_VARIABLE)
85 ${PERL_EXECUTABLE} -V:installsitesearch
87 PERL_SITESEARCH_OUTPUT_VARIABLE
89 PERL_SITESEARCH_RESULT_VARIABLE
91 if (NOT PERL_SITESEARCH_RESULT_VARIABLE)
92 string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_SITESEARCH ${PERL_SITESEARCH_OUTPUT_VARIABLE})
93 endif (NOT PERL_SITESEARCH_RESULT_VARIABLE)
98 ${PERL_EXECUTABLE} -V:installsitelib
100 PERL_SITELIB_OUTPUT_VARIABLE
102 PERL_SITELIB_RESULT_VARIABLE
104 if (NOT PERL_SITELIB_RESULT_VARIABLE)
105 string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_SITELIB ${PERL_SITELIB_OUTPUT_VARIABLE})
106 endif (NOT PERL_SITELIB_RESULT_VARIABLE)
111 ${PERL_EXECUTABLE} -V:installvendorarch
113 PERL_VENDORARCH_OUTPUT_VARIABLE
115 PERL_VENDORARCH_RESULT_VARIABLE
117 if (NOT PERL_VENDORARCH_RESULT_VARIABLE)
118 string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_VENDORARCH ${PERL_VENDORARCH_OUTPUT_VARIABLE})
119 endif (NOT PERL_VENDORARCH_RESULT_VARIABLE)
124 ${PERL_EXECUTABLE} -V:installvendorlib
126 PERL_VENDORLIB_OUTPUT_VARIABLE
128 PERL_VENDORLIB_RESULT_VARIABLE
130 if (NOT PERL_VENDORLIB_RESULT_VARIABLE)
131 string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_VENDORLIB ${PERL_VENDORLIB_OUTPUT_VARIABLE})
132 endif (NOT PERL_VENDORLIB_RESULT_VARIABLE)
137 ${PERL_EXECUTABLE} -V:installarchlib
139 PERL_ARCHLIB_OUTPUT_VARIABLE
141 PERL_ARCHLIB_RESULT_VARIABLE
143 if (NOT PERL_ARCHLIB_RESULT_VARIABLE)
144 string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_ARCHLIB ${PERL_ARCHLIB_OUTPUT_VARIABLE})
145 endif (NOT PERL_ARCHLIB_RESULT_VARIABLE)
150 ${PERL_EXECUTABLE} -V:installprivlib
152 PERL_PRIVLIB_OUTPUT_VARIABLE
154 PERL_PRIVLIB_RESULT_VARIABLE
156 if (NOT PERL_PRIVLIB_RESULT_VARIABLE)
157 string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_PRIVLIB ${PERL_PRIVLIB_OUTPUT_VARIABLE})
158 endif (NOT PERL_PRIVLIB_RESULT_VARIABLE)
161 ### PERL_POSSIBLE_INCLUDE_PATHS
162 set(PERL_POSSIBLE_INCLUDE_PATHS
164 /usr/lib/perl5/${PERL_VERSION}/${PERL_ARCHNAME}/CORE
165 /usr/lib/perl/${PERL_VERSION}/${PERL_ARCHNAME}/CORE
166 /usr/lib/perl5/${PERL_VERSION}/CORE
167 /usr/lib/perl/${PERL_VERSION}/CORE
170 ### PERL_POSSIBLE_LIB_PATHS
171 set(PERL_POSSIBLE_LIB_PATHS
173 /usr/lib/perl5/${PERL_VERSION}/${PERL_ARCHNAME}/CORE
174 /usr/lib/perl/${PERL_VERSION}/${PERL_ARCHNAME}/CORE
175 /usr/lib/perl5/${PERL_VERSION}/CORE
176 /usr/lib/perl/${PERL_VERSION}/CORE
179 ### PERL_POSSIBLE_LIBRARY_NAME
182 ${PERL_EXECUTABLE} -V:libperl
184 PERL_LIBRARY_OUTPUT_VARIABLE
186 PERL_LIBRARY_RESULT_VARIABLE
188 if (NOT PERL_LIBRARY_RESULT_VARIABLE)
189 foreach(_perl_lib_path ${PERL_POSSIBLE_LIB_PATHS})
190 string(REGEX REPLACE "libperl='([^']+)'" "\\1" PERL_LIBRARY_OUTPUT_VARIABLE ${PERL_LIBRARY_OUTPUT_VARIABLE})
191 set(PERL_POSSIBLE_LIBRARY_NAME ${PERL_POSSIBLE_LIBRARY_NAME} "${_perl_lib_path}/${PERL_LIBRARY_OUTPUT_VARIABLE}")
192 endforeach(_perl_lib_path ${PERL_POSSIBLE_LIB_PATHS})
193 endif (NOT PERL_LIBRARY_RESULT_VARIABLE)
195 ### PERL_INCLUDE_PATH
196 find_path(PERL_INCLUDE_PATH
200 ${PERL_POSSIBLE_INCLUDE_PATHS}
204 find_library(PERL_LIBRARY
206 ${PERL_POSSIBLE_LIBRARY_NAME}
210 ${PERL_POSSIBLE_LIB_PATHS}
213 endif (PERL_EXECUTABLE)
215 # handle the QUIETLY and REQUIRED arguments and set PERLLIBS_FOUND to TRUE if
216 # all listed variables are TRUE
217 INCLUDE(FindPackageHandleStandardArgs)
218 FIND_PACKAGE_HANDLE_STANDARD_ARGS(PerlLibs DEFAULT_MSG PERL_LIBRARY PERL_INCLUDE_PATH)
220 # Introduced after CMake 2.6.4 to bring module into compliance
221 set(PERL_INCLUDE_DIR ${PERL_INCLUDE_PATH})
222 set(PERL_INCLUDE_DIRS ${PERL_INCLUDE_PATH})
223 set(PERL_LIBRARIES ${PERL_LIBRARY})