FindPerlLibs.cmake 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. #.rst:
  2. # FindPerlLibs
  3. # ------------
  4. #
  5. # Find Perl libraries
  6. #
  7. # This module finds if PERL is installed and determines where the
  8. # include files and libraries are. It also determines what the name of
  9. # the library is. This code sets the following variables:
  10. #
  11. # ::
  12. #
  13. # PERLLIBS_FOUND = True if perl.h & libperl were found
  14. # PERL_INCLUDE_PATH = path to where perl.h is found
  15. # PERL_LIBRARY = path to libperl
  16. # PERL_EXECUTABLE = full path to the perl binary
  17. #
  18. #
  19. #
  20. # The minimum required version of Perl can be specified using the
  21. # standard syntax, e.g. find_package(PerlLibs 6.0)
  22. #
  23. # ::
  24. #
  25. # The following variables are also available if needed
  26. # (introduced after CMake 2.6.4)
  27. #
  28. #
  29. #
  30. # ::
  31. #
  32. # PERL_SITESEARCH = path to the sitesearch install dir
  33. # PERL_SITELIB = path to the sitelib install directory
  34. # PERL_VENDORARCH = path to the vendor arch install directory
  35. # PERL_VENDORLIB = path to the vendor lib install directory
  36. # PERL_ARCHLIB = path to the arch lib install directory
  37. # PERL_PRIVLIB = path to the priv lib install directory
  38. # PERL_EXTRA_C_FLAGS = Compilation flags used to build perl
  39. #=============================================================================
  40. # Copyright 2004-2009 Kitware, Inc.
  41. # Copyright 2008 Andreas Schneider <asn@cryptomilk.org>
  42. #
  43. # Distributed under the OSI-approved BSD License (the "License");
  44. # see accompanying file Copyright.txt for details.
  45. #
  46. # This software is distributed WITHOUT ANY WARRANTY; without even the
  47. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  48. # See the License for more information.
  49. #=============================================================================
  50. # (To distribute this file outside of CMake, substitute the full
  51. # License text for the above reference.)
  52. # find the perl executable
  53. include(${CMAKE_CURRENT_LIST_DIR}/FindPerl.cmake)
  54. if (PERL_EXECUTABLE)
  55. ### PERL_PREFIX
  56. execute_process(
  57. COMMAND
  58. ${PERL_EXECUTABLE} -V:prefix
  59. OUTPUT_VARIABLE
  60. PERL_PREFIX_OUTPUT_VARIABLE
  61. RESULT_VARIABLE
  62. PERL_PREFIX_RESULT_VARIABLE
  63. )
  64. if (NOT PERL_PREFIX_RESULT_VARIABLE)
  65. string(REGEX REPLACE "prefix='([^']+)'.*" "\\1" PERL_PREFIX ${PERL_PREFIX_OUTPUT_VARIABLE})
  66. endif ()
  67. ### PERL_ARCHNAME
  68. execute_process(
  69. COMMAND
  70. ${PERL_EXECUTABLE} -V:archname
  71. OUTPUT_VARIABLE
  72. PERL_ARCHNAME_OUTPUT_VARIABLE
  73. RESULT_VARIABLE
  74. PERL_ARCHNAME_RESULT_VARIABLE
  75. )
  76. if (NOT PERL_ARCHNAME_RESULT_VARIABLE)
  77. string(REGEX REPLACE "archname='([^']+)'.*" "\\1" PERL_ARCHNAME ${PERL_ARCHNAME_OUTPUT_VARIABLE})
  78. endif ()
  79. ### PERL_EXTRA_C_FLAGS
  80. execute_process(
  81. COMMAND
  82. ${PERL_EXECUTABLE} -V:cppflags
  83. OUTPUT_VARIABLE
  84. PERL_CPPFLAGS_OUTPUT_VARIABLE
  85. RESULT_VARIABLE
  86. PERL_CPPFLAGS_RESULT_VARIABLE
  87. )
  88. if (NOT PERL_CPPFLAGS_RESULT_VARIABLE)
  89. string(REGEX REPLACE "cppflags='([^']+)'.*" "\\1" PERL_EXTRA_C_FLAGS ${PERL_CPPFLAGS_OUTPUT_VARIABLE})
  90. endif ()
  91. ### PERL_SITESEARCH
  92. execute_process(
  93. COMMAND
  94. ${PERL_EXECUTABLE} -V:installsitesearch
  95. OUTPUT_VARIABLE
  96. PERL_SITESEARCH_OUTPUT_VARIABLE
  97. RESULT_VARIABLE
  98. PERL_SITESEARCH_RESULT_VARIABLE
  99. )
  100. if (NOT PERL_SITESEARCH_RESULT_VARIABLE)
  101. string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_SITESEARCH ${PERL_SITESEARCH_OUTPUT_VARIABLE})
  102. file(TO_CMAKE_PATH "${PERL_SITESEARCH}" PERL_SITESEARCH)
  103. endif ()
  104. ### PERL_SITELIB
  105. execute_process(
  106. COMMAND
  107. ${PERL_EXECUTABLE} -V:installsitelib
  108. OUTPUT_VARIABLE
  109. PERL_SITELIB_OUTPUT_VARIABLE
  110. RESULT_VARIABLE
  111. PERL_SITELIB_RESULT_VARIABLE
  112. )
  113. if (NOT PERL_SITELIB_RESULT_VARIABLE)
  114. string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_SITELIB ${PERL_SITELIB_OUTPUT_VARIABLE})
  115. file(TO_CMAKE_PATH "${PERL_SITELIB}" PERL_SITELIB)
  116. endif ()
  117. ### PERL_VENDORARCH
  118. execute_process(
  119. COMMAND
  120. ${PERL_EXECUTABLE} -V:installvendorarch
  121. OUTPUT_VARIABLE
  122. PERL_VENDORARCH_OUTPUT_VARIABLE
  123. RESULT_VARIABLE
  124. PERL_VENDORARCH_RESULT_VARIABLE
  125. )
  126. if (NOT PERL_VENDORARCH_RESULT_VARIABLE)
  127. string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_VENDORARCH ${PERL_VENDORARCH_OUTPUT_VARIABLE})
  128. file(TO_CMAKE_PATH "${PERL_VENDORARCH}" PERL_VENDORARCH)
  129. endif ()
  130. ### PERL_VENDORLIB
  131. execute_process(
  132. COMMAND
  133. ${PERL_EXECUTABLE} -V:installvendorlib
  134. OUTPUT_VARIABLE
  135. PERL_VENDORLIB_OUTPUT_VARIABLE
  136. RESULT_VARIABLE
  137. PERL_VENDORLIB_RESULT_VARIABLE
  138. )
  139. if (NOT PERL_VENDORLIB_RESULT_VARIABLE)
  140. string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_VENDORLIB ${PERL_VENDORLIB_OUTPUT_VARIABLE})
  141. file(TO_CMAKE_PATH "${PERL_VENDORLIB}" PERL_VENDORLIB)
  142. endif ()
  143. macro(perl_adjust_darwin_lib_variable varname)
  144. string( TOUPPER PERL_${varname} FINDPERL_VARNAME )
  145. string( TOLOWER install${varname} PERL_VARNAME )
  146. if (NOT PERL_MINUSV_OUTPUT_VARIABLE)
  147. execute_process(
  148. COMMAND
  149. ${PERL_EXECUTABLE} -V
  150. OUTPUT_VARIABLE
  151. PERL_MINUSV_OUTPUT_VARIABLE
  152. RESULT_VARIABLE
  153. PERL_MINUSV_RESULT_VARIABLE
  154. )
  155. endif()
  156. if (NOT PERL_MINUSV_RESULT_VARIABLE)
  157. string(REGEX MATCH "(${PERL_VARNAME}.*points? to the Updates directory)"
  158. PERL_NEEDS_ADJUSTMENT ${PERL_MINUSV_OUTPUT_VARIABLE})
  159. if (PERL_NEEDS_ADJUSTMENT)
  160. string(REGEX REPLACE "(.*)/Updates/" "/System/\\1/" ${FINDPERL_VARNAME} ${${FINDPERL_VARNAME}})
  161. endif ()
  162. endif ()
  163. endmacro()
  164. ### PERL_ARCHLIB
  165. execute_process(
  166. COMMAND
  167. ${PERL_EXECUTABLE} -V:installarchlib
  168. OUTPUT_VARIABLE
  169. PERL_ARCHLIB_OUTPUT_VARIABLE
  170. RESULT_VARIABLE
  171. PERL_ARCHLIB_RESULT_VARIABLE
  172. )
  173. if (NOT PERL_ARCHLIB_RESULT_VARIABLE)
  174. string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_ARCHLIB ${PERL_ARCHLIB_OUTPUT_VARIABLE})
  175. perl_adjust_darwin_lib_variable( ARCHLIB )
  176. file(TO_CMAKE_PATH "${PERL_ARCHLIB}" PERL_ARCHLIB)
  177. endif ()
  178. ### PERL_PRIVLIB
  179. execute_process(
  180. COMMAND
  181. ${PERL_EXECUTABLE} -V:installprivlib
  182. OUTPUT_VARIABLE
  183. PERL_PRIVLIB_OUTPUT_VARIABLE
  184. RESULT_VARIABLE
  185. PERL_PRIVLIB_RESULT_VARIABLE
  186. )
  187. if (NOT PERL_PRIVLIB_RESULT_VARIABLE)
  188. string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_PRIVLIB ${PERL_PRIVLIB_OUTPUT_VARIABLE})
  189. perl_adjust_darwin_lib_variable( PRIVLIB )
  190. file(TO_CMAKE_PATH "${PERL_PRIVLIB}" PERL_PRIVLIB)
  191. endif ()
  192. ### PERL_POSSIBLE_LIBRARY_NAMES
  193. execute_process(
  194. COMMAND
  195. ${PERL_EXECUTABLE} -V:libperl
  196. OUTPUT_VARIABLE
  197. PERL_LIBRARY_OUTPUT_VARIABLE
  198. RESULT_VARIABLE
  199. PERL_LIBRARY_RESULT_VARIABLE
  200. )
  201. if (NOT PERL_LIBRARY_RESULT_VARIABLE)
  202. string(REGEX REPLACE "libperl='([^']+)'.*" "\\1" PERL_POSSIBLE_LIBRARY_NAMES ${PERL_LIBRARY_OUTPUT_VARIABLE})
  203. else ()
  204. set(PERL_POSSIBLE_LIBRARY_NAMES perl${PERL_VERSION_STRING} perl)
  205. endif ()
  206. ### PERL_INCLUDE_PATH
  207. find_path(PERL_INCLUDE_PATH
  208. NAMES
  209. perl.h
  210. PATHS
  211. ${PERL_ARCHLIB}/CORE
  212. /usr/lib/perl5/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
  213. /usr/lib/perl/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
  214. /usr/lib/perl5/${PERL_VERSION_STRING}/CORE
  215. /usr/lib/perl/${PERL_VERSION_STRING}/CORE
  216. )
  217. ### PERL_LIBRARY
  218. find_library(PERL_LIBRARY
  219. NAMES
  220. ${PERL_POSSIBLE_LIBRARY_NAMES}
  221. PATHS
  222. ${PERL_ARCHLIB}/CORE
  223. /usr/lib/perl5/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
  224. /usr/lib/perl/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
  225. /usr/lib/perl5/${PERL_VERSION_STRING}/CORE
  226. /usr/lib/perl/${PERL_VERSION_STRING}/CORE
  227. )
  228. endif ()
  229. # handle the QUIETLY and REQUIRED arguments and set PERLLIBS_FOUND to TRUE if
  230. # all listed variables are TRUE
  231. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  232. find_package_handle_standard_args(PerlLibs REQUIRED_VARS PERL_LIBRARY PERL_INCLUDE_PATH
  233. VERSION_VAR PERL_VERSION_STRING)
  234. # Introduced after CMake 2.6.4 to bring module into compliance
  235. set(PERL_INCLUDE_DIR ${PERL_INCLUDE_PATH})
  236. set(PERL_INCLUDE_DIRS ${PERL_INCLUDE_PATH})
  237. set(PERL_LIBRARIES ${PERL_LIBRARY})
  238. # For backward compatibility with CMake before 2.8.8
  239. set(PERL_VERSION ${PERL_VERSION_STRING})
  240. mark_as_advanced(
  241. PERL_INCLUDE_PATH
  242. PERL_LIBRARY
  243. )