2012-02-03 12:26:49 +01:00
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# CMake file for python support
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
|
2012-01-03 14:48:12 +01:00
|
|
|
if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
|
2012-02-03 12:26:49 +01:00
|
|
|
ocv_module_disable(python)
|
2012-01-03 14:48:12 +01:00
|
|
|
endif()
|
2012-02-06 12:30:59 +01:00
|
|
|
if(ANDROID OR IOS OR NOT PYTHONLIBS_FOUND OR NOT PYTHON_USE_NUMPY)
|
2012-02-03 12:26:49 +01:00
|
|
|
ocv_module_disable(python)
|
2012-01-25 10:04:49 +01:00
|
|
|
endif()
|
2012-01-03 14:48:12 +01:00
|
|
|
|
2012-02-03 12:26:49 +01:00
|
|
|
set(the_description "The python bindings")
|
2012-04-09 14:07:47 +02:00
|
|
|
ocv_add_module(python BINDINGS opencv_core opencv_flann opencv_imgproc opencv_video opencv_ml opencv_features2d opencv_highgui opencv_calib3d opencv_photo opencv_objdetect opencv_legacy OPTIONAL opencv_nonfree)
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2012-04-08 19:36:41 +02:00
|
|
|
add_definitions(-DPYTHON_USE_NUMPY=1)
|
|
|
|
|
|
|
|
ocv_module_include_directories(
|
|
|
|
"${PYTHON_INCLUDE_PATH}"
|
|
|
|
"${PYTHON_NUMPY_INCLUDE_DIR}"
|
2011-05-03 18:00:31 +02:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src2"
|
2010-05-11 19:44:00 +02:00
|
|
|
)
|
2010-11-02 18:58:22 +01:00
|
|
|
|
2012-04-08 19:36:41 +02:00
|
|
|
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_calib3d_LOCATION}/include/opencv2/calib3d/calib3d.hpp"
|
|
|
|
"${OPENCV_MODULE_opencv_objdetect_LOCATION}/include/opencv2/objdetect/objdetect.hpp")
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2012-04-09 14:07:47 +02:00
|
|
|
if(HAVE_opencv_nonfree)
|
|
|
|
list(APPEND opencv_hdrs "${OPENCV_MODULE_opencv_nonfree_LOCATION}/include/opencv2/nonfree/features2d.hpp"
|
|
|
|
"${OPENCV_MODULE_opencv_nonfree_LOCATION}/include/opencv2/nonfree/nonfree.hpp")
|
|
|
|
endif()
|
|
|
|
|
2011-05-03 18:00:31 +02:00
|
|
|
set(cv2_generated_hdrs
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_funcs.h"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_func_tab.h"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_types.h"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_type_reg.h"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_const_reg.h")
|
2010-05-11 19:44:00 +02:00
|
|
|
|
2011-05-03 18:00:31 +02:00
|
|
|
add_custom_command(
|
2011-07-12 14:56:03 +02:00
|
|
|
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
|
2012-04-08 19:36:41 +02:00
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/gen.py)
|
2011-05-03 18:00:31 +02:00
|
|
|
|
2011-07-12 14:56:03 +02:00
|
|
|
add_custom_command(
|
2012-04-08 19:36:41 +02:00
|
|
|
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})
|
2011-07-12 14:56:03 +02:00
|
|
|
|
2012-04-08 19:36:41 +02:00
|
|
|
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})
|
2011-07-12 14:56:03 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2012-04-08 19:36:41 +02:00
|
|
|
set_target_properties(${the_module} PROPERTIES
|
|
|
|
PREFIX ""
|
|
|
|
OUTPUT_NAME cv2
|
|
|
|
SUFFIX ${CVPY_SUFFIX})
|
2011-05-03 18:00:31 +02:00
|
|
|
|
2012-04-10 17:50:19 +02:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")
|
2012-04-08 23:49:19 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(MSVC AND NOT ENABLE_NOISY_WARNINGS)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4100") #unreferenced formal parameter
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4127") #conditional expression is constant
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4505") #unreferenced local function has been removed
|
|
|
|
string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
2011-05-30 16:08:43 +02:00
|
|
|
endif()
|
|
|
|
|
2012-04-10 17:50:19 +02:00
|
|
|
if(MSVC AND NOT BUILD_SHARED_LIBS)
|
|
|
|
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
|
|
|
|
endif()
|
|
|
|
|
2012-04-08 19:36:41 +02:00
|
|
|
if(MSVC)
|
2012-03-30 01:10:21 +02:00
|
|
|
set(PYTHON_INSTALL_CONFIGURATIONS CONFIGURATIONS Release)
|
2010-05-11 19:44:00 +02:00
|
|
|
else()
|
2012-03-30 01:10:21 +02:00
|
|
|
set(PYTHON_INSTALL_CONFIGURATIONS "")
|
2010-05-11 19:44:00 +02:00
|
|
|
endif()
|
2011-08-12 20:03:01 +02:00
|
|
|
|
2012-04-08 19:36:41 +02:00
|
|
|
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)
|