1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
10 This module finds if PERL is installed and determines where the
11 include files and libraries are. It also determines what the name of
12 the library is. This code sets the following variables:
16 PERLLIBS_FOUND = True if perl.h & libperl were found
17 PERL_INCLUDE_PATH = path to where perl.h is found
18 PERL_LIBRARY = path to libperl
19 PERL_EXECUTABLE = full path to the perl binary
23 The minimum required version of Perl can be specified using the
24 standard syntax, e.g. find_package(PerlLibs 6.0)
28 The following variables are also available if needed
29 (introduced after CMake 2.6.4)
35 PERL_SITESEARCH = path to the sitesearch install dir (-V:installsitesearch)
36 PERL_SITEARCH = path to the sitelib install directory (-V:installsitearch)
37 PERL_SITELIB = path to the sitelib install directory (-V:installsitelib)
38 PERL_VENDORARCH = path to the vendor arch install directory (-V:installvendorarch)
39 PERL_VENDORLIB = path to the vendor lib install directory (-V:installvendorlib)
40 PERL_ARCHLIB = path to the core arch lib install directory (-V:archlib)
41 PERL_PRIVLIB = path to the core priv lib install directory (-V:privlib)
42 PERL_UPDATE_ARCHLIB = path to the update arch lib install directory (-V:installarchlib)
43 PERL_UPDATE_PRIVLIB = path to the update priv lib install directory (-V:installprivlib)
44 PERL_EXTRA_C_FLAGS = Compilation flags used to build perl
45 #]=======================================================================]
47 # find the perl executable
48 include(${CMAKE_CURRENT_LIST_DIR}/FindPerl.cmake)
52 function (perl_get_info _pgi_info tag)
53 cmake_parse_arguments(_PGI "IS_PATH" "" "" ${ARGN})
55 set (${_pgi_info} NOTFOUND PARENT_SCOPE)
57 execute_process(COMMAND "${PERL_EXECUTABLE}" -V:${tag}
58 OUTPUT_VARIABLE result
59 RESULT_VARIABLE status)
62 string(REGEX REPLACE "${tag}='([^']*)'.*" "\\1" result "${result}")
64 file(TO_CMAKE_PATH "${result}" result)
66 set (${_pgi_info} "${result}" PARENT_SCOPE)
71 perl_get_info(PERL_PREFIX prefix IS_PATH)
74 perl_get_info(PERL_ARCHNAME archname)
76 ### PERL_EXTRA_C_FLAGS
77 perl_get_info(PERL_EXTRA_C_FLAGS cppflags)
80 perl_get_info(PERL_SITESEARCH installsitesearch IS_PATH)
83 perl_get_info(PERL_SITEARCH installsitearch IS_PATH)
86 perl_get_info(PERL_SITELIB installsitelib IS_PATH)
89 perl_get_info(PERL_VENDORARCH installvendorarch IS_PATH)
92 perl_get_info(PERL_VENDORLIB installvendorlib IS_PATH)
95 perl_get_info(PERL_ARCHLIB archlib IS_PATH)
98 perl_get_info(PERL_PRIVLIB privlib IS_PATH)
100 ### PERL_UPDATE_ARCHLIB
101 perl_get_info(PERL_UPDATE_ARCHLIB installarchlib IS_PATH)
103 ### PERL_UPDATE_PRIVLIB
104 perl_get_info(PERL_UPDATE_PRIVLIB installprivlib IS_PATH)
106 ### PERL_POSSIBLE_LIBRARY_NAMES
107 perl_get_info(PERL_POSSIBLE_LIBRARY_NAMES libperl)
108 if (NOT PERL_POSSIBLE_LIBRARY_NAMES)
109 set(PERL_POSSIBLE_LIBRARY_NAMES perl${PERL_VERSION_STRING} perl)
111 if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN")
112 list (APPEND PERL_POSSIBLE_LIBRARY_NAMES perl${PERL_VERSION_STRING})
114 if (CMAKE_SYSTEM_NAME MATCHES "MSYS|CYGWIN")
115 # on MSYS and CYGWIN environments, current perl -V:libperl gives shared library name
116 # rather than the import library. So, extends possible library names
117 list (APPEND PERL_POSSIBLE_LIBRARY_NAMES perl)
120 ### PERL_INCLUDE_PATH
121 find_path(PERL_INCLUDE_PATH
125 "${PERL_UPDATE_ARCHLIB}/CORE"
126 "${PERL_ARCHLIB}/CORE"
127 /usr/lib/perl5/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
128 /usr/lib/perl/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
129 /usr/lib/perl5/${PERL_VERSION_STRING}/CORE
130 /usr/lib/perl/${PERL_VERSION_STRING}/CORE
134 find_library(PERL_LIBRARY
136 ${PERL_POSSIBLE_LIBRARY_NAMES}
138 "${PERL_UPDATE_ARCHLIB}/CORE"
139 "${PERL_ARCHLIB}/CORE"
140 /usr/lib/perl5/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
141 /usr/lib/perl/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE
142 /usr/lib/perl5/${PERL_VERSION_STRING}/CORE
143 /usr/lib/perl/${PERL_VERSION_STRING}/CORE
148 include(FindPackageHandleStandardArgs)
149 find_package_handle_standard_args(PerlLibs REQUIRED_VARS PERL_LIBRARY PERL_INCLUDE_PATH
150 VERSION_VAR PERL_VERSION_STRING)
152 # Introduced after CMake 2.6.4 to bring module into compliance
153 set(PERL_INCLUDE_DIR ${PERL_INCLUDE_PATH})
154 set(PERL_INCLUDE_DIRS ${PERL_INCLUDE_PATH})
155 set(PERL_LIBRARIES ${PERL_LIBRARY})
156 # For backward compatibility with CMake before 2.8.8
157 set(PERL_VERSION ${PERL_VERSION_STRING})