正在显示
1 个修改的文件
包含
118 行增加
和
0 行删除
cmake/FindPythonLibrary.cmake
0 → 100644
1 | +# Find Python | ||
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 | + | ||
26 | + | ||
27 | +INCLUDE(CMakeFindFrameworks) | ||
28 | + | ||
29 | +if(EXISTS "${PYTHON_INCLUDE_PATH}" AND EXISTS "${PYTHON_LIBRARY}" AND EXISTS "${PYTHON_SITE_PACKAGES_DIR}") | ||
30 | + # Already in cache, be silent | ||
31 | + set(PYTHONLIBRARY_FOUND TRUE) | ||
32 | +else(EXISTS "${PYTHON_INCLUDE_PATH}" AND EXISTS "${PYTHON_LIBRARY}" AND EXISTS "${PYTHON_SITE_PACKAGES_DIR}") | ||
33 | + | ||
34 | + FIND_PACKAGE(PythonInterp 3) | ||
35 | + | ||
36 | + if(PYTHONINTERP_FOUND) | ||
37 | + FIND_FILE(_find_lib_python_py FindLibPython.py PATHS ${CMAKE_MODULE_PATH} NO_CMAKE_FIND_ROOT_PATH) | ||
38 | + | ||
39 | + EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_lib_python_py} OUTPUT_VARIABLE python_config) | ||
40 | + if(python_config) | ||
41 | + STRING(REGEX REPLACE ".*exec_prefix:([^\n]+).*$" "\\1" PYTHON_PREFIX ${python_config}) | ||
42 | + STRING(REGEX REPLACE ".*\nshort_version:([^\n]+).*$" "\\1" PYTHON_SHORT_VERSION ${python_config}) | ||
43 | + STRING(REGEX REPLACE ".*\nlong_version:([^\n]+).*$" "\\1" PYTHON_LONG_VERSION ${python_config}) | ||
44 | + STRING(REGEX REPLACE ".*\npy_inc_dir:([^\n]+).*$" "\\1" PYTHON_INCLUDE_PATH ${python_config}) | ||
45 | + if(NOT PYTHON_SITE_PACKAGES_DIR) | ||
46 | + if(NOT PYTHON_LIBS_WITH_KDE_LIBS) | ||
47 | + STRING(REGEX REPLACE ".*\nsite_packages_dir:([^\n]+).*$" "\\1" PYTHON_SITE_PACKAGES_DIR ${python_config}) | ||
48 | + else(NOT PYTHON_LIBS_WITH_KDE_LIBS) | ||
49 | + set(PYTHON_SITE_PACKAGES_DIR ${KDE4_LIB_INSTALL_DIR}/python${PYTHON_SHORT_VERSION}/site-packages) | ||
50 | + endif(NOT PYTHON_LIBS_WITH_KDE_LIBS) | ||
51 | + endif(NOT PYTHON_SITE_PACKAGES_DIR) | ||
52 | + STRING(REGEX REPLACE "([0-9]+).([0-9]+)" "\\1\\2" PYTHON_SHORT_VERSION_NO_DOT ${PYTHON_SHORT_VERSION}) | ||
53 | + set(PYTHON_LIBRARY_NAMES python${PYTHON_SHORT_VERSION} python${PYTHON_SHORT_VERSION_NO_DOT} python${PYTHON_SHORT_VERSION}m python${PYTHON_SHORT_VERSION_NO_DOT}m) | ||
54 | + if(WIN32) | ||
55 | + STRING(REPLACE "\\" "/" PYTHON_SITE_PACKAGES_DIR ${PYTHON_SITE_PACKAGES_DIR}) | ||
56 | + FIND_LIBRARY(PYTHON_LIBRARY NAMES ${PYTHON_LIBRARY_NAMES} PATHS ${PYTHON_PREFIX}/lib ${PYTHON_PREFIX}/libs) | ||
57 | + endif(WIN32) | ||
58 | + FIND_LIBRARY(PYTHON_LIBRARY NAMES ${PYTHON_LIBRARY_NAMES}) | ||
59 | + set(PYTHON_INCLUDE_PATH ${PYTHON_INCLUDE_PATH} CACHE FILEPATH "Directory holding the python.h include file" FORCE) | ||
60 | + set(PYTHONLIBRARY_FOUND TRUE) | ||
61 | + endif(python_config) | ||
62 | + | ||
63 | + # adapted from cmake's builtin FindPythonLibs | ||
64 | + if(APPLE) | ||
65 | + # If a framework has been detected in the include path, make sure | ||
66 | + # framework's versioned library (not any .dylib) is used for linking | ||
67 | + # NOTE: don't rely upon Python.framework/Versions/Current, since that may be 2.7 | ||
68 | + if("${PYTHON_INCLUDE_PATH}" MATCHES "Python\\.framework") | ||
69 | + set(PYTHON_LIBRARY "") | ||
70 | + set(PYTHON_DEBUG_LIBRARY "") | ||
71 | + # get clean path to just framework | ||
72 | + STRING(REGEX REPLACE "^(.*/Python\\.framework).*$" "\\1" _py_fw "${PYTHON_INCLUDE_PATH}") | ||
73 | + if("${_py_fw}" MATCHES "Cellar/python") | ||
74 | + # Appears to be a Homebrew Python install; do specific fix ups | ||
75 | + # get Homebrew prefix (may not be /usr/local) | ||
76 | + STRING(REGEX REPLACE "^(.+)/Cellar.*$" "\\1" _hb_prefix "${_py_fw}") | ||
77 | + # prefer the Homebrew prefix framework over only versioned Python keg | ||
78 | + set(_py_fw "${_hb_prefix}/Frameworks/Python.framework") | ||
79 | + # prefer the symlinked-to Homebrew site-packages over only versioned Python keg | ||
80 | + set(PYTHON_SITE_PACKAGES_DIR "${_hb_prefix}/lib/python${PYTHON_SHORT_VERSION}/site-packages") | ||
81 | + endif("${_py_fw}" MATCHES "Cellar/python") | ||
82 | + # prefer the Headers subdirectory for includes | ||
83 | + if(EXISTS "${_py_fw}/Versions/${PYTHON_SHORT_VERSION}/Headers") | ||
84 | + set(PYTHON_INCLUDE_PATH "${_py_fw}/Versions/${PYTHON_SHORT_VERSION}/Headers" CACHE FILEPATH "Directory holding the python.h include file" FORCE) | ||
85 | + endif(EXISTS "${_py_fw}/Versions/${PYTHON_SHORT_VERSION}/Headers") | ||
86 | + endif("${PYTHON_INCLUDE_PATH}" MATCHES "Python\\.framework") | ||
87 | + if(NOT PYTHON_LIBRARY) | ||
88 | + # ensure the versioned framework's library is defined, instead of relying upon -F search paths | ||
89 | + if(EXISTS "${_py_fw}/Versions/${PYTHON_SHORT_VERSION}/Python") | ||
90 | + set(PYTHON_LIBRARY "${_py_fw}/Versions/${PYTHON_SHORT_VERSION}/Python" CACHE FILEPATH "Python framework library" FORCE) | ||
91 | + endif(EXISTS "${_py_fw}/Versions/${PYTHON_SHORT_VERSION}/Python") | ||
92 | + endif(NOT PYTHON_LIBRARY) | ||
93 | + if(PYTHON_LIBRARY) | ||
94 | + set(PYTHONLIBRARY_FOUND TRUE) | ||
95 | + endif(PYTHON_LIBRARY) | ||
96 | + endif(APPLE) | ||
97 | + endif(PYTHONINTERP_FOUND) | ||
98 | + | ||
99 | + if(PYTHONLIBRARY_FOUND) | ||
100 | + if(APPLE) | ||
101 | + # keep reference to system or custom python site-packages | ||
102 | + # useful during app-bundling operations | ||
103 | + set(PYTHON_SITE_PACKAGES_SYS ${PYTHON_SITE_PACKAGES_DIR} CACHE FILEPATH "Directory holding Python site packages") | ||
104 | + endif(APPLE) | ||
105 | + set(PYTHON_LIBRARIES ${PYTHON_LIBRARY}) | ||
106 | + if(NOT PYTHONLIBRARY_FIND_QUIETLY) | ||
107 | + message(STATUS "Found Python executable: ${PYTHON_EXECUTABLE}") | ||
108 | + message(STATUS "Found Python version: ${PYTHON_LONG_VERSION}") | ||
109 | + message(STATUS "Found Python library: ${PYTHON_LIBRARY}") | ||
110 | + message(STATUS "Found Python site-packages: ${PYTHON_SITE_PACKAGES_DIR}") | ||
111 | + endif(NOT PYTHONLIBRARY_FIND_QUIETLY) | ||
112 | + else(PYTHONLIBRARY_FOUND) | ||
113 | + if(PYTHONLIBRARY_FIND_REQUIRED) | ||
114 | + message(FATAL_ERROR "Could not find Python") | ||
115 | + endif(PYTHONLIBRARY_FIND_REQUIRED) | ||
116 | + endif(PYTHONLIBRARY_FOUND) | ||
117 | + | ||
118 | +endif (EXISTS "${PYTHON_INCLUDE_PATH}" AND EXISTS "${PYTHON_LIBRARY}" AND EXISTS "${PYTHON_SITE_PACKAGES_DIR}") |
请
注册
或
登录
后发表评论