Merge pull request #1340 from SpecLad:python-updates

This commit is contained in:
Roman Donchenko 2013-08-26 16:41:13 +04:00 committed by OpenCV Buildbot
commit f44ed7f37c
4 changed files with 37 additions and 60 deletions

View File

@ -807,14 +807,14 @@ endif()
# ========================== python ========================== # ========================== python ==========================
status("") status("")
status(" Python:") status(" Python:")
status(" Interpreter:" PYTHON_EXECUTABLE THEN "${PYTHON_EXECUTABLE} (ver ${PYTHON_VERSION_FULL})" ELSE NO) status(" Interpreter:" PYTHONINTERP_FOUND THEN "${PYTHON_EXECUTABLE} (ver ${PYTHON_VERSION_STRING})" ELSE NO)
if(BUILD_opencv_python) if(BUILD_opencv_python)
if(PYTHONLIBS_VERSION_STRING) if(PYTHONLIBS_VERSION_STRING)
status(" Libraries:" HAVE_opencv_python THEN "${PYTHON_LIBRARIES} (ver ${PYTHONLIBS_VERSION_STRING})" ELSE NO) status(" Libraries:" HAVE_opencv_python THEN "${PYTHON_LIBRARIES} (ver ${PYTHONLIBS_VERSION_STRING})" ELSE NO)
else() else()
status(" Libraries:" HAVE_opencv_python THEN ${PYTHON_LIBRARIES} ELSE NO) status(" Libraries:" HAVE_opencv_python THEN "${PYTHON_LIBRARIES}" ELSE NO)
endif() endif()
status(" numpy:" PYTHON_NUMPY_INCLUDE_DIR THEN "${PYTHON_NUMPY_INCLUDE_DIR} (ver ${PYTHON_NUMPY_VERSION})" ELSE "NO (Python wrappers can not be generated)") status(" numpy:" PYTHON_NUMPY_INCLUDE_DIRS THEN "${PYTHON_NUMPY_INCLUDE_DIRS} (ver ${PYTHON_NUMPY_VERSION})" ELSE "NO (Python wrappers can not be generated)")
status(" packages path:" PYTHON_EXECUTABLE THEN "${PYTHON_PACKAGES_PATH}" ELSE "-") status(" packages path:" PYTHON_EXECUTABLE THEN "${PYTHON_PACKAGES_PATH}" ELSE "-")
endif() endif()

View File

@ -2,7 +2,7 @@ if(WIN32 AND NOT PYTHON_EXECUTABLE)
# search for executable with the same bitness as resulting binaries # search for executable with the same bitness as resulting binaries
# standard FindPythonInterp always prefers executable from system path # standard FindPythonInterp always prefers executable from system path
# this is really important because we are using the interpreter for numpy search and for choosing the install location # this is really important because we are using the interpreter for numpy search and for choosing the install location
foreach(_CURRENT_VERSION ${Python_ADDITIONAL_VERSIONS} 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0) foreach(_CURRENT_VERSION ${Python_ADDITIONAL_VERSIONS} 2.7 "${MIN_VER_PYTHON}")
find_host_program(PYTHON_EXECUTABLE find_host_program(PYTHON_EXECUTABLE
NAMES python${_CURRENT_VERSION} python NAMES python${_CURRENT_VERSION} python
PATHS PATHS
@ -12,39 +12,15 @@ if(WIN32 AND NOT PYTHON_EXECUTABLE)
) )
endforeach() endforeach()
endif() endif()
find_host_package(PythonInterp 2.0) find_host_package(PythonInterp "${MIN_VER_PYTHON}")
unset(HAVE_SPHINX CACHE) unset(HAVE_SPHINX CACHE)
if(PYTHON_EXECUTABLE)
if(PYTHON_VERSION_STRING) if(PYTHONINTERP_FOUND)
set(PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}") set(PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
set(PYTHON_VERSION_FULL "${PYTHON_VERSION_STRING}")
else()
execute_process(COMMAND ${PYTHON_EXECUTABLE} --version
ERROR_VARIABLE PYTHON_VERSION_FULL
ERROR_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "[0-9]+.[0-9]+" PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_FULL}")
endif()
if("${PYTHON_VERSION_FULL}" MATCHES "[0-9]+.[0-9]+.[0-9]+")
set(PYTHON_VERSION_FULL "${CMAKE_MATCH_0}")
elseif("${PYTHON_VERSION_FULL}" MATCHES "[0-9]+.[0-9]+")
set(PYTHON_VERSION_FULL "${CMAKE_MATCH_0}")
else()
unset(PYTHON_VERSION_FULL)
endif()
if(NOT ANDROID AND NOT IOS) if(NOT ANDROID AND NOT IOS)
if(CMAKE_VERSION VERSION_GREATER 2.8.8 AND PYTHON_VERSION_FULL) find_host_package(PythonLibs "${PYTHON_VERSION_STRING}" EXACT)
find_host_package(PythonLibs ${PYTHON_VERSION_FULL} EXACT)
else()
find_host_package(PythonLibs ${PYTHON_VERSION_FULL})
endif()
# cmake 2.4 (at least on Ubuntu 8.04 (hardy)) don't define PYTHONLIBS_FOUND
if(NOT PYTHONLIBS_FOUND AND PYTHON_INCLUDE_PATH)
set(PYTHONLIBS_FOUND ON)
endif()
endif() endif()
if(NOT ANDROID AND NOT IOS) if(NOT ANDROID AND NOT IOS)
@ -78,28 +54,29 @@ if(PYTHON_EXECUTABLE)
endif() endif()
SET(PYTHON_PACKAGES_PATH "${_PYTHON_PACKAGES_PATH}" CACHE PATH "Where to install the python packages.") SET(PYTHON_PACKAGES_PATH "${_PYTHON_PACKAGES_PATH}" CACHE PATH "Where to install the python packages.")
if(NOT PYTHON_NUMPY_INCLUDE_DIR) if(NOT PYTHON_NUMPY_INCLUDE_DIRS)
# Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy # Attempt to discover the NumPy include directory. If this succeeds, then build python API with NumPy
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])" execute_process(COMMAND "${PYTHON_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 PYTHON_NUMPY_PROCESS RESULT_VARIABLE PYTHON_NUMPY_PROCESS
OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIR OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIRS
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE)
if(PYTHON_NUMPY_PROCESS EQUAL 0) if(PYTHON_NUMPY_PROCESS EQUAL 0)
file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIR}" _PYTHON_NUMPY_INCLUDE_DIR) file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIRS}" _PYTHON_NUMPY_INCLUDE_DIRS)
set(PYTHON_NUMPY_INCLUDE_DIR ${_PYTHON_NUMPY_INCLUDE_DIR} CACHE PATH "Path to numpy headers") set(PYTHON_NUMPY_INCLUDE_DIRS "${_PYTHON_NUMPY_INCLUDE_DIRS}" CACHE PATH "Path to numpy headers")
endif() endif()
endif() endif()
if(PYTHON_NUMPY_INCLUDE_DIR) if(PYTHON_NUMPY_INCLUDE_DIRS)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print(numpy.version.version)" execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import numpy; print(numpy.version.version)"
RESULT_VARIABLE PYTHON_NUMPY_PROCESS
OUTPUT_VARIABLE PYTHON_NUMPY_VERSION OUTPUT_VARIABLE PYTHON_NUMPY_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE)
endif() endif()
endif(NOT ANDROID AND NOT IOS) endif(NOT ANDROID AND NOT IOS)
endif()
if(BUILD_DOCS) if(BUILD_DOCS)
find_host_program(SPHINX_BUILD sphinx-build) find_host_program(SPHINX_BUILD sphinx-build)
if(SPHINX_BUILD) if(SPHINX_BUILD)
execute_process(COMMAND "${SPHINX_BUILD}" execute_process(COMMAND "${SPHINX_BUILD}"
@ -112,5 +89,4 @@ if(PYTHON_EXECUTABLE)
message(STATUS "Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}") message(STATUS "Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}")
endif() endif()
endif() endif()
endif(BUILD_DOCS) endif(BUILD_DOCS)
endif(PYTHON_EXECUTABLE)

View File

@ -1,2 +1,3 @@
set(MIN_VER_CMAKE 2.8.7) set(MIN_VER_CMAKE 2.8.7)
set(MIN_VER_PYTHON 2.6)
set(MIN_VER_ZLIB 1.2.3) set(MIN_VER_ZLIB 1.2.3)

View File

@ -6,7 +6,7 @@ if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
ocv_module_disable(python) ocv_module_disable(python)
endif() endif()
if(ANDROID OR IOS OR NOT PYTHONLIBS_FOUND OR NOT PYTHON_NUMPY_INCLUDE_DIR) if(ANDROID OR IOS OR NOT PYTHONLIBS_FOUND OR NOT PYTHON_NUMPY_INCLUDE_DIRS)
ocv_module_disable(python) ocv_module_disable(python)
endif() endif()
@ -15,7 +15,7 @@ ocv_add_module(python BINDINGS opencv_core opencv_flann opencv_imgproc opencv_vi
ocv_module_include_directories( ocv_module_include_directories(
"${PYTHON_INCLUDE_PATH}" "${PYTHON_INCLUDE_PATH}"
"${PYTHON_NUMPY_INCLUDE_DIR}" ${PYTHON_NUMPY_INCLUDE_DIRS}
"${CMAKE_CURRENT_SOURCE_DIR}/src2" "${CMAKE_CURRENT_SOURCE_DIR}/src2"
) )