From 1a81da012d3cd1235d2f40a3c787bc6e24d2626c Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Fri, 23 Aug 2013 18:24:02 +0400 Subject: [PATCH 1/4] Removed old Python detection cruft. None of this should be relevant as of CMake 2.8.7. --- CMakeLists.txt | 4 ++-- cmake/OpenCVDetectPython.cmake | 32 ++++---------------------------- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a24ba1af75..db1b685c92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -807,12 +807,12 @@ endif() # ========================== python ========================== status("") 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(PYTHONLIBS_VERSION_STRING) status(" Libraries:" HAVE_opencv_python THEN "${PYTHON_LIBRARIES} (ver ${PYTHONLIBS_VERSION_STRING})" ELSE NO) else() - status(" Libraries:" HAVE_opencv_python THEN ${PYTHON_LIBRARIES} ELSE NO) + status(" Libraries:" HAVE_opencv_python THEN "${PYTHON_LIBRARIES}" ELSE NO) 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(" packages path:" PYTHON_EXECUTABLE THEN "${PYTHON_PACKAGES_PATH}" ELSE "-") diff --git a/cmake/OpenCVDetectPython.cmake b/cmake/OpenCVDetectPython.cmake index 777f820bda..ca693e701c 100644 --- a/cmake/OpenCVDetectPython.cmake +++ b/cmake/OpenCVDetectPython.cmake @@ -15,36 +15,12 @@ endif() find_host_package(PythonInterp 2.0) unset(HAVE_SPHINX CACHE) -if(PYTHON_EXECUTABLE) - if(PYTHON_VERSION_STRING) - 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(PYTHONINTERP_FOUND) + set(PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}") if(NOT ANDROID AND NOT IOS) - if(CMAKE_VERSION VERSION_GREATER 2.8.8 AND PYTHON_VERSION_FULL) - 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() + find_host_package(PythonLibs "${PYTHON_VERSION_STRING}" EXACT) endif() if(NOT ANDROID AND NOT IOS) @@ -113,4 +89,4 @@ if(PYTHON_EXECUTABLE) endif() endif() endif(BUILD_DOCS) -endif(PYTHON_EXECUTABLE) +endif() From dbb684b85f511f791db6d20d0523a5321bf48079 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Fri, 23 Aug 2013 18:31:51 +0400 Subject: [PATCH 2/4] Bumped minimal Python version to 2.6. Rationale: we already depend on it (e.g. some scripts use print_function). --- cmake/OpenCVDetectPython.cmake | 4 ++-- cmake/OpenCVMinDepVersions.cmake | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmake/OpenCVDetectPython.cmake b/cmake/OpenCVDetectPython.cmake index ca693e701c..fa88ba0dcf 100644 --- a/cmake/OpenCVDetectPython.cmake +++ b/cmake/OpenCVDetectPython.cmake @@ -2,7 +2,7 @@ if(WIN32 AND NOT PYTHON_EXECUTABLE) # search for executable with the same bitness as resulting binaries # 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 - 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 NAMES python${_CURRENT_VERSION} python PATHS @@ -12,7 +12,7 @@ if(WIN32 AND NOT PYTHON_EXECUTABLE) ) endforeach() endif() -find_host_package(PythonInterp 2.0) +find_host_package(PythonInterp "${MIN_VER_PYTHON}") unset(HAVE_SPHINX CACHE) diff --git a/cmake/OpenCVMinDepVersions.cmake b/cmake/OpenCVMinDepVersions.cmake index 9ec40d963a..b659a83794 100644 --- a/cmake/OpenCVMinDepVersions.cmake +++ b/cmake/OpenCVMinDepVersions.cmake @@ -1,2 +1,3 @@ set(MIN_VER_CMAKE 2.8.7) +set(MIN_VER_PYTHON 2.6) set(MIN_VER_ZLIB 1.2.3) From 67ae438daef9eb70e17f927eb915fee0cfc3291a Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Fri, 23 Aug 2013 18:41:13 +0400 Subject: [PATCH 3/4] Refactored NumPy detection. Most importantly, added support for multiple include directores, but also did some general cleanup. --- CMakeLists.txt | 4 ++-- cmake/OpenCVDetectPython.cmake | 20 ++++++++++---------- modules/python/CMakeLists.txt | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db1b685c92..29fdc4eca9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -814,8 +814,8 @@ if(BUILD_opencv_python) else() status(" Libraries:" HAVE_opencv_python THEN "${PYTHON_LIBRARIES}" ELSE NO) 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(" packages path:" PYTHON_EXECUTABLE THEN "${PYTHON_PACKAGES_PATH}" ELSE "-") + 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 "-") endif() # ========================== java ========================== diff --git a/cmake/OpenCVDetectPython.cmake b/cmake/OpenCVDetectPython.cmake index fa88ba0dcf..8630a82da7 100644 --- a/cmake/OpenCVDetectPython.cmake +++ b/cmake/OpenCVDetectPython.cmake @@ -54,24 +54,24 @@ if(PYTHONINTERP_FOUND) endif() 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 - 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 - OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIR + OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE) if(PYTHON_NUMPY_PROCESS EQUAL 0) - file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIR}" _PYTHON_NUMPY_INCLUDE_DIR) - set(PYTHON_NUMPY_INCLUDE_DIR ${_PYTHON_NUMPY_INCLUDE_DIR} CACHE PATH "Path to numpy headers") + file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIRS}" _PYTHON_NUMPY_INCLUDE_DIRS) + set(PYTHON_NUMPY_INCLUDE_DIRS "${_PYTHON_NUMPY_INCLUDE_DIRS}" CACHE PATH "Path to numpy headers") endif() endif() - if(PYTHON_NUMPY_INCLUDE_DIR) - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print(numpy.version.version)" - RESULT_VARIABLE PYTHON_NUMPY_PROCESS - OUTPUT_VARIABLE PYTHON_NUMPY_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE) + if(PYTHON_NUMPY_INCLUDE_DIRS) + execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import numpy; print(numpy.version.version)" + OUTPUT_VARIABLE PYTHON_NUMPY_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) endif() endif(NOT ANDROID AND NOT IOS) diff --git a/modules/python/CMakeLists.txt b/modules/python/CMakeLists.txt index 877b454174..d3bed1695b 100644 --- a/modules/python/CMakeLists.txt +++ b/modules/python/CMakeLists.txt @@ -6,7 +6,7 @@ if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug") ocv_module_disable(python) 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) endif() @@ -15,7 +15,7 @@ ocv_add_module(python BINDINGS opencv_core opencv_flann opencv_imgproc opencv_vi ocv_module_include_directories( "${PYTHON_INCLUDE_PATH}" - "${PYTHON_NUMPY_INCLUDE_DIR}" + ${PYTHON_NUMPY_INCLUDE_DIRS} "${CMAKE_CURRENT_SOURCE_DIR}/src2" ) From 055a581977a0b878c8f8fe78eca699feb4ba26dd Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Fri, 23 Aug 2013 18:43:06 +0400 Subject: [PATCH 4/4] Moved Sphinx detection outside of the PYTHONINTERP_FOUND block. Who knows, maybe the user's Sphinx installation uses a Python we couldn't find. --- cmake/OpenCVDetectPython.cmake | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cmake/OpenCVDetectPython.cmake b/cmake/OpenCVDetectPython.cmake index 8630a82da7..65c45c9036 100644 --- a/cmake/OpenCVDetectPython.cmake +++ b/cmake/OpenCVDetectPython.cmake @@ -74,19 +74,19 @@ if(PYTHONINTERP_FOUND) OUTPUT_STRIP_TRAILING_WHITESPACE) endif() endif(NOT ANDROID AND NOT IOS) - - if(BUILD_DOCS) - find_host_program(SPHINX_BUILD sphinx-build) - if(SPHINX_BUILD) - execute_process(COMMAND "${SPHINX_BUILD}" - OUTPUT_QUIET - ERROR_VARIABLE SPHINX_OUTPUT - OUTPUT_STRIP_TRAILING_WHITESPACE) - if(SPHINX_OUTPUT MATCHES "Sphinx v([0-9][^ \n]*)") - set(SPHINX_VERSION "${CMAKE_MATCH_1}") - set(HAVE_SPHINX 1) - message(STATUS "Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}") - endif() - endif() - endif(BUILD_DOCS) endif() + +if(BUILD_DOCS) + find_host_program(SPHINX_BUILD sphinx-build) + if(SPHINX_BUILD) + execute_process(COMMAND "${SPHINX_BUILD}" + OUTPUT_QUIET + ERROR_VARIABLE SPHINX_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(SPHINX_OUTPUT MATCHES "Sphinx v([0-9][^ \n]*)") + set(SPHINX_VERSION "${CMAKE_MATCH_1}") + set(HAVE_SPHINX 1) + message(STATUS "Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}") + endif() + endif() +endif(BUILD_DOCS)