1 if(WIN32 AND NOT PYTHON_EXECUTABLE)
2 # search for executable with the same bitness as resulting binaries
3 # standard FindPythonInterp always prefers executable from system path
4 # this is really important because we are using the interpreter for numpy search and for choosing the install location
5 foreach(_CURRENT_VERSION ${Python_ADDITIONAL_VERSIONS} 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
6 find_host_program(PYTHON_EXECUTABLE
7 NAMES python${_CURRENT_VERSION} python
9 [HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Python\\\\PythonCore\\\\${_CURRENT_VERSION}\\\\InstallPath]
10 [HKEY_CURRENT_USER\\\\SOFTWARE\\\\Python\\\\PythonCore\\\\${_CURRENT_VERSION}\\\\InstallPath]
11 NO_SYSTEM_ENVIRONMENT_PATH
15 find_host_package(PythonInterp 2.0)
17 unset(PYTHON_USE_NUMPY CACHE)
18 unset(HAVE_SPHINX CACHE)
20 if(PYTHON_VERSION_STRING)
21 set(PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
22 set(PYTHON_VERSION_FULL "${PYTHON_VERSION_STRING}")
24 execute_process(COMMAND ${PYTHON_EXECUTABLE} --version
25 ERROR_VARIABLE PYTHON_VERSION_FULL
26 ERROR_STRIP_TRAILING_WHITESPACE)
28 string(REGEX MATCH "[0-9]+.[0-9]+" PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_FULL}")
31 if("${PYTHON_VERSION_FULL}" MATCHES "[0-9]+.[0-9]+.[0-9]+")
32 set(PYTHON_VERSION_FULL "${CMAKE_MATCH_0}")
33 elseif("${PYTHON_VERSION_FULL}" MATCHES "[0-9]+.[0-9]+")
34 set(PYTHON_VERSION_FULL "${CMAKE_MATCH_0}")
36 unset(PYTHON_VERSION_FULL)
39 if(NOT ANDROID AND NOT IOS)
40 ocv_check_environment_variables(PYTHON_LIBRARY PYTHON_INCLUDE_DIR)
41 if(CMAKE_VERSION VERSION_GREATER 2.8.8 AND PYTHON_VERSION_FULL)
42 find_host_package(PythonLibs ${PYTHON_VERSION_FULL} EXACT)
44 find_host_package(PythonLibs ${PYTHON_VERSION_FULL})
46 # cmake 2.4 (at least on Ubuntu 8.04 (hardy)) don't define PYTHONLIBS_FOUND
47 if(NOT PYTHONLIBS_FOUND AND PYTHON_INCLUDE_PATH)
48 set(PYTHONLIBS_FOUND ON)
52 if(NOT ANDROID AND NOT IOS)
54 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *; print get_python_lib()"
55 RESULT_VARIABLE PYTHON_CVPY_PROCESS
56 OUTPUT_VARIABLE PYTHON_STD_PACKAGES_PATH
57 OUTPUT_STRIP_TRAILING_WHITESPACE)
58 if("${PYTHON_STD_PACKAGES_PATH}" MATCHES "site-packages")
59 set(_PYTHON_PACKAGES_PATH "python${PYTHON_VERSION_MAJOR_MINOR}/site-packages")
60 else() #debian based assumed, install to the dist-packages.
61 set(_PYTHON_PACKAGES_PATH "python${PYTHON_VERSION_MAJOR_MINOR}/dist-packages")
63 if(EXISTS "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/${PYTHON_PACKAGES_PATH}")
64 set(_PYTHON_PACKAGES_PATH "lib${LIB_SUFFIX}/${_PYTHON_PACKAGES_PATH}")
66 set(_PYTHON_PACKAGES_PATH "lib/${_PYTHON_PACKAGES_PATH}")
68 elseif(CMAKE_HOST_WIN32)
69 get_filename_component(PYTHON_PATH "${PYTHON_EXECUTABLE}" PATH)
70 file(TO_CMAKE_PATH "${PYTHON_PATH}" PYTHON_PATH)
71 if(NOT EXISTS "${PYTHON_PATH}/Lib/site-packages")
73 get_filename_component(PYTHON_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${PYTHON_VERSION_MAJOR_MINOR}\\InstallPath]" ABSOLUTE)
75 get_filename_component(PYTHON_PATH "[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${PYTHON_VERSION_MAJOR_MINOR}\\InstallPath]" ABSOLUTE)
77 file(TO_CMAKE_PATH "${PYTHON_PATH}" PYTHON_PATH)
79 set(_PYTHON_PACKAGES_PATH "${PYTHON_PATH}/Lib/site-packages")
81 SET(PYTHON_PACKAGES_PATH "${_PYTHON_PACKAGES_PATH}" CACHE PATH "Where to install the python packages.")
83 if(NOT PYTHON_NUMPY_INCLUDE_DIR)
84 if(CMAKE_CROSSCOMPILING)
85 message(STATUS "Cannot probe for Python/Numpy support (because we are cross-compiling OpenCV)")
86 message(STATUS "If you want to enable Python/Numpy support, set the following variables:")
87 message(STATUS " PYTHON_INCLUDE_PATH")
88 message(STATUS " PYTHON_LIBRARIES")
89 message(STATUS " PYTHON_NUMPY_INCLUDE_DIR")
91 # Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy
92 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print numpy.distutils.misc_util.get_numpy_include_dirs()[0]"
93 RESULT_VARIABLE PYTHON_NUMPY_PROCESS
94 OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIR
95 OUTPUT_STRIP_TRAILING_WHITESPACE)
97 if(NOT PYTHON_NUMPY_PROCESS EQUAL 0)
98 unset(PYTHON_NUMPY_INCLUDE_DIR)
103 if(PYTHON_NUMPY_INCLUDE_DIR)
104 file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIR}" _PYTHON_NUMPY_INCLUDE_DIR)
105 set(PYTHON_NUMPY_INCLUDE_DIR ${_PYTHON_NUMPY_INCLUDE_DIR} CACHE PATH "Path to numpy headers")
106 set(PYTHON_USE_NUMPY TRUE)
107 if(CMAKE_CROSSCOMPILING)
108 if(NOT PYTHON_NUMPY_VERSION)
109 set(PYTHON_NUMPY_VERSION "undefined - cannot be probed because of the cross-compilation")
112 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print numpy.version.version"
113 RESULT_VARIABLE PYTHON_NUMPY_PROCESS
114 OUTPUT_VARIABLE PYTHON_NUMPY_VERSION
115 OUTPUT_STRIP_TRAILING_WHITESPACE)
118 endif(NOT ANDROID AND NOT IOS)
121 find_host_program(SPHINX_BUILD sphinx-build)
123 execute_process(COMMAND "${SPHINX_BUILD}"
125 ERROR_VARIABLE SPHINX_OUTPUT
126 OUTPUT_STRIP_TRAILING_WHITESPACE)
127 if(SPHINX_OUTPUT MATCHES "Sphinx v([0-9][^ \n]*)")
128 set(SPHINX_VERSION "${CMAKE_MATCH_1}")
130 message(STATUS "Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}")
134 endif(PYTHON_EXECUTABLE)