3
# Copyright (c) 2007, Simon Edwards <simon@simonzone.com>
4
# Redistribution and use is allowed according to the terms of the BSD license.
5
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
7
# Find the Python interpreter and related Python directories.
9
# This file defines the following variables:
11
# PYTHON_EXECUTABLE - The path and filename of the Python interpreter.
13
# PYTHON_SHORT_VERSION - The version of the Python interpreter found,
14
# excluding the patch version number. (e.g. 2.5 and not 2.5.1))
16
# PYTHON_LONG_VERSION - The version of the Python interpreter found as a human
19
# PYTHON_SITE_PACKAGES_DIR - Location of the Python site-packages directory.
21
# PYTHON_INCLUDE_PATH - Directory holding the python.h include file.
23
# PYTHON_LIBRARY, PYTHON_LIBRARIES- Location of the Python library.
26
# Already in cache, be silent
27
SET(PYTHONLIBRARY_FOUND TRUE)
30
FIND_PACKAGE(PythonInterp REQUIRED)
31
GET_FILENAME_COMPONENT(_cmake_module_path ${CMAKE_CURRENT_LIST_FILE} PATH)
33
EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_cmake_module_path}/FindLibPython.py OUTPUT_VARIABLE python_config)
35
STRING(REGEX REPLACE ".*exec_prefix:([^\n]+).*$" "\\1" PYTHON_PREFIX ${python_config})
36
STRING(REGEX REPLACE ".*\nshort_version:([^\n]+).*$" "\\1" PYTHON_SHORT_VERSION ${python_config})
37
STRING(REGEX REPLACE ".*\nlong_version:([^\n]+).*$" "\\1" PYTHON_LONG_VERSION ${python_config})
38
STRING(REGEX REPLACE ".*\npy_inc_dir:([^\n]+).*$" "\\1" PYTHON_INCLUDE_PATH ${python_config})
39
STRING(REGEX REPLACE ".*\nsite_packages_dir:([^\n]+).*$" "\\1" PYTHON_SITE_PACKAGES_DIR ${python_config})
40
FIND_LIBRARY(PYTHON_LIBRARY NAMES python${PYTHON_SHORT_VERSION} PATHS ${PYTHON_PREFIX}/lib NO_DEFAULT_PATH)
41
SET(PYTHON_LIBRARIES ${PYTHON_LIBRARY})
42
SET(PYTHONLIBRARY_FOUND TRUE)
45
IF(PYTHONLIBRARY_FOUND)
46
IF(NOT PYTHONLIBRARY_FIND_QUIETLY)
47
MESSAGE(STATUS "Found Python executable: ${PYTHON_EXECUTABLE}")
48
MESSAGE(STATUS "Found Python version: ${PYTHON_LONG_VERSION}")
49
MESSAGE(STATUS "Found Python library: ${PYTHON_LIBRARY}")
50
ENDIF(NOT PYTHONLIBRARY_FIND_QUIETLY)
51
ELSE(PYTHONLIBRARY_FOUND)
52
IF(PYTHONLIBRARY_FIND_REQUIRED)
53
MESSAGE(FATAL_ERROR "Could not find Python")
54
ENDIF(PYTHONLIBRARY_FIND_REQUIRED)
55
ENDIF(PYTHONLIBRARY_FOUND)
57
ENDIF (PYTHON_LIBRARY)