1
# FindPythonLibrary.cmake
2
# ~~~~~~~~~~~~~~~~~~~~~~~
3
# Find the Python interpreter and related Python directories.
5
# This file defines the following variables:
7
# PYTHON_EXECUTABLE - The path and filename of the Python interpreter.
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))
12
# PYTHON_LONG_VERSION - The version of the Python interpreter found as a human
15
# PYTHON_SITE_PACKAGES_DIR - Location of the Python site-packages directory.
17
# PYTHON_INCLUDE_PATH - Directory holding the python.h include file.
19
# PYTHON_LIBRARY, PYTHON_LIBRARIES- Location of the Python library.
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.
25
INCLUDE(CMakeFindFrameworks)
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)
33
if(PYTHONINTERP_FOUND)
34
FIND_FILE(_find_lib_python_py FindLibPython.py PATHS ${CMAKE_MODULE_PATH})
36
EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_lib_python_py} OUTPUT_VARIABLE 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})
46
STRING(REPLACE "\\" "/" PYTHON_SITE_PACKAGES_DIR ${PYTHON_SITE_PACKAGES_DIR})
48
FIND_LIBRARY(PYTHON_LIBRARY NAMES ${PYTHON_LIBRARY_NAMES} PATHS ${PYTHON_PREFIX}/lib ${PYTHON_PREFIX}/libs NO_DEFAULT_PATH)
49
set(PYTHONLIBRARY_FOUND TRUE)
52
# adapted from cmake's builtin FindPythonLibs
54
CMAKE_FIND_FRAMEWORKS(Python)
55
set(PYTHON_FRAMEWORK_INCLUDES)
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)
69
endif(PYTHONINTERP_FOUND)
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)
83
endif (EXISTS PYTHON_LIBRARY)