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_INSTALL_DIR - this cache variable can be used for installing
16 # own python modules. You may want to adjust this to be the
17 # same as ${PYTHON_SITE_PACKAGES_DIR}, but then admin
18 # privileges may be required for installation.
20 # PYTHON_SITE_PACKAGES_DIR - Location of the Python site-packages directory.
22 # PYTHON_INCLUDE_PATH - Directory holding the python.h include file.
24 # PYTHON_LIBRARY, PYTHON_LIBRARIES- Location of the Python library.
26 # Copyright (c) 2007, Simon Edwards <simon@simonzone.com>
27 # Copyright (c) 2012, Luca Beltrame <lbeltrame@kde.org>
28 # Redistribution and use is allowed according to the terms of the BSD license.
29 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
31 include(FindPackageHandleStandardArgs)
33 find_package(PythonInterp)
35 if (PYTHONINTERP_FOUND)
37 option(INSTALL_PYTHON_FILES_IN_PYTHON_PREFIX "Install the Python files in the Python packages dir" FALSE)
39 # Set the Python libraries to what we actually found for interpreters
40 set(Python_ADDITIONAL_VERSIONS "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
41 # These are kept for compatibility
42 set(PYTHON_SHORT_VERSION "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
43 set(PYTHON_LONG_VERSION ${PYTHON_VERSION_STRING})
45 find_package(PythonLibs QUIET)
48 set(PYTHON_LIBRARY ${PYTHON_LIBRARIES})
49 endif(PYTHONLIBS_FOUND)
51 # Auto detect Python site-packages directory
52 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(True))"
53 OUTPUT_VARIABLE PYTHON_SITE_PACKAGES_DIR
54 OUTPUT_STRIP_TRAILING_WHITESPACE
57 message(STATUS "Python system site-packages directory: ${PYTHON_SITE_PACKAGES_DIR}")
58 if(INSTALL_PYTHON_FILES_IN_PYTHON_PREFIX)
59 set(PYTHON_SITE_PACKAGES_INSTALL_DIR ${PYTHON_SITE_PACKAGES_DIR})
61 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(True, prefix='${CMAKE_INSTALL_PREFIX}'))"
62 OUTPUT_VARIABLE PYTHON_SITE_PACKAGES_INSTALL_DIR
63 OUTPUT_STRIP_TRAILING_WHITESPACE
67 if(NOT PYTHON_SITE_PACKAGES_INSTALL_DIR STREQUAL PYTHON_SITE_PACKAGES_DIR)
68 message(STATUS "The Python files will be installed to ${PYTHON_SITE_PACKAGES_INSTALL_DIR}. Make sure to add them to the Python search path (e.g. by setting PYTHONPATH)")
71 endif(PYTHONINTERP_FOUND)
73 find_package_handle_standard_args(PythonLibrary DEFAULT_MSG PYTHON_LIBRARY)