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 # Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy
85 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]"
86 RESULT_VARIABLE PYTHON_NUMPY_PROCESS
87 OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIR
88 OUTPUT_STRIP_TRAILING_WHITESPACE)
90 if(PYTHON_NUMPY_PROCESS EQUAL 0)
91 file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIR}" _PYTHON_NUMPY_INCLUDE_DIR)
92 set(PYTHON_NUMPY_INCLUDE_DIR ${_PYTHON_NUMPY_INCLUDE_DIR} CACHE PATH "Path to numpy headers")
96 if(PYTHON_NUMPY_INCLUDE_DIR)
97 set(PYTHON_USE_NUMPY TRUE)
98 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print numpy.version.version"
99 RESULT_VARIABLE PYTHON_NUMPY_PROCESS
100 OUTPUT_VARIABLE PYTHON_NUMPY_VERSION
101 OUTPUT_STRIP_TRAILING_WHITESPACE)
103 endif(NOT ANDROID AND NOT IOS)
106 find_host_program(SPHINX_BUILD sphinx-build)
108 execute_process(COMMAND "${SPHINX_BUILD}"
110 ERROR_VARIABLE SPHINX_OUTPUT
111 OUTPUT_STRIP_TRAILING_WHITESPACE)
112 if(SPHINX_OUTPUT MATCHES "Sphinx v([0-9][^ \n]*)")
113 set(SPHINX_VERSION "${CMAKE_MATCH_1}")
115 message(STATUS "Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}")
119 endif(PYTHON_EXECUTABLE)