Updated formatting of documentation plus a little reorganization.
[cmake.git] / Modules / FindPerlLibs.cmake
blob4662d57fbecc72bb7e4db928bba35a344ec929fc
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
24 include(FindPerl)
26 if (PERL_EXECUTABLE)
27   ### PERL_PREFIX
28   execute_process(
29     COMMAND
30       ${PERL_EXECUTABLE} -V:prefix
31       OUTPUT_VARIABLE
32         PERL_PREFIX_OUTPUT_VARIABLE
33       RESULT_VARIABLE
34         PERL_PREFIX_RESULT_VARIABLE
35   )
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)
41   ### PERL_VERSION
42   execute_process(
43     COMMAND
44       ${PERL_EXECUTABLE} -V:version
45       OUTPUT_VARIABLE
46         PERL_VERSION_OUTPUT_VARIABLE
47       RESULT_VARIABLE
48         PERL_VERSION_RESULT_VARIABLE
49   )
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)
54   ### PERL_ARCHNAME
55   execute_process(
56     COMMAND
57       ${PERL_EXECUTABLE} -V:archname
58       OUTPUT_VARIABLE
59         PERL_ARCHNAME_OUTPUT_VARIABLE
60       RESULT_VARIABLE
61         PERL_ARCHNAME_RESULT_VARIABLE
62   )
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
70   execute_process(
71     COMMAND
72       ${PERL_EXECUTABLE} -V:cppflags
73     OUTPUT_VARIABLE
74       PERL_CPPFLAGS_OUTPUT_VARIABLE
75     RESULT_VARIABLE
76       PERL_CPPFLAGS_RESULT_VARIABLE
77     )
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)
82   ### PERL_SITESEARCH
83   execute_process(
84     COMMAND
85       ${PERL_EXECUTABLE} -V:installsitesearch
86     OUTPUT_VARIABLE
87       PERL_SITESEARCH_OUTPUT_VARIABLE
88     RESULT_VARIABLE
89       PERL_SITESEARCH_RESULT_VARIABLE
90   )
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)
95   ### PERL_SITELIB
96   execute_process(
97     COMMAND
98       ${PERL_EXECUTABLE} -V:installsitelib
99     OUTPUT_VARIABLE
100       PERL_SITELIB_OUTPUT_VARIABLE
101     RESULT_VARIABLE
102       PERL_SITELIB_RESULT_VARIABLE
103   )
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)
108   ### PERL_VENDORARCH
109   execute_process(
110     COMMAND
111       ${PERL_EXECUTABLE} -V:installvendorarch
112     OUTPUT_VARIABLE
113       PERL_VENDORARCH_OUTPUT_VARIABLE
114     RESULT_VARIABLE
115       PERL_VENDORARCH_RESULT_VARIABLE
116     )
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)
121   ### PERL_VENDORLIB
122   execute_process(
123     COMMAND
124       ${PERL_EXECUTABLE} -V:installvendorlib
125     OUTPUT_VARIABLE
126       PERL_VENDORLIB_OUTPUT_VARIABLE
127     RESULT_VARIABLE
128       PERL_VENDORLIB_RESULT_VARIABLE
129   )
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)
134   ### PERL_ARCHLIB
135   execute_process(
136     COMMAND
137       ${PERL_EXECUTABLE} -V:installarchlib
138       OUTPUT_VARIABLE
139         PERL_ARCHLIB_OUTPUT_VARIABLE
140       RESULT_VARIABLE
141         PERL_ARCHLIB_RESULT_VARIABLE
142   )
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)
147   ### PERL_PRIVLIB
148   execute_process(
149     COMMAND
150       ${PERL_EXECUTABLE} -V:installprivlib
151     OUTPUT_VARIABLE
152       PERL_PRIVLIB_OUTPUT_VARIABLE
153     RESULT_VARIABLE
154       PERL_PRIVLIB_RESULT_VARIABLE
155   )
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
163     ${PERL_ARCHLIB}/CORE
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
168     )
170   ### PERL_POSSIBLE_LIB_PATHS
171   set(PERL_POSSIBLE_LIB_PATHS
172     ${PERL_ARCHLIB}/CORE
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
177   )
179   ### PERL_POSSIBLE_LIBRARY_NAME
180   execute_process(
181     COMMAND
182       ${PERL_EXECUTABLE} -V:libperl
183     OUTPUT_VARIABLE
184       PERL_LIBRARY_OUTPUT_VARIABLE
185     RESULT_VARIABLE
186       PERL_LIBRARY_RESULT_VARIABLE
187   )
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
197     NAMES
198       perl.h
199     PATHS
200       ${PERL_POSSIBLE_INCLUDE_PATHS}
201   )
202   
203   ### PERL_LIBRARY
204   find_library(PERL_LIBRARY
205     NAMES
206       ${PERL_POSSIBLE_LIBRARY_NAME}
207       perl${PERL_VERSION}
208       perl
209     PATHS
210       ${PERL_POSSIBLE_LIB_PATHS}
211   )
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})
225 mark_as_advanced(
226   PERL_INCLUDE_PATH
227   PERL_EXECUTABLE
228   PERL_LIBRARY