2017-12-10 02:54:52 +08:00
|
|
|
set(MODULE_NAME "python_bindings_generator")
|
2017-12-16 05:36:22 +08:00
|
|
|
set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE)
|
2017-12-10 02:54:52 +08:00
|
|
|
ocv_add_module(${MODULE_NAME} INTERNAL)
|
|
|
|
|
|
|
|
set(OPENCV_PYTHON_SIGNATURES_FILE "${CMAKE_CURRENT_BINARY_DIR}/pyopencv_signatures.json" CACHE INTERNAL "")
|
|
|
|
set(OPENCV_PYTHON_BINDINGS_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "")
|
|
|
|
|
|
|
|
# This file is included from a subdirectory
|
|
|
|
set(PYTHON_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../")
|
|
|
|
|
|
|
|
# get list of modules to wrap
|
|
|
|
set(OPENCV_PYTHON_MODULES)
|
|
|
|
foreach(m ${OPENCV_MODULES_BUILD})
|
|
|
|
if (";${OPENCV_MODULE_${m}_WRAPPERS};" MATCHES ";${MODULE_NAME};" AND HAVE_${m})
|
|
|
|
list(APPEND OPENCV_PYTHON_MODULES ${m})
|
|
|
|
#message(STATUS "\t${m}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
set(opencv_hdrs "")
|
|
|
|
set(opencv_userdef_hdrs "")
|
|
|
|
foreach(m ${OPENCV_PYTHON_MODULES})
|
2018-07-27 19:29:01 +08:00
|
|
|
foreach (hdr ${OPENCV_MODULE_${m}_HEADERS})
|
|
|
|
ocv_is_subdir(is_sub "${OPENCV_MODULE_${m}_LOCATION}/include" "${hdr}")
|
|
|
|
if(is_sub)
|
|
|
|
list(APPEND opencv_hdrs "${hdr}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2018-08-25 06:18:33 +08:00
|
|
|
file(GLOB hdr ${OPENCV_MODULE_${m}_LOCATION}/misc/python/shadow*.hpp)
|
|
|
|
list(APPEND opencv_hdrs ${hdr})
|
2017-12-10 02:54:52 +08:00
|
|
|
file(GLOB userdef_hdrs ${OPENCV_MODULE_${m}_LOCATION}/misc/python/pyopencv*.hpp)
|
|
|
|
list(APPEND opencv_userdef_hdrs ${userdef_hdrs})
|
|
|
|
endforeach(m)
|
|
|
|
|
|
|
|
# header blacklist
|
|
|
|
ocv_list_filterout(opencv_hdrs "modules/.*\\\\.h$")
|
2018-08-06 19:46:46 +08:00
|
|
|
ocv_list_filterout(opencv_hdrs "modules/core/.*/cuda/")
|
2017-12-10 02:54:52 +08:00
|
|
|
ocv_list_filterout(opencv_hdrs "modules/core/.*/hal/")
|
2018-01-27 21:09:28 +08:00
|
|
|
ocv_list_filterout(opencv_hdrs "modules/core/.*/opencl/")
|
2017-12-10 02:54:52 +08:00
|
|
|
ocv_list_filterout(opencv_hdrs "modules/.+/utils/.*")
|
|
|
|
ocv_list_filterout(opencv_hdrs "modules/.*\\\\.inl\\\\.h*")
|
|
|
|
ocv_list_filterout(opencv_hdrs "modules/.*_inl\\\\.h*")
|
|
|
|
ocv_list_filterout(opencv_hdrs "modules/.*\\\\.details\\\\.h*")
|
2018-06-07 17:32:48 +08:00
|
|
|
ocv_list_filterout(opencv_hdrs "modules/.*\\\\.private\\\\.h*")
|
2018-10-28 21:32:27 +08:00
|
|
|
ocv_list_filterout(opencv_hdrs "modules/.*/private\\\\.h*")
|
2017-12-10 02:54:52 +08:00
|
|
|
ocv_list_filterout(opencv_hdrs "modules/.*/detection_based_tracker\\\\.hpp") # Conditional compilation
|
2018-08-06 19:46:46 +08:00
|
|
|
if(NOT HAVE_CUDA)
|
|
|
|
ocv_list_filterout(opencv_hdrs "modules/cuda.*")
|
|
|
|
ocv_list_filterout(opencv_hdrs "modules/cudev")
|
|
|
|
endif()
|
2017-12-10 02:54:52 +08:00
|
|
|
|
2018-01-05 12:42:24 +08:00
|
|
|
set(cv2_generated_files
|
2017-12-10 02:54:52 +08:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_include.h"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_funcs.h"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_types.h"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_type_reg.h"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_ns_reg.h"
|
|
|
|
"${OPENCV_PYTHON_SIGNATURES_FILE}"
|
|
|
|
)
|
|
|
|
|
|
|
|
string(REPLACE ";" "\n" opencv_hdrs_ "${opencv_hdrs}")
|
|
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/headers.txt" "${opencv_hdrs_}")
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${cv2_generated_files}
|
2018-01-05 12:42:24 +08:00
|
|
|
COMMAND "${PYTHON_DEFAULT_EXECUTABLE}" "${PYTHON_SOURCE_DIR}/src2/gen2.py" "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/headers.txt"
|
|
|
|
DEPENDS "${PYTHON_SOURCE_DIR}/src2/gen2.py"
|
|
|
|
"${PYTHON_SOURCE_DIR}/src2/hdr_parser.py"
|
|
|
|
# not a real build dependency (file(WRITE) result): ${CMAKE_CURRENT_BINARY_DIR}/headers.txt
|
|
|
|
${opencv_hdrs}
|
2017-12-10 02:54:52 +08:00
|
|
|
COMMENT "Generate files for Python bindings and documentation"
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(gen_opencv_python_source DEPENDS ${cv2_generated_files})
|
|
|
|
|
|
|
|
set(cv2_custom_hdr "${CMAKE_CURRENT_BINARY_DIR}/pyopencv_custom_headers.h")
|
2018-01-05 12:42:24 +08:00
|
|
|
set(cv2_custom_hdr_str "//user-defined headers\n")
|
2017-12-10 02:54:52 +08:00
|
|
|
foreach(uh ${opencv_userdef_hdrs})
|
2018-01-05 12:42:24 +08:00
|
|
|
set(cv2_custom_hdr_str "${cv2_custom_hdr_str}#include \"${uh}\"\n")
|
2017-12-10 02:54:52 +08:00
|
|
|
endforeach(uh)
|
2018-01-05 12:42:24 +08:00
|
|
|
if(EXISTS "${cv2_custom_hdr}")
|
|
|
|
file(READ "${cv2_custom_hdr}" __content)
|
|
|
|
else()
|
|
|
|
set(__content "")
|
|
|
|
endif()
|
|
|
|
if("${__content}" STREQUAL "${cv2_custom_hdr_str}")
|
|
|
|
# Up-to-date
|
|
|
|
else()
|
|
|
|
file(WRITE "${cv2_custom_hdr}" "${cv2_custom_hdr_str}")
|
|
|
|
endif()
|
|
|
|
unset(__content)
|
2018-06-07 17:32:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Configuration for standalone build of Python bindings
|
|
|
|
#
|
|
|
|
set(PYTHON_CONFIG_SCRIPT "")
|
|
|
|
ocv_cmake_script_append_var(PYTHON_CONFIG_SCRIPT
|
|
|
|
CMAKE_BUILD_TYPE
|
|
|
|
BUILD_SHARED_LIBS
|
|
|
|
|
|
|
|
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
|
|
|
|
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
|
|
|
|
|
|
|
CV_GCC CV_CLANG ENABLE_NOISY_WARNINGS
|
|
|
|
|
|
|
|
CMAKE_MODULE_LINKER_FLAGS
|
|
|
|
CMAKE_INSTALL_PREFIX
|
2018-10-28 21:32:27 +08:00
|
|
|
OPENCV_PYTHON_INSTALL_PATH
|
2018-06-07 17:32:48 +08:00
|
|
|
|
|
|
|
OpenCV_SOURCE_DIR
|
|
|
|
|
|
|
|
OPENCV_FORCE_PYTHON_LIBS
|
|
|
|
OPENCV_PYTHON_SKIP_LINKER_EXCLUDE_LIBS
|
|
|
|
|
|
|
|
OPENCV_PYTHON_BINDINGS_DIR
|
|
|
|
cv2_custom_hdr
|
|
|
|
cv2_generated_files
|
|
|
|
)
|
|
|
|
set(CMAKE_HELPER_SCRIPT "${CMAKE_BINARY_DIR}/opencv_python_config.cmake")
|
|
|
|
file(GENERATE OUTPUT "${CMAKE_HELPER_SCRIPT}" CONTENT "${PYTHON_CONFIG_SCRIPT}")
|