FindPerlLibs.cmake
Go to the documentation of this file.
1 ##############################################################################
2 # @file FindPerlLibs.cmake
3 # @brief Find Perl libraries. Fixes issue with CMake's default FindPerlLibs.
4 #
5 # @sa http://www.cmake.org/pipermail/cmake/2008-July/022638.html
6 #
7 # @ingroup CMakeFindModules
8 ##############################################################################
9 
10 #=============================================================================
11 # Copyright 2011-2012 University of Pennsylvania
12 # Copyright 2013-2016 Andreas Schuh <andreas.schuh.84@gmail.com>
13 #
14 # Distributed under the OSI-approved BSD License (the "License");
15 # see accompanying file Copyright.txt for details.
16 #
17 # This software is distributed WITHOUT ANY WARRANTY; without even the
18 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 # See the License for more information.
20 #=============================================================================
21 # (To distribute this file outside of CMake, substitute the full
22 # License text for the above reference.)
23 
24 # ----------------------------------------------------------------------------
25 # use CMake's FindPerlLibs.cmake module
26 set (PerlLibs_FIND_REQUIRED_BACKUP "${PerlLibs_FIND_REQUIRED}")
27 set (PerlLibs_FIND_QUIETLY_BACKUP "${PerlLibs_FIND_QUIETLY}")
30 
31 include ("${CMAKE_ROOT}/Modules/FindPerlLibs.cmake")
32 
34 set (PerlLibs_FIND_QUIETLY "${PerlLibs_FIND_QUIETLY_BACKUP}")
35 unset (PerlLibs_FIND_REQUIRED_BACKUP)
36 unset (PerlLibs_FIND_QUIETLY_BACKUP)
37 
38 # ----------------------------------------------------------------------------
39 # try to fix any issues
40 if (PERL_EXECUTABLE)
41  execute_process (
42  COMMAND "${PERL_EXECUTABLE}" -MConfig -e "print \$Config{version}"
43  OUTPUT_VARIABLE PERL_OUTPUT
44  RESULT_VARIABLE PERL_RETURN_VALUE
45  )
46  if (PERL_RETURN_VALUE EQUAL 0)
47  set (PERL_VERSION_STRING ${PERL_OUTPUT})
48  endif ()
49  if (PERL_VERSION_STRING MATCHES "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
50  set (PERL_VERSION_MAJOR "${CMAKE_MATCH_1}")
51  set (PERL_VERSION_MINOR "${CMAKE_MATCH_2}")
52  set (PERL_VERSION_PATCH "${CMAKE_MATCH_3}")
53  else ()
54  message (WARNING "Perl interpreter version string has unexpected format: ${PERL_VERSION_STRING}")
55  endif ()
56 
57  # try to fix failure in PERL_INCLUDE_PATH
58  if (PERL_INCLUDE_PATH MATCHES ".*-NOTFOUND")
59  execute_process (
60  COMMAND "${PERL_EXECUTABLE}" -MConfig -e "print \$Config{archlibexp}"
61  OUTPUT_VARIABLE PERL_OUTPUT
62  RESULT_VARIABLE PERL_RETURN_VALUE
63  )
64  if (NOT PERL_RETURN_VALUE)
65  find_path (PERL_INCLUDE_PATH perl.h "${PERL_OUTPUT}/CORE")
66  endif ()
67  endif ()
68 
69  # try to fix failure in PERL_LIBRARY
70  IF (PERL_LIBRARY MATCHES ".*-NOTFOUND")
71  execute_process (
72  COMMAND "${PERL_EXECUTABLE}" -MConfig -e "print \$Config{libperl}"
73  OUTPUT_VARIABLE PERL_OUTPUT
74  RESULT_VARIABLE PERL_RETURN_VALUE
75  )
76  if (NOT PERL_RETURN_VALUE)
77  find_library (PERL_LIBRARY NAMES "${PERL_OUTPUT}" PATHS "${PERL_INCLUDE_PATH}")
78  endif ()
79  endif ()
80 
81  # unset local variables
82  unset (PERL_OUTPUT)
83  unset (PERL_RETURN_VALUE)
84 endif ()
85 
86 # ----------------------------------------------------------------------------
87 # handle the QUIETLY and REQUIRED arguments and set *_FOUND to TRUE
88 # if all listed variables are found or TRUE
89 include (FindPackageHandleStandardArgs)
90 
91 find_package_handle_standard_args (
92  PerlLibs
93  REQUIRED_VARS
94  PERL_LIBRARY
95  PERL_INCLUDE_PATH
96  VERSION_VAR
97  PERL_VERSION_STRING
98 )
99 
100 if (NOT DEFINED PerlLibs_FOUND AND DEFINED PERLLIBS_FOUND)
101  set (PerlLibs_FOUND "${PERLLIBS_FOUND}")
102 endif ()
103 
104 # ----------------------------------------------------------------------------
105 # map names of variables from upper-case prefix to case-sensitive prefix
106 #
107 # This is normally automatically done by CMake BASIS find_package,
108 # but because "PerlLibs" sets variables also for "Perl" by *including*
109 # the FindPerl module, we have to do it here explicitly at least for
110 # those variables which are set by the FindPerl module.
111 if (NOT DEFINED Perl_FOUND AND DEFINED PERL_FOUND)
112  set (Perl_FOUND "${PERL_FOUND}")
113 endif ()
114 
115 if (Perl_FOUND)
116  set (Perl_EXECUTABLE "${PERL_EXECUTABLE}")
117  set (Perl_VERSION_MAJOR "${PERL_VERSION_MAJOR}")
118  set (Perl_VERSION_MINOR "${PERL_VERSION_MINOR}")
119  set (Perl_VERSION_PATCH "${PERL_VERSION_PATCH}")
120  set (Perl_VERSION_STRING "${PERL_VERSION_STRING}")
121 endif ()
122 
123 if (PerlLibs_FOUND)
124  set (PerlLibs_LIBRARY "${PERL_LIBRARY}")
125  set (PerlLibs_INCLUDE_DIR "${PERL_INCLUDE_PATH}")
126  set (PerlLibs_VERSION_MAJOR "${PERL_VERSION_MAJOR}")
127  set (PerlLibs_VERSION_MINOR "${PERL_VERSION_MINOR}")
128  set (PerlLibs_VERSION_PATCH "${PERL_VERSION_PATCH}")
129  set (PerlLibs_VERSION_STRING "${PERL_VERSION_STRING}")
130 endif ()
cmake PERL_VERSION_MINOR
cmake PerlLibs_FIND_REQUIRED_BACKUP
cmake PerlLibs_FIND_QUIETLY
cmake PERL_VERSION_MAJOR
cmake PerlLibs_FIND_QUIETLY_BACKUP
cmake PERL_VERSION_PATCH
cmake PerlLibs_FIND_REQUIRED
cmake PERL_VERSION_STRING