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(HAVE_SPHINX CACHE)
19 if(PYTHON_VERSION_STRING)
20 set(PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
21 set(PYTHON_VERSION_FULL "${PYTHON_VERSION_STRING}")
23 execute_process(COMMAND ${PYTHON_EXECUTABLE} --version
24 ERROR_VARIABLE PYTHON_VERSION_FULL
25 ERROR_STRIP_TRAILING_WHITESPACE)
27 string(REGEX MATCH "[0-9]+.[0-9]+" PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_FULL}")
30 if("${PYTHON_VERSION_FULL}" MATCHES "[0-9]+.[0-9]+.[0-9]+")
31 set(PYTHON_VERSION_FULL "${CMAKE_MATCH_0}")
32 elseif("${PYTHON_VERSION_FULL}" MATCHES "[0-9]+.[0-9]+")
33 set(PYTHON_VERSION_FULL "${CMAKE_MATCH_0}")
35 unset(PYTHON_VERSION_FULL)
38 if(NOT ANDROID AND NOT IOS)
39 if(CMAKE_VERSION VERSION_GREATER 2.8.8 AND PYTHON_VERSION_FULL)
40 find_host_package(PythonLibs ${PYTHON_VERSION_FULL} EXACT)
42 find_host_package(PythonLibs ${PYTHON_VERSION_FULL})
44 # cmake 2.4 (at least on Ubuntu 8.04 (hardy)) don't define PYTHONLIBS_FOUND
45 if(NOT PYTHONLIBS_FOUND AND PYTHON_INCLUDE_PATH)
46 set(PYTHONLIBS_FOUND ON)
50 if(NOT ANDROID AND NOT IOS)
52 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *; print(get_python_lib())"
53 RESULT_VARIABLE PYTHON_CVPY_PROCESS
54 OUTPUT_VARIABLE PYTHON_STD_PACKAGES_PATH
55 OUTPUT_STRIP_TRAILING_WHITESPACE)
56 if("${PYTHON_STD_PACKAGES_PATH}" MATCHES "site-packages")
57 set(_PYTHON_PACKAGES_PATH "python${PYTHON_VERSION_MAJOR_MINOR}/site-packages")
58 else() #debian based assumed, install to the dist-packages.
59 set(_PYTHON_PACKAGES_PATH "python${PYTHON_VERSION_MAJOR_MINOR}/dist-packages")
61 if(EXISTS "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/${PYTHON_PACKAGES_PATH}")
62 set(_PYTHON_PACKAGES_PATH "lib${LIB_SUFFIX}/${_PYTHON_PACKAGES_PATH}")
64 set(_PYTHON_PACKAGES_PATH "lib/${_PYTHON_PACKAGES_PATH}")
66 elseif(CMAKE_HOST_WIN32)
67 get_filename_component(PYTHON_PATH "${PYTHON_EXECUTABLE}" PATH)
68 file(TO_CMAKE_PATH "${PYTHON_PATH}" PYTHON_PATH)
69 if(NOT EXISTS "${PYTHON_PATH}/Lib/site-packages")
71 get_filename_component(PYTHON_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${PYTHON_VERSION_MAJOR_MINOR}\\InstallPath]" ABSOLUTE)
73 get_filename_component(PYTHON_PATH "[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${PYTHON_VERSION_MAJOR_MINOR}\\InstallPath]" ABSOLUTE)
75 file(TO_CMAKE_PATH "${PYTHON_PATH}" PYTHON_PATH)
77 set(_PYTHON_PACKAGES_PATH "${PYTHON_PATH}/Lib/site-packages")
79 SET(PYTHON_PACKAGES_PATH "${_PYTHON_PACKAGES_PATH}" CACHE PATH "Where to install the python packages.")
81 if(NOT PYTHON_NUMPY_INCLUDE_DIR)
82 # Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy
83 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])"
84 RESULT_VARIABLE PYTHON_NUMPY_PROCESS
85 OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIR
86 OUTPUT_STRIP_TRAILING_WHITESPACE)
88 if(PYTHON_NUMPY_PROCESS EQUAL 0)
89 file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIR}" _PYTHON_NUMPY_INCLUDE_DIR)
90 set(PYTHON_NUMPY_INCLUDE_DIR ${_PYTHON_NUMPY_INCLUDE_DIR} CACHE PATH "Path to numpy headers")
94 if(PYTHON_NUMPY_INCLUDE_DIR)
95 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print(numpy.version.version)"
96 RESULT_VARIABLE PYTHON_NUMPY_PROCESS
97 OUTPUT_VARIABLE PYTHON_NUMPY_VERSION
98 OUTPUT_STRIP_TRAILING_WHITESPACE)
100 endif(NOT ANDROID AND NOT IOS)
103 find_host_program(SPHINX_BUILD sphinx-build)
105 execute_process(COMMAND "${SPHINX_BUILD}"
107 ERROR_VARIABLE SPHINX_OUTPUT
108 OUTPUT_STRIP_TRAILING_WHITESPACE)
109 if(SPHINX_OUTPUT MATCHES "^Sphinx v([0-9][^ \n]*)")
110 set(SPHINX_VERSION "${CMAKE_MATCH_1}")
112 message(STATUS "Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}")
116 endif(PYTHON_EXECUTABLE)