FindPerlLibs.cmake 5.03 KB
Newer Older
1 2 3
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#[=======================================================================[.rst:
FindPerlLibs
------------

Find Perl libraries

This module finds if PERL is installed and determines where the
include files and libraries are.  It also determines what the name of
the library is.  This code sets the following variables:

::

  PERLLIBS_FOUND    = True if perl.h & libperl were found
  PERL_INCLUDE_PATH = path to where perl.h is found
  PERL_LIBRARY      = path to libperl
  PERL_EXECUTABLE   = full path to the perl binary



The minimum required version of Perl can be specified using the
standard syntax, e.g.  find_package(PerlLibs 6.0)

::

  The following variables are also available if needed
  (introduced after CMake 2.6.4)



::

  PERL_SITESEARCH     = path to the sitesearch install dir (-V:installsitesearch)
  PERL_SITEARCH       = path to the sitelib install directory (-V:installsitearch)
  PERL_SITELIB        = path to the sitelib install directory (-V:installsitelib)
  PERL_VENDORARCH     = path to the vendor arch install directory (-V:installvendorarch)
  PERL_VENDORLIB      = path to the vendor lib install directory (-V:installvendorlib)
  PERL_ARCHLIB        = path to the core arch lib install directory (-V:archlib)
  PERL_PRIVLIB        = path to the core priv lib install directory (-V:privlib)
  PERL_UPDATE_ARCHLIB = path to the update arch lib install directory (-V:installarchlib)
  PERL_UPDATE_PRIVLIB = path to the update priv lib install directory (-V:installprivlib)
  PERL_EXTRA_C_FLAGS = Compilation flags used to build perl
#]=======================================================================]
46 47

# find the perl executable
48
include(${CMAKE_CURRENT_LIST_DIR}/FindPerl.cmake)
49

50
if (PERL_EXECUTABLE)
51

52 53
  function (perl_get_info _pgi_info tag)
    cmake_parse_arguments(_PGI "IS_PATH" "" "" ${ARGN})
54

55
    set (${_pgi_info} NOTFOUND PARENT_SCOPE)
56

57 58 59
    execute_process(COMMAND "${PERL_EXECUTABLE}" -V:${tag}
      OUTPUT_VARIABLE result
      RESULT_VARIABLE status)
60

61 62 63 64 65 66 67 68 69 70 71 72 73 74
    if (NOT status)
      string(REGEX REPLACE "${tag}='([^']*)'.*" "\\1" result "${result}")
      if (_PGI_IS_PATH)
        file(TO_CMAKE_PATH "${result}" result)
      endif()
      set (${_pgi_info} "${result}" PARENT_SCOPE)
    endif ()
  endfunction()

  ### PERL_PREFIX
  perl_get_info(PERL_PREFIX prefix IS_PATH)

  ### PERL_ARCHNAME
  perl_get_info(PERL_ARCHNAME archname)
75

76
  ### PERL_EXTRA_C_FLAGS
77
  perl_get_info(PERL_EXTRA_C_FLAGS cppflags)
78 79

  ### PERL_SITESEARCH
80 81 82 83
  perl_get_info(PERL_SITESEARCH installsitesearch IS_PATH)

  ### PERL_SITEARCH
  perl_get_info(PERL_SITEARCH installsitearch IS_PATH)
84 85

  ### PERL_SITELIB
86
  perl_get_info(PERL_SITELIB installsitelib IS_PATH)
87 88

  ### PERL_VENDORARCH
89
  perl_get_info(PERL_VENDORARCH installvendorarch IS_PATH)
90 91

  ### PERL_VENDORLIB
92
  perl_get_info(PERL_VENDORLIB installvendorlib IS_PATH)
93 94

  ### PERL_ARCHLIB
95
  perl_get_info(PERL_ARCHLIB archlib IS_PATH)
96 97

  ### PERL_PRIVLIB
98
  perl_get_info(PERL_PRIVLIB privlib IS_PATH)
99

100
  ### PERL_UPDATE_ARCHLIB
101
  perl_get_info(PERL_UPDATE_ARCHLIB installarchlib IS_PATH)
102 103

  ### PERL_UPDATE_PRIVLIB
104
  perl_get_info(PERL_UPDATE_PRIVLIB installprivlib IS_PATH)
105

106
  ### PERL_POSSIBLE_LIBRARY_NAMES
107 108
  perl_get_info(PERL_POSSIBLE_LIBRARY_NAMES libperl)
  if (NOT PERL_POSSIBLE_LIBRARY_NAMES)
109
    set(PERL_POSSIBLE_LIBRARY_NAMES perl${PERL_VERSION_STRING} perl)
110
  endif()
111 112 113 114 115
  if (CMAKE_SYSTEM_NAME MATCHES "MSYS|CYGWIN")
    # on MSYS and CYGWIN environments, current perl -V:libperl gives shared library name
    # rather than the import library. So, extends possible library names
    list (APPEND PERL_POSSIBLE_LIBRARY_NAMES perl)
  endif()
116 117 118 119 120 121

  ### PERL_INCLUDE_PATH
  find_path(PERL_INCLUDE_PATH
    NAMES
      perl.h
    PATHS
122 123
      "${PERL_UPDATE_ARCHLIB}/CORE"
      "${PERL_ARCHLIB}/CORE"
124 125 126 127
      /usr/lib/perl5/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
      /usr/lib/perl/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
      /usr/lib/perl5/${PERL_VERSION_STRING}/CORE
      /usr/lib/perl/${PERL_VERSION_STRING}/CORE
128
  )
129

130 131 132
  ### PERL_LIBRARY
  find_library(PERL_LIBRARY
    NAMES
133
      ${PERL_POSSIBLE_LIBRARY_NAMES}
134
    PATHS
135 136
      "${PERL_UPDATE_ARCHLIB}/CORE"
      "${PERL_ARCHLIB}/CORE"
137 138 139 140
      /usr/lib/perl5/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
      /usr/lib/perl/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
      /usr/lib/perl5/${PERL_VERSION_STRING}/CORE
      /usr/lib/perl/${PERL_VERSION_STRING}/CORE
141 142
  )

143
endif ()
144

145
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
146
find_package_handle_standard_args(PerlLibs REQUIRED_VARS PERL_LIBRARY PERL_INCLUDE_PATH
147
                                           VERSION_VAR PERL_VERSION_STRING)
148

149 150 151 152
# Introduced after CMake 2.6.4 to bring module into compliance
set(PERL_INCLUDE_DIR  ${PERL_INCLUDE_PATH})
set(PERL_INCLUDE_DIRS ${PERL_INCLUDE_PATH})
set(PERL_LIBRARIES    ${PERL_LIBRARY})
153
# For backward compatibility with CMake before 2.8.8
154
set(PERL_VERSION ${PERL_VERSION_STRING})
155

156
mark_as_advanced(
157 158
  PERL_INCLUDE_PATH
  PERL_LIBRARY
159
)