+ set(_numpy_include_dirs ${${numpy_include_dirs}})
+
+ if(NOT _numpy_include_dirs)
+ if(CMAKE_CROSSCOMPILING)
+ message(STATUS "Cannot probe for Python/Numpy support (because we are cross-compiling OpenCV)")
+ message(STATUS "If you want to enable Python/Numpy support, set the following variables:")
+ message(STATUS " PYTHON2_INCLUDE_PATH")
+ message(STATUS " PYTHON2_LIBRARIES")
+ message(STATUS " PYTHON2_NUMPY_INCLUDE_DIRS")
+ message(STATUS " PYTHON3_INCLUDE_PATH")
+ message(STATUS " PYTHON3_LIBRARIES")
+ message(STATUS " PYTHON3_NUMPY_INCLUDE_DIRS")
+ else()
+ # Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy
+ execute_process(COMMAND "${_executable}" -c "import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print(os.pathsep.join(numpy.distutils.misc_util.get_numpy_include_dirs()))"
+ RESULT_VARIABLE _numpy_process
+ OUTPUT_VARIABLE _numpy_include_dirs
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ if(NOT _numpy_process EQUAL 0)
+ unset(_numpy_include_dirs)
+ endif()
+ endif()
+ endif()
+
+ if(_numpy_include_dirs)
+ file(TO_CMAKE_PATH "${_numpy_include_dirs}" _numpy_include_dirs)
+ if(CMAKE_CROSSCOMPILING)
+ if(NOT _numpy_version)
+ set(_numpy_version "undefined - cannot be probed because of the cross-compilation")
+ endif()
+ else()
+ execute_process(COMMAND "${_executable}" -c "import numpy; print(numpy.version.version)"
+ RESULT_VARIABLE _numpy_process
+ OUTPUT_VARIABLE _numpy_version
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ endif()
+ endif()
+ endif(NOT ANDROID AND NOT IOS)
+ endif()
+
+ # Export return values
+ set(${found} "${_found}" PARENT_SCOPE)
+ set(${executable} "${_executable}" CACHE FILEPATH "Path to Python interpretor")
+ set(${version_string} "${_version_string}" PARENT_SCOPE)
+ set(${version_major} "${_version_major}" PARENT_SCOPE)
+ set(${version_minor} "${_version_minor}" PARENT_SCOPE)
+ set(${libs_found} "${_libs_found}" PARENT_SCOPE)
+ set(${libs_version_string} "${_libs_version_string}" PARENT_SCOPE)
+ set(${libraries} "${_libraries}" PARENT_SCOPE)
+ set(${library} "${_library}" CACHE FILEPATH "Path to Python library")
+ set(${debug_libraries} "${_debug_libraries}" PARENT_SCOPE)
+ set(${debug_library} "${_debug_library}" CACHE FILEPATH "Path to Python debug")
+ set(${include_path} "${_include_path}" PARENT_SCOPE)
+ set(${include_dir} "${_include_dir}" CACHE PATH "Python include dir")
+ set(${include_dir2} "${_include_dir2}" CACHE PATH "Python include dir 2")
+ set(${packages_path} "${_packages_path}" CACHE PATH "Where to install the python packages.")
+ set(${numpy_include_dirs} ${_numpy_include_dirs} CACHE PATH "Path to numpy headers")
+ set(${numpy_version} "${_numpy_version}" PARENT_SCOPE)
+endfunction(find_python)
+
+find_python(2.7 "${MIN_VER_PYTHON2}" PYTHON2_LIBRARY PYTHON2_INCLUDE_DIR
+ PYTHON2INTERP_FOUND PYTHON2_EXECUTABLE PYTHON2_VERSION_STRING
+ PYTHON2_VERSION_MAJOR PYTHON2_VERSION_MINOR PYTHON2LIBS_FOUND
+ PYTHON2LIBS_VERSION_STRING PYTHON2_LIBRARIES PYTHON2_LIBRARY
+ PYTHON2_DEBUG_LIBRARIES PYTHON2_LIBRARY_DEBUG PYTHON2_INCLUDE_PATH
+ PYTHON2_INCLUDE_DIR PYTHON2_INCLUDE_DIR2 PYTHON2_PACKAGES_PATH
+ PYTHON2_NUMPY_INCLUDE_DIRS PYTHON2_NUMPY_VERSION)
+
+find_python(3.4 "${MIN_VER_PYTHON3}" PYTHON3_LIBRARY PYTHON3_INCLUDE_DIR
+ PYTHON3INTERP_FOUND PYTHON3_EXECUTABLE PYTHON3_VERSION_STRING
+ PYTHON3_VERSION_MAJOR PYTHON3_VERSION_MINOR PYTHON3LIBS_FOUND
+ PYTHON3LIBS_VERSION_STRING PYTHON3_LIBRARIES PYTHON3_LIBRARY
+ PYTHON3_DEBUG_LIBRARIES PYTHON3_LIBRARY_DEBUG PYTHON3_INCLUDE_PATH
+ PYTHON3_INCLUDE_DIR PYTHON3_INCLUDE_DIR2 PYTHON3_PACKAGES_PATH
+ PYTHON3_NUMPY_INCLUDE_DIRS PYTHON3_NUMPY_VERSION)
+
+# Use Python 2 as default Python interpreter
+if(PYTHON2LIBS_FOUND)
+ set(PYTHON_DEFAULT_AVAILABLE "TRUE")
+ set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON2_EXECUTABLE}")