mirror of
https://github.com/opencv/opencv.git
synced 2024-11-26 20:20:20 +08:00
Fixed python detection on Windows with both 32bit and 64bit pythons installed.
This commit is contained in:
parent
35a7dfbd37
commit
c16a1d86cc
@ -835,26 +835,30 @@ status(" Use TBB:" HAVE_TBB THEN YES ELSE NO)
|
||||
status(" Use Cuda:" HAVE_CUDA THEN YES ELSE NO)
|
||||
status(" Use Eigen:" HAVE_EIGEN THEN YES ELSE NO)
|
||||
|
||||
status("")
|
||||
status(" Python interpreter:" PYTHON_EXECUTABLE THEN "${PYTHON_EXECUTABLE} (ver ${PYTHON_VERSION_MAJOR_MINOR})" ELSE NO)
|
||||
# interfaces to other languages
|
||||
status("")
|
||||
status(" Interfaces:")
|
||||
status(" Python:" HAVE_opencv_python THEN YES ELSE NO)
|
||||
status(" Python numpy:" PYTHON_USE_NUMPY THEN YES ELSE "NO (Python wrappers can not be generated)")
|
||||
status(" Python:")
|
||||
status(" Interpreter:" PYTHON_EXECUTABLE THEN "${PYTHON_EXECUTABLE} (ver ${PYTHON_VERSION_FULL})" ELSE NO)
|
||||
status(" Libraries:" HAVE_opencv_python THEN ${PYTHON_LIBRARIES} ELSE NO)
|
||||
status(" numpy:" PYTHON_USE_NUMPY 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 -)
|
||||
|
||||
if(ANDROID)
|
||||
status(" Java:" HAVE_opencv_java THEN YES ELSE NO)
|
||||
status("")
|
||||
status(" Java:" HAVE_opencv_java THEN YES ELSE NO)
|
||||
endif()
|
||||
|
||||
# documentation
|
||||
status("")
|
||||
status(" Documentation:")
|
||||
status(" Sphinx:" HAVE_SPHINX THEN "${SPHINX_BUILD} (ver ${SPHINX_VERSION})" ELSE NO)
|
||||
status(" PdfLaTeX compiler:" PDFLATEX_COMPILER THEN "${PDFLATEX_COMPILER}" ELSE NO)
|
||||
if(BUILD_DOCS AND HAVE_SPHINX)
|
||||
status(" Build Documentation:" PDFLATEX_COMPILER THEN YES ELSE "YES (only HTML without math expressions)")
|
||||
else()
|
||||
status(" Build Documentation:" NO)
|
||||
if(BUILD_DOCS)
|
||||
status("")
|
||||
status(" Documentation:")
|
||||
status(" Sphinx:" HAVE_SPHINX THEN "${SPHINX_BUILD} (ver ${SPHINX_VERSION})" ELSE NO)
|
||||
status(" PdfLaTeX compiler:" PDFLATEX_COMPILER THEN "${PDFLATEX_COMPILER}" ELSE NO)
|
||||
if(HAVE_SPHINX)
|
||||
status(" Build Documentation:" PDFLATEX_COMPILER THEN YES ELSE "YES (only HTML without math expressions)")
|
||||
else()
|
||||
status(" Build Documentation:" NO)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# samples and tests
|
||||
|
@ -1,7 +1,18 @@
|
||||
if(MSVC AND NOT PYTHON_EXECUTABLE)
|
||||
# search for executable with the same bitness as resulting binaries
|
||||
# standard FindPythonInterp always prefers executable from system path
|
||||
foreach(_CURRENT_VERSION ${Python_ADDITIONAL_VERSIONS} 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
|
||||
find_host_program(PYTHON_EXECUTABLE
|
||||
NAMES python${_CURRENT_VERSION} python
|
||||
PATHS [HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Python\\\\PythonCore\\\\${_CURRENT_VERSION}\\\\InstallPath]
|
||||
NO_SYSTEM_ENVIRONMENT_PATH
|
||||
)
|
||||
endforeach()
|
||||
endif()
|
||||
find_host_package(PythonInterp)
|
||||
|
||||
set(PYTHON_USE_NUMPY 0)
|
||||
set(HAVE_SPHINX 0)
|
||||
unset(PYTHON_USE_NUMPY CACHE)
|
||||
unset(HAVE_SPHINX CACHE)
|
||||
|
||||
if(PYTHON_EXECUTABLE)
|
||||
if(NOT ANDROID AND NOT IOS)
|
||||
@ -14,9 +25,10 @@ if(PYTHON_EXECUTABLE)
|
||||
|
||||
execute_process(COMMAND ${PYTHON_EXECUTABLE} --version
|
||||
ERROR_VARIABLE PYTHON_VERSION_FULL
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
ERROR_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
string(REGEX MATCH "[0-9]+.[0-9]+" PYTHON_VERSION_MAJOR_MINOR "${PYTHON_VERSION_FULL}")
|
||||
string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" PYTHON_VERSION_FULL "${PYTHON_VERSION_FULL}")
|
||||
|
||||
if(NOT ANDROID AND NOT IOS)
|
||||
if(CMAKE_HOST_UNIX)
|
||||
@ -46,18 +58,25 @@ if(PYTHON_EXECUTABLE)
|
||||
set(PYTHON_PACKAGES_PATH "${PYTHON_PATH}/Lib/site-packages")
|
||||
endif()
|
||||
|
||||
# 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]"
|
||||
RESULT_VARIABLE PYTHON_NUMPY_PROCESS
|
||||
OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIRS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
if(PYTHON_NUMPY_PROCESS EQUAL 0)
|
||||
set(PYTHON_USE_NUMPY 1)
|
||||
add_definitions(-DPYTHON_USE_NUMPY=1)
|
||||
file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIRS}" PYTHON_NUMPY_INCLUDE_DIRS)
|
||||
ocv_include_directories(${PYTHON_NUMPY_INCLUDE_DIRS})
|
||||
message(STATUS " Use NumPy headers from: ${PYTHON_NUMPY_INCLUDE_DIRS}")
|
||||
if(NOT PYTHON_NUMPY_INCLUDE_DIR)
|
||||
# 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]"
|
||||
RESULT_VARIABLE PYTHON_NUMPY_PROCESS
|
||||
OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIR
|
||||
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")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(PYTHON_NUMPY_INCLUDE_DIR)
|
||||
set(PYTHON_USE_NUMPY TRUE)
|
||||
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)
|
||||
endif()
|
||||
endif(NOT ANDROID AND NOT IOS)
|
||||
|
||||
@ -73,7 +92,7 @@ if(PYTHON_EXECUTABLE)
|
||||
find_host_program(SPHINX_BUILD sphinx-build)
|
||||
if(SPHINX_BUILD)
|
||||
set(HAVE_SPHINX 1)
|
||||
message(STATUS " Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}")
|
||||
message(STATUS " Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}")
|
||||
endif()
|
||||
endif()
|
||||
endif(BUILD_DOCS)
|
||||
|
@ -10,45 +10,29 @@ if(ANDROID OR IOS OR NOT PYTHONLIBS_FOUND OR NOT PYTHON_USE_NUMPY)
|
||||
endif()
|
||||
|
||||
set(the_description "The python bindings")
|
||||
ocv_add_module(python BINDINGS opencv_core opencv_flann opencv_imgproc opencv_video opencv_ml opencv_features2d opencv_highgui opencv_calib3d opencv_photo opencv_nonfree opencv_objdetect opencv_legacy opencv_contrib)
|
||||
ocv_add_module(python BINDINGS opencv_core opencv_flann opencv_imgproc opencv_video opencv_ml opencv_features2d opencv_highgui opencv_calib3d opencv_photo opencv_nonfree opencv_objdetect opencv_legacy)
|
||||
|
||||
ocv_include_directories(${PYTHON_INCLUDE_PATH})
|
||||
ocv_include_directories(
|
||||
add_definitions(-DPYTHON_USE_NUMPY=1)
|
||||
|
||||
ocv_module_include_directories(
|
||||
"${PYTHON_INCLUDE_PATH}"
|
||||
"${PYTHON_NUMPY_INCLUDE_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src2"
|
||||
"${OpenCV_SOURCE_DIR}/modules/core/include"
|
||||
"${OpenCV_SOURCE_DIR}/modules/flann/include"
|
||||
"${OpenCV_SOURCE_DIR}/modules/imgproc/include"
|
||||
"${OpenCV_SOURCE_DIR}/modules/video/include"
|
||||
"${OpenCV_SOURCE_DIR}/modules/photo/include"
|
||||
"${OpenCV_SOURCE_DIR}/modules/highgui/include"
|
||||
"${OpenCV_SOURCE_DIR}/modules/ml/include"
|
||||
"${OpenCV_SOURCE_DIR}/modules/features2d/include"
|
||||
"${OpenCV_SOURCE_DIR}/modules/flann/include"
|
||||
"${OpenCV_SOURCE_DIR}/modules/calib3d/include"
|
||||
"${OpenCV_SOURCE_DIR}/modules/objdetect/include"
|
||||
"${OpenCV_SOURCE_DIR}/modules/nonfree/include"
|
||||
"${OpenCV_SOURCE_DIR}/modules/legacy/include"
|
||||
"${OpenCV_SOURCE_DIR}/modules/contrib/include"
|
||||
)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set(opencv_hdrs "${OpenCV_SOURCE_DIR}/modules/core/include/opencv2/core/core.hpp"
|
||||
"${OpenCV_SOURCE_DIR}/modules/flann/include/opencv2/flann/miniflann.hpp"
|
||||
"${OpenCV_SOURCE_DIR}/modules/imgproc/include/opencv2/imgproc/imgproc.hpp"
|
||||
"${OpenCV_SOURCE_DIR}/modules/video/include/opencv2/video/background_segm.hpp"
|
||||
"${OpenCV_SOURCE_DIR}/modules/video/include/opencv2/video/tracking.hpp"
|
||||
"${OpenCV_SOURCE_DIR}/modules/photo/include/opencv2/photo/photo.hpp"
|
||||
"${OpenCV_SOURCE_DIR}/modules/highgui/include/opencv2/highgui/highgui.hpp"
|
||||
"${OpenCV_SOURCE_DIR}/modules/ml/include/opencv2/ml/ml.hpp"
|
||||
"${OpenCV_SOURCE_DIR}/modules/features2d/include/opencv2/features2d/features2d.hpp"
|
||||
"${OpenCV_SOURCE_DIR}/modules/nonfree/include/opencv2/nonfree/features2d.hpp"
|
||||
"${OpenCV_SOURCE_DIR}/modules/calib3d/include/opencv2/calib3d/calib3d.hpp"
|
||||
"${OpenCV_SOURCE_DIR}/modules/objdetect/include/opencv2/objdetect/objdetect.hpp")
|
||||
|
||||
if(MSVC)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
|
||||
endif()
|
||||
set(opencv_hdrs
|
||||
"${OPENCV_MODULE_opencv_core_LOCATION}/include/opencv2/core/core.hpp"
|
||||
"${OPENCV_MODULE_opencv_flann_LOCATION}/include/opencv2/flann/miniflann.hpp"
|
||||
"${OPENCV_MODULE_opencv_imgproc_LOCATION}/include/opencv2/imgproc/imgproc.hpp"
|
||||
"${OPENCV_MODULE_opencv_video_LOCATION}/include/opencv2/video/background_segm.hpp"
|
||||
"${OPENCV_MODULE_opencv_video_LOCATION}/include/opencv2/video/tracking.hpp"
|
||||
"${OPENCV_MODULE_opencv_photo_LOCATION}/include/opencv2/photo/photo.hpp"
|
||||
"${OPENCV_MODULE_opencv_highgui_LOCATION}/include/opencv2/highgui/highgui.hpp"
|
||||
"${OPENCV_MODULE_opencv_ml_LOCATION}/include/opencv2/ml/ml.hpp"
|
||||
"${OPENCV_MODULE_opencv_features2d_LOCATION}/include/opencv2/features2d/features2d.hpp"
|
||||
"${OPENCV_MODULE_opencv_nonfree_LOCATION}/include/opencv2/nonfree/features2d.hpp"
|
||||
"${OPENCV_MODULE_opencv_calib3d_LOCATION}/include/opencv2/calib3d/calib3d.hpp"
|
||||
"${OPENCV_MODULE_opencv_objdetect_LOCATION}/include/opencv2/objdetect/objdetect.hpp")
|
||||
|
||||
set(cv2_generated_hdrs
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_funcs.h"
|
||||
@ -57,53 +41,48 @@ set(cv2_generated_hdrs
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_type_reg.h"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_const_reg.h")
|
||||
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated0.i
|
||||
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/src2/gen.py" "${CMAKE_CURRENT_SOURCE_DIR}/src2"
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/api
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/defs
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/gen.py
|
||||
)
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/gen.py)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${cv2_generated_hdrs}
|
||||
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/src2/gen2.py" ${CMAKE_CURRENT_BINARY_DIR} ${opencv_hdrs}
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/gen2.py
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/hdr_parser.py
|
||||
DEPENDS ${opencv_hdrs})
|
||||
OUTPUT ${cv2_generated_hdrs}
|
||||
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/src2/gen2.py" ${CMAKE_CURRENT_BINARY_DIR} ${opencv_hdrs}
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/gen2.py
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/hdr_parser.py
|
||||
DEPENDS ${opencv_hdrs})
|
||||
|
||||
set(cv2_target "opencv_python")
|
||||
add_library(${cv2_target} SHARED src2/cv2.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated0.i ${cv2_generated_hdrs} src2/cv2.cv.hpp)
|
||||
target_link_libraries(${cv2_target} ${PYTHON_LIBRARIES} opencv_core opencv_flann opencv_imgproc opencv_video opencv_ml opencv_features2d opencv_highgui opencv_calib3d opencv_objdetect opencv_legacy opencv_contrib opencv_photo)
|
||||
|
||||
set_target_properties(${cv2_target} PROPERTIES PREFIX "")
|
||||
set_target_properties(${cv2_target} PROPERTIES OUTPUT_NAME "cv2")
|
||||
add_library(${the_module} SHARED src2/cv2.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated0.i ${cv2_generated_hdrs} src2/cv2.cv.hpp)
|
||||
target_link_libraries(${the_module} ${PYTHON_LIBRARIES} ${OPENCV_MODULE_${the_module}_DEPS})
|
||||
|
||||
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig; print distutils.sysconfig.get_config_var('SO')"
|
||||
RESULT_VARIABLE PYTHON_CVPY_PROCESS
|
||||
OUTPUT_VARIABLE CVPY_SUFFIX
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
set_target_properties(${cv2_target} PROPERTIES SUFFIX ${CVPY_SUFFIX})
|
||||
set_target_properties(${the_module} PROPERTIES
|
||||
PREFIX ""
|
||||
OUTPUT_NAME cv2
|
||||
SUFFIX ${CVPY_SUFFIX})
|
||||
|
||||
if (MSVC AND NOT BUILD_SHARED_LIBS)
|
||||
set_target_properties(${cv2_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
|
||||
if(MSVC AND NOT BUILD_SHARED_LIBS)
|
||||
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
|
||||
endif()
|
||||
|
||||
set(cvpymodules ${cv2_target})
|
||||
|
||||
if(WIN32)
|
||||
set(CVPY_PATH "Python${PYTHON_VERSION_MAJOR_MINOR}/Lib/site-packages")
|
||||
if(MSVC)
|
||||
set(PYTHON_INSTALL_CONFIGURATIONS CONFIGURATIONS Release)
|
||||
else()
|
||||
set(CVPY_PATH ${PYTHON_PACKAGES_PATH})
|
||||
set(PYTHON_INSTALL_CONFIGURATIONS "")
|
||||
endif()
|
||||
|
||||
install(TARGETS ${cvpymodules} ${PYTHON_INSTALL_CONFIGURATIONS}
|
||||
RUNTIME DESTINATION ${CVPY_PATH} COMPONENT main
|
||||
LIBRARY DESTINATION ${CVPY_PATH} COMPONENT main
|
||||
ARCHIVE DESTINATION ${CVPY_PATH} COMPONENT main
|
||||
)
|
||||
install(FILES src2/cv.py ${PYTHON_INSTALL_CONFIGURATIONS} DESTINATION ${CVPY_PATH} COMPONENT main)
|
||||
install(TARGETS ${the_module}
|
||||
${PYTHON_INSTALL_CONFIGURATIONS}
|
||||
RUNTIME DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT main
|
||||
LIBRARY DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT main
|
||||
ARCHIVE DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT main
|
||||
)
|
||||
install(FILES src2/cv.py ${PYTHON_INSTALL_CONFIGURATIONS} DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT main)
|
||||
|
Loading…
Reference in New Issue
Block a user