~telepathy-kde/telepathy-kde/telepathy-logger-qt

« back to all changes in this revision

Viewing changes to cmake/modules/FindPythonLibrary.cmake

  • Committer: Alexander Akulich
  • Date: 2019-10-03 20:28:29 UTC
  • Revision ID: git-v1:cae0e0254e88899e83bc707a6caf69e7b414aa46
CMake: Remove own FindPython modules, use standard FindPython3 instead

Summary:
- Do not rename PYTHON_EXECUTABLE variable to give a room for Python4 update.

This revision depends on D24065.

Test Plan: Configure and build in a clean environment.

Reviewers: #kde_telepathy, davidedmundson, apol, heikobecker

Reviewed By: apol, heikobecker

Tags: #kde_telepathy

Differential Revision: https://phabricator.kde.org/D24066

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# FindPythonLibrary.cmake
2
 
# ~~~~~~~~~~~~~~~~~~~~~~~
3
 
# Find the Python interpreter and related Python directories.
4
 
#
5
 
# This file defines the following variables:
6
 
7
 
# PYTHON_EXECUTABLE - The path and filename of the Python interpreter.
8
 
#
9
 
# PYTHON_SHORT_VERSION - The version of the Python interpreter found,
10
 
#     excluding the patch version number. (e.g. 2.5 and not 2.5.1))
11
 
12
 
# PYTHON_LONG_VERSION - The version of the Python interpreter found as a human
13
 
#     readable string.
14
 
#
15
 
# PYTHON_SITE_PACKAGES_DIR - Location of the Python site-packages directory.
16
 
#
17
 
# PYTHON_INCLUDE_PATH - Directory holding the python.h include file.
18
 
#
19
 
# PYTHON_LIBRARY, PYTHON_LIBRARIES- Location of the Python library.
20
 
 
21
 
# Copyright (c) 2007, Simon Edwards <simon@simonzone.com>
22
 
# Redistribution and use is allowed according to the terms of the BSD license.
23
 
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
24
 
 
25
 
INCLUDE(CMakeFindFrameworks)
26
 
 
27
 
if(EXISTS PYTHON_LIBRARY)
28
 
  # Already in cache, be silent
29
 
  set(PYTHONLIBRARY_FOUND TRUE)
30
 
else(EXISTS PYTHON_LIBRARY)
31
 
  FIND_PACKAGE(PythonInterp)
32
 
 
33
 
  if(PYTHONINTERP_FOUND)
34
 
    FIND_FILE(_find_lib_python_py FindLibPython.py PATHS ${CMAKE_MODULE_PATH})
35
 
 
36
 
    EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_lib_python_py} OUTPUT_VARIABLE python_config)
37
 
    if(python_config)
38
 
      STRING(REGEX REPLACE ".*exec_prefix:([^\n]+).*$" "\\1" PYTHON_PREFIX ${python_config})
39
 
      STRING(REGEX REPLACE ".*\nshort_version:([^\n]+).*$" "\\1" PYTHON_SHORT_VERSION ${python_config})
40
 
      STRING(REGEX REPLACE ".*\nlong_version:([^\n]+).*$" "\\1" PYTHON_LONG_VERSION ${python_config})
41
 
      STRING(REGEX REPLACE ".*\npy_inc_dir:([^\n]+).*$" "\\1" PYTHON_INCLUDE_PATH ${python_config})
42
 
      STRING(REGEX REPLACE ".*\nsite_packages_dir:([^\n]+).*$" "\\1" PYTHON_SITE_PACKAGES_DIR ${python_config})
43
 
      STRING(REGEX REPLACE "([0-9]+).([0-9]+)" "\\1\\2" PYTHON_SHORT_VERSION_NO_DOT ${PYTHON_SHORT_VERSION})
44
 
      set(PYTHON_LIBRARY_NAMES python${PYTHON_SHORT_VERSION} python${PYTHON_SHORT_VERSION_NO_DOT})
45
 
      if(WIN32)
46
 
          STRING(REPLACE "\\" "/" PYTHON_SITE_PACKAGES_DIR ${PYTHON_SITE_PACKAGES_DIR})
47
 
      endif(WIN32)
48
 
      FIND_LIBRARY(PYTHON_LIBRARY NAMES ${PYTHON_LIBRARY_NAMES} PATHS ${PYTHON_PREFIX}/lib ${PYTHON_PREFIX}/libs NO_DEFAULT_PATH)
49
 
      set(PYTHONLIBRARY_FOUND TRUE)
50
 
    endif(python_config)
51
 
 
52
 
    # adapted from cmake's builtin FindPythonLibs
53
 
    if(APPLE)
54
 
      CMAKE_FIND_FRAMEWORKS(Python)
55
 
      set(PYTHON_FRAMEWORK_INCLUDES)
56
 
      if(Python_FRAMEWORKS)
57
 
        # If a framework has been selected for the include path,
58
 
        # make sure "-framework" is used to link it.
59
 
        if("${PYTHON_INCLUDE_PATH}" MATCHES "Python\\.framework")
60
 
          set(PYTHON_LIBRARY "")
61
 
          set(PYTHON_DEBUG_LIBRARY "")
62
 
        endif("${PYTHON_INCLUDE_PATH}" MATCHES "Python\\.framework")
63
 
        if(NOT PYTHON_LIBRARY)
64
 
          set (PYTHON_LIBRARY "-framework Python" CACHE FILEPATH "Python Framework" FORCE)
65
 
        endif(NOT PYTHON_LIBRARY)
66
 
        set(PYTHONLIBRARY_FOUND TRUE)
67
 
      endif(Python_FRAMEWORKS)
68
 
    endif(APPLE)
69
 
  endif(PYTHONINTERP_FOUND)
70
 
 
71
 
  if(PYTHONLIBRARY_FOUND)
72
 
    set(PYTHON_LIBRARIES ${PYTHON_LIBRARY})
73
 
    if(NOT PYTHONLIBRARY_FIND_QUIETLY)
74
 
      message(STATUS "Found Python executable: ${PYTHON_EXECUTABLE}")
75
 
      message(STATUS "Found Python version: ${PYTHON_LONG_VERSION}")
76
 
    endif(NOT PYTHONLIBRARY_FIND_QUIETLY)
77
 
  else(PYTHONLIBRARY_FOUND)
78
 
    if(PYTHONLIBRARY_FIND_REQUIRED)
79
 
      message(FATAL_ERROR "Could not find Python")
80
 
    endif(PYTHONLIBRARY_FIND_REQUIRED)
81
 
  endif(PYTHONLIBRARY_FOUND)
82
 
 
83
 
endif (EXISTS PYTHON_LIBRARY)