1 # - Find python libraries
2 # This module finds if Python is installed and determines where the
3 # include files and libraries are. It also determines what the name of
4 # the library is. This code sets the following variables:
6 # PYTHON_LIBRARIES = path to the python library
7 # PYTHON_INCLUDE_PATH = path to where Python.h is found
8 # PYTHON_DEBUG_LIBRARIES = path to the debug library
9 # PYTHON_VERSION = version of python library
11 # The user can set this variable to choose their preferred python
12 # version to be found:
14 # PREFERRED_PYTHON_VERSION = preferred version of the python library
16 INCLUDE(CMakeFindFrameworks)
19 FIND_LIBRARY(PYTHON_DEBUG_LIBRARY
20 NAMES python25_d python24_d python23_d python22_d python21_d python20_d python
22 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.5\\InstallPath]/libs/Debug
23 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.5\\InstallPath]/libs
24 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.4\\InstallPath]/libs/Debug
25 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.4\\InstallPath]/libs
26 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath]/libs/Debug
27 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath]/libs
28 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.2\\InstallPath]/libs/Debug
29 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.2\\InstallPath]/libs
30 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]/libs/Debug
31 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]/libs
32 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]/libs/Debug
33 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]/libs
34 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.6\\InstallPath]/libs/Debug
35 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.6\\InstallPath]/libs
36 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.5\\InstallPath]/libs/Debug
37 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.5\\InstallPath]/libs
41 FIND_LIBRARY(PYTHON_LIBRARY ${PREFERRED_PYTHON_VERSION}
42 NAMES python25 python2.5
52 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.5\\InstallPath]/libs
53 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.4\\InstallPath]/libs
54 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath]/libs
55 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.2\\InstallPath]/libs
56 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]/libs
57 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]/libs
58 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.6\\InstallPath]/libs
59 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.5\\InstallPath]/libs
72 message(STATUS "Found Python: ${PYTHON_LIBRARY}")
75 # Search for the python framework on Apple.
76 CMAKE_FIND_FRAMEWORKS(Python)
77 SET(PYTHON_FRAMEWORK_INCLUDES)
79 IF(NOT PYTHON_INCLUDE_PATH)
80 FOREACH(version 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
81 FOREACH(dir ${Python_FRAMEWORKS})
82 SET(PYTHON_FRAMEWORK_INCLUDES ${PYTHON_FRAMEWORK_INCLUDES}
83 ${dir}/Versions/${version}/include/python${version})
86 ENDIF(NOT PYTHON_INCLUDE_PATH)
87 ENDIF(Python_FRAMEWORKS)
89 FIND_PATH(PYTHON_INCLUDE_PATH
93 ${PYTHON_FRAMEWORK_INCLUDES}
94 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.5\\InstallPath]/include
95 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.4\\InstallPath]/include
96 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath]/include
97 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.2\\InstallPath]/include
98 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]/include
99 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]/include
100 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.6\\InstallPath]/include
101 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.5\\InstallPath]/include
104 ${PREFERRED_PYTHON_VERSION}
124 FIND_PROGRAM( PYTHON_EXECUTABLE NAMES ${PREFERRED_PYTHON_VERSION} python )
126 IF ( PYTHON_EXECUTABLE )
127 EXEC_PROGRAM( ${PYTHON_EXECUTABLE} ARGS "-c \"import sys; print sys.version[:3]\"" OUTPUT_VARIABLE PYTHON_VERSION )
128 STRING( REGEX REPLACE "[\r\n]" " " PYTHON_VERSION "${PYTHON_VERSION}" )
129 ENDIF ( PYTHON_EXECUTABLE )
131 # Python Should be built and installed as a Framework on OSX
132 IF(Python_FRAMEWORKS)
133 # If a framework has been selected for the include path,
134 # make sure "-framework" is used to link it.
135 IF("${PYTHON_INCLUDE_PATH}" MATCHES "Python\\.framework")
136 SET(PYTHON_LIBRARY "")
137 SET(PYTHON_DEBUG_LIBRARY "")
138 ENDIF("${PYTHON_INCLUDE_PATH}" MATCHES "Python\\.framework")
139 IF(NOT PYTHON_LIBRARY)
140 SET (PYTHON_LIBRARY "-framework Python" CACHE FILEPATH "Python Framework" FORCE)
141 ENDIF(NOT PYTHON_LIBRARY)
142 IF(NOT PYTHON_DEBUG_LIBRARY)
143 SET (PYTHON_DEBUG_LIBRARY "-framework Python" CACHE FILEPATH "Python Framework" FORCE)
144 ENDIF(NOT PYTHON_DEBUG_LIBRARY)
145 ENDIF(Python_FRAMEWORKS)
147 # We use PYTHON_LIBRARY and PYTHON_DEBUG_LIBRARY for the cache entries
148 # because they are meant to specify the location of a single library.
149 # We now set the variables listed by the documentation for this
151 SET(PYTHON_LIBRARIES "${PYTHON_LIBRARY}")
152 SET(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}")