FindPerlLibs.cmake 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindPerlLibs
  5. ------------
  6. Find Perl libraries
  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. PERLLIBS_FOUND = True if perl.h & libperl were found
  12. PERL_INCLUDE_PATH = path to where perl.h is found
  13. PERL_LIBRARY = path to libperl
  14. PERL_EXECUTABLE = full path to the perl binary
  15. The minimum required version of Perl can be specified using the
  16. standard syntax, e.g. find_package(PerlLibs 6.0)
  17. ::
  18. The following variables are also available if needed
  19. (introduced after CMake 2.6.4)
  20. ::
  21. PERL_SITESEARCH = path to the sitesearch install dir (-V:installsitesearch)
  22. PERL_SITEARCH = path to the sitelib install directory (-V:installsitearch)
  23. PERL_SITELIB = path to the sitelib install directory (-V:installsitelib)
  24. PERL_VENDORARCH = path to the vendor arch install directory (-V:installvendorarch)
  25. PERL_VENDORLIB = path to the vendor lib install directory (-V:installvendorlib)
  26. PERL_ARCHLIB = path to the core arch lib install directory (-V:archlib)
  27. PERL_PRIVLIB = path to the core priv lib install directory (-V:privlib)
  28. PERL_UPDATE_ARCHLIB = path to the update arch lib install directory (-V:installarchlib)
  29. PERL_UPDATE_PRIVLIB = path to the update priv lib install directory (-V:installprivlib)
  30. PERL_EXTRA_C_FLAGS = Compilation flags used to build perl
  31. #]=======================================================================]
  32. # find the perl executable
  33. include(${CMAKE_CURRENT_LIST_DIR}/FindPerl.cmake)
  34. if (PERL_EXECUTABLE)
  35. function (perl_get_info _pgi_info tag)
  36. cmake_parse_arguments(_PGI "IS_PATH" "" "" ${ARGN})
  37. set (${_pgi_info} NOTFOUND PARENT_SCOPE)
  38. execute_process(COMMAND "${PERL_EXECUTABLE}" -V:${tag}
  39. OUTPUT_VARIABLE result
  40. RESULT_VARIABLE status)
  41. if (NOT status)
  42. string(REGEX REPLACE "${tag}='([^']*)'.*" "\\1" result "${result}")
  43. if (_PGI_IS_PATH)
  44. file(TO_CMAKE_PATH "${result}" result)
  45. endif()
  46. set (${_pgi_info} "${result}" PARENT_SCOPE)
  47. endif ()
  48. endfunction()
  49. ### PERL_PREFIX
  50. perl_get_info(PERL_PREFIX prefix IS_PATH)
  51. ### PERL_ARCHNAME
  52. perl_get_info(PERL_ARCHNAME archname)
  53. ### PERL_EXTRA_C_FLAGS
  54. perl_get_info(PERL_EXTRA_C_FLAGS cppflags)
  55. ### PERL_SITESEARCH
  56. perl_get_info(PERL_SITESEARCH installsitesearch IS_PATH)
  57. ### PERL_SITEARCH
  58. perl_get_info(PERL_SITEARCH installsitearch IS_PATH)
  59. ### PERL_SITELIB
  60. perl_get_info(PERL_SITELIB installsitelib IS_PATH)
  61. ### PERL_VENDORARCH
  62. perl_get_info(PERL_VENDORARCH installvendorarch IS_PATH)
  63. ### PERL_VENDORLIB
  64. perl_get_info(PERL_VENDORLIB installvendorlib IS_PATH)
  65. ### PERL_ARCHLIB
  66. perl_get_info(PERL_ARCHLIB archlib IS_PATH)
  67. ### PERL_PRIVLIB
  68. perl_get_info(PERL_PRIVLIB privlib IS_PATH)
  69. ### PERL_UPDATE_ARCHLIB
  70. perl_get_info(PERL_UPDATE_ARCHLIB installarchlib IS_PATH)
  71. ### PERL_UPDATE_PRIVLIB
  72. perl_get_info(PERL_UPDATE_PRIVLIB installprivlib IS_PATH)
  73. ### PERL_POSSIBLE_LIBRARY_NAMES
  74. perl_get_info(PERL_POSSIBLE_LIBRARY_NAMES libperl)
  75. if (NOT PERL_POSSIBLE_LIBRARY_NAMES)
  76. set(PERL_POSSIBLE_LIBRARY_NAMES perl${PERL_VERSION_STRING} perl)
  77. endif()
  78. if (CMAKE_SYSTEM_NAME MATCHES "MSYS|CYGWIN")
  79. # on MSYS and CYGWIN environments, current perl -V:libperl gives shared library name
  80. # rather than the import library. So, extends possible library names
  81. list (APPEND PERL_POSSIBLE_LIBRARY_NAMES perl)
  82. endif()
  83. ### PERL_INCLUDE_PATH
  84. find_path(PERL_INCLUDE_PATH
  85. NAMES
  86. perl.h
  87. PATHS
  88. "${PERL_UPDATE_ARCHLIB}/CORE"
  89. "${PERL_ARCHLIB}/CORE"
  90. /usr/lib/perl5/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
  91. /usr/lib/perl/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
  92. /usr/lib/perl5/${PERL_VERSION_STRING}/CORE
  93. /usr/lib/perl/${PERL_VERSION_STRING}/CORE
  94. )
  95. ### PERL_LIBRARY
  96. find_library(PERL_LIBRARY
  97. NAMES
  98. ${PERL_POSSIBLE_LIBRARY_NAMES}
  99. PATHS
  100. "${PERL_UPDATE_ARCHLIB}/CORE"
  101. "${PERL_ARCHLIB}/CORE"
  102. /usr/lib/perl5/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
  103. /usr/lib/perl/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
  104. /usr/lib/perl5/${PERL_VERSION_STRING}/CORE
  105. /usr/lib/perl/${PERL_VERSION_STRING}/CORE
  106. )
  107. endif ()
  108. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  109. find_package_handle_standard_args(PerlLibs REQUIRED_VARS PERL_LIBRARY PERL_INCLUDE_PATH
  110. VERSION_VAR PERL_VERSION_STRING)
  111. # Introduced after CMake 2.6.4 to bring module into compliance
  112. set(PERL_INCLUDE_DIR ${PERL_INCLUDE_PATH})
  113. set(PERL_INCLUDE_DIRS ${PERL_INCLUDE_PATH})
  114. set(PERL_LIBRARIES ${PERL_LIBRARY})
  115. # For backward compatibility with CMake before 2.8.8
  116. set(PERL_VERSION ${PERL_VERSION_STRING})
  117. mark_as_advanced(
  118. PERL_INCLUDE_PATH
  119. PERL_LIBRARY
  120. )