Add initial support for python bindings
[alexxy/gromacs.git] / src / pygromacs / cmake / modules / FindPythonLibrary.cmake
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_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.
19 #
20 # PYTHON_SITE_PACKAGES_DIR - Location of the Python site-packages directory.
21 #
22 # PYTHON_INCLUDE_PATH - Directory holding the python.h include file.
23 #
24 # PYTHON_LIBRARY, PYTHON_LIBRARIES- Location of the Python library.
25
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.
30
31 include(FindPackageHandleStandardArgs)
32
33 find_package(PythonInterp)
34
35 if (PYTHONINTERP_FOUND)
36
37     option(INSTALL_PYTHON_FILES_IN_PYTHON_PREFIX "Install the Python files in the Python packages dir" FALSE)
38
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})
44
45     find_package(PythonLibs QUIET)
46
47     if(PYTHONLIBS_FOUND)
48         set(PYTHON_LIBRARY ${PYTHON_LIBRARIES})
49     endif(PYTHONLIBS_FOUND)
50
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
55                    )
56
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})
60     else()
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
64                        )
65     endif()
66
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)")
69     endif()
70
71 endif(PYTHONINTERP_FOUND)
72
73 find_package_handle_standard_args(PythonLibrary DEFAULT_MSG PYTHON_LIBRARY)
74