Merge topic 'cpack-innosetup-linux'
[kiteware-cmake.git] / Modules / FindPerlLibs.cmake
blobd576b86cd50c71248b9b548ebed5b0286a589f30
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:
5 FindPerlLibs
6 ------------
8 Find Perl libraries
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)
50 if (PERL_EXECUTABLE)
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)
61     if (NOT status)
62       string(REGEX REPLACE "${tag}='([^']*)'.*" "\\1" result "${result}")
63       if (_PGI_IS_PATH)
64         file(TO_CMAKE_PATH "${result}" result)
65       endif()
66       set (${_pgi_info} "${result}" PARENT_SCOPE)
67     endif ()
68   endfunction()
70   ### PERL_PREFIX
71   perl_get_info(PERL_PREFIX prefix IS_PATH)
73   ### PERL_ARCHNAME
74   perl_get_info(PERL_ARCHNAME archname)
76   ### PERL_EXTRA_C_FLAGS
77   perl_get_info(PERL_EXTRA_C_FLAGS cppflags)
79   ### PERL_SITESEARCH
80   perl_get_info(PERL_SITESEARCH installsitesearch IS_PATH)
82   ### PERL_SITEARCH
83   perl_get_info(PERL_SITEARCH installsitearch IS_PATH)
85   ### PERL_SITELIB
86   perl_get_info(PERL_SITELIB installsitelib IS_PATH)
88   ### PERL_VENDORARCH
89   perl_get_info(PERL_VENDORARCH installvendorarch IS_PATH)
91   ### PERL_VENDORLIB
92   perl_get_info(PERL_VENDORLIB installvendorlib IS_PATH)
94   ### PERL_ARCHLIB
95   perl_get_info(PERL_ARCHLIB archlib IS_PATH)
97   ### PERL_PRIVLIB
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)
110   endif()
111   if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN")
112     list (APPEND PERL_POSSIBLE_LIBRARY_NAMES perl${PERL_VERSION_STRING})
113   endif()
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)
118   endif()
120   ### PERL_INCLUDE_PATH
121   find_path(PERL_INCLUDE_PATH
122     NAMES
123       perl.h
124     PATHS
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
131   )
133   ### PERL_LIBRARY
134   find_library(PERL_LIBRARY
135     NAMES
136       ${PERL_POSSIBLE_LIBRARY_NAMES}
137     PATHS
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
144   )
146 endif ()
148 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
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})
159 mark_as_advanced(
160   PERL_INCLUDE_PATH
161   PERL_LIBRARY