2012-02-03 19:26:49 +08:00
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# CMake file for python support
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
|
2012-01-03 21:48:12 +08:00
|
|
|
if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
|
2012-02-03 19:26:49 +08:00
|
|
|
ocv_module_disable(python)
|
2012-01-03 21:48:12 +08:00
|
|
|
endif()
|
2013-04-12 21:05:23 +08:00
|
|
|
|
2013-08-23 22:41:13 +08:00
|
|
|
if(ANDROID OR IOS OR NOT PYTHONLIBS_FOUND OR NOT PYTHON_NUMPY_INCLUDE_DIRS)
|
2012-02-03 19:26:49 +08:00
|
|
|
ocv_module_disable(python)
|
2012-01-25 17:04:49 +08:00
|
|
|
endif()
|
2012-01-03 21:48:12 +08:00
|
|
|
|
2012-02-03 19:26:49 +08:00
|
|
|
set(the_description "The python bindings")
|
2014-07-22 18:22:46 +08:00
|
|
|
|
2014-07-27 20:35:35 +08:00
|
|
|
set(candidate_deps "")
|
2014-07-22 18:22:46 +08:00
|
|
|
foreach(mp ${OPENCV_MODULES_PATH} ${OPENCV_EXTRA_MODULES_PATH})
|
|
|
|
file(GLOB names "${mp}/*")
|
2014-07-23 18:54:04 +08:00
|
|
|
foreach(m IN LISTS names)
|
|
|
|
if(IS_DIRECTORY ${m})
|
|
|
|
get_filename_component(m ${m} NAME)
|
2014-07-27 20:35:35 +08:00
|
|
|
list(APPEND candidate_deps "opencv_${m}")
|
2014-07-22 18:22:46 +08:00
|
|
|
endif()
|
2014-07-23 18:54:04 +08:00
|
|
|
endforeach(m)
|
|
|
|
endforeach(mp)
|
2014-07-27 22:03:27 +08:00
|
|
|
|
|
|
|
# module blacklist
|
2014-07-27 20:35:35 +08:00
|
|
|
ocv_list_filterout(candidate_deps "^opencv_cud(a|ev)")
|
2014-07-27 21:41:12 +08:00
|
|
|
ocv_list_filterout(candidate_deps "^opencv_adas$")
|
2014-07-27 22:03:27 +08:00
|
|
|
ocv_list_filterout(candidate_deps "^opencv_tracking$")
|
2014-07-27 21:41:12 +08:00
|
|
|
|
2014-07-22 18:22:46 +08:00
|
|
|
|
|
|
|
ocv_add_module(python BINDINGS OPTIONAL ${candidate_deps})
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2012-04-14 05:50:59 +08:00
|
|
|
ocv_module_include_directories(
|
|
|
|
"${PYTHON_INCLUDE_PATH}"
|
2013-08-23 22:41:13 +08:00
|
|
|
${PYTHON_NUMPY_INCLUDE_DIRS}
|
2011-05-04 00:00:31 +08:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src2"
|
2010-05-12 01:44:00 +08:00
|
|
|
)
|
2010-11-03 01:58:22 +08:00
|
|
|
|
2012-04-14 05:50:59 +08:00
|
|
|
|
2014-07-27 20:35:35 +08:00
|
|
|
set(opencv_hdrs "")
|
2014-07-23 18:54:04 +08:00
|
|
|
foreach(m IN LISTS OPENCV_MODULE_opencv_python_DEPS)
|
2014-07-27 20:35:35 +08:00
|
|
|
list(APPEND opencv_hdrs ${OPENCV_MODULE_${m}_HEADERS})
|
2014-07-23 18:54:04 +08:00
|
|
|
endforeach(m)
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2014-07-27 22:03:27 +08:00
|
|
|
# header blacklist
|
2014-07-27 20:35:35 +08:00
|
|
|
ocv_list_filterout(opencv_hdrs ".h$")
|
|
|
|
ocv_list_filterout(opencv_hdrs "opencv2/core/cuda")
|
|
|
|
ocv_list_filterout(opencv_hdrs "opencv2/objdetect/detection_based_tracker.hpp")
|
|
|
|
ocv_list_filterout(opencv_hdrs "opencv2/optim.hpp")
|
|
|
|
|
2011-05-04 00:00:31 +08:00
|
|
|
set(cv2_generated_hdrs
|
2014-05-12 18:58:54 +08:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_include.h"
|
2011-05-04 00:00:31 +08:00
|
|
|
"${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-12 01:44:00 +08:00
|
|
|
|
2014-07-27 20:35:35 +08:00
|
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/headers.txt" "${opencv_hdrs}")
|
2011-07-12 20:56:03 +08:00
|
|
|
add_custom_command(
|
2012-04-14 05:50:59 +08:00
|
|
|
OUTPUT ${cv2_generated_hdrs}
|
2014-07-27 20:35:35 +08:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/src2/gen2.py" ${CMAKE_CURRENT_BINARY_DIR} "${CMAKE_CURRENT_BINARY_DIR}/headers.txt"
|
2012-04-14 05:50:59 +08:00
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/gen2.py
|
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/hdr_parser.py
|
2014-07-27 20:35:35 +08:00
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/headers.txt
|
2012-04-14 05:50:59 +08:00
|
|
|
DEPENDS ${opencv_hdrs})
|
|
|
|
|
2013-04-12 21:05:23 +08:00
|
|
|
add_library(${the_module} SHARED src2/cv2.cpp ${cv2_generated_hdrs})
|
2013-03-21 00:42:07 +08:00
|
|
|
set_target_properties(${the_module} PROPERTIES COMPILE_DEFINITIONS OPENCV_NOSTL)
|
|
|
|
|
2012-06-13 00:18:14 +08:00
|
|
|
if(PYTHON_DEBUG_LIBRARIES AND NOT PYTHON_LIBRARIES MATCHES "optimized.*debug")
|
2012-04-30 22:33:52 +08:00
|
|
|
target_link_libraries(${the_module} debug ${PYTHON_DEBUG_LIBRARIES} optimized ${PYTHON_LIBRARIES})
|
|
|
|
else()
|
|
|
|
target_link_libraries(${the_module} ${PYTHON_LIBRARIES})
|
|
|
|
endif()
|
|
|
|
target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS})
|
2011-07-12 20:56:03 +08:00
|
|
|
|
2013-06-13 04:04:34 +08:00
|
|
|
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('SO'))"
|
2011-07-12 20:56:03 +08:00
|
|
|
RESULT_VARIABLE PYTHON_CVPY_PROCESS
|
|
|
|
OUTPUT_VARIABLE CVPY_SUFFIX
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
2012-04-14 05:50:59 +08:00
|
|
|
set_target_properties(${the_module} PROPERTIES
|
|
|
|
PREFIX ""
|
|
|
|
OUTPUT_NAME cv2
|
|
|
|
SUFFIX ${CVPY_SUFFIX})
|
2011-05-04 00:00:31 +08:00
|
|
|
|
2013-01-22 21:56:04 +08:00
|
|
|
if(ENABLE_SOLUTION_FOLDERS)
|
|
|
|
set_target_properties(${the_module} PROPERTIES FOLDER "bindings")
|
|
|
|
endif()
|
|
|
|
|
2013-07-29 18:16:37 +08:00
|
|
|
if(MSVC)
|
|
|
|
add_definitions(-DCVAPI_EXPORTS)
|
|
|
|
endif()
|
|
|
|
|
2012-04-14 05:50:59 +08:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")
|
2011-05-30 22:08:43 +08:00
|
|
|
endif()
|
|
|
|
|
2012-04-14 05:50:59 +08:00
|
|
|
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
|
2012-10-17 07:18:30 +08:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4505") #unreferenced local function has been removed
|
2012-04-14 05:50:59 +08:00
|
|
|
string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(MSVC AND NOT BUILD_SHARED_LIBS)
|
|
|
|
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
|
|
|
|
endif()
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
if(MSVC AND NOT PYTHON_DEBUG_LIBRARIES)
|
2012-03-30 07:10:21 +08:00
|
|
|
set(PYTHON_INSTALL_CONFIGURATIONS CONFIGURATIONS Release)
|
2010-05-12 01:44:00 +08:00
|
|
|
else()
|
2012-03-30 07:10:21 +08:00
|
|
|
set(PYTHON_INSTALL_CONFIGURATIONS "")
|
2010-05-12 01:44:00 +08:00
|
|
|
endif()
|
2011-08-13 02:03:01 +08:00
|
|
|
|
2013-10-04 21:15:02 +08:00
|
|
|
if(WIN32)
|
|
|
|
set(PYTHON_INSTALL_ARCHIVE "")
|
|
|
|
else()
|
2014-01-17 20:30:31 +08:00
|
|
|
set(PYTHON_INSTALL_ARCHIVE ARCHIVE DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT python)
|
2013-10-04 21:15:02 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT INSTALL_CREATE_DISTRIB)
|
|
|
|
install(TARGETS ${the_module}
|
|
|
|
${PYTHON_INSTALL_CONFIGURATIONS}
|
2014-01-17 20:30:31 +08:00
|
|
|
RUNTIME DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT python
|
|
|
|
LIBRARY DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT python
|
2013-10-04 21:15:02 +08:00
|
|
|
${PYTHON_INSTALL_ARCHIVE}
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
if(DEFINED PYTHON_VERSION_MAJOR)
|
|
|
|
set(__ver "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
|
|
|
|
else()
|
|
|
|
set(__ver "unknown")
|
|
|
|
endif()
|
|
|
|
install(TARGETS ${the_module}
|
|
|
|
CONFIGURATIONS Release
|
2014-01-17 20:30:31 +08:00
|
|
|
RUNTIME DESTINATION python/${__ver}/${OpenCV_ARCH} COMPONENT python
|
|
|
|
LIBRARY DESTINATION python/${__ver}/${OpenCV_ARCH} COMPONENT python
|
2013-10-04 21:15:02 +08:00
|
|
|
)
|
|
|
|
endif()
|