2017-09-25 21:52:07 +08:00
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# CMake file for js support
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
set(the_description "The js bindings")
|
2018-09-26 23:53:02 +08:00
|
|
|
|
|
|
|
if(NOT BUILD_opencv_js) # should be enabled explicitly (by build_js.py script)
|
|
|
|
ocv_module_disable(js)
|
|
|
|
endif()
|
2017-09-25 21:52:07 +08:00
|
|
|
|
|
|
|
set(OPENCV_JS "opencv.js")
|
|
|
|
|
2018-09-20 19:55:45 +08:00
|
|
|
find_path(EMSCRIPTEN_INCLUDE_DIR
|
|
|
|
emscripten/bind.h
|
|
|
|
PATHS
|
|
|
|
ENV EMSCRIPTEN_ROOT
|
|
|
|
PATH_SUFFIXES system/include include
|
|
|
|
DOC "Location of Emscripten SDK")
|
|
|
|
|
|
|
|
if(NOT EMSCRIPTEN_INCLUDE_DIR OR NOT PYTHON_DEFAULT_AVAILABLE)
|
2018-09-26 23:53:02 +08:00
|
|
|
set(DISABLE_MSG "Module 'js' disabled because the following dependencies are not found:")
|
2018-09-20 19:55:45 +08:00
|
|
|
if(NOT EMSCRIPTEN_INCLUDE_DIR)
|
|
|
|
set(DISABLE_MSG "${DISABLE_MSG} Emscripten")
|
|
|
|
endif()
|
|
|
|
if(NOT PYTHON_DEFAULT_AVAILABLE)
|
|
|
|
set(DISABLE_MSG "${DISABLE_MSG} Python")
|
|
|
|
endif()
|
|
|
|
message(STATUS ${DISABLE_MSG})
|
2018-09-26 23:53:02 +08:00
|
|
|
ocv_module_disable(js)
|
2018-09-20 19:55:45 +08:00
|
|
|
endif()
|
|
|
|
|
2018-09-26 23:53:02 +08:00
|
|
|
ocv_add_module(js BINDINGS)
|
2017-09-25 21:52:07 +08:00
|
|
|
|
2018-09-20 19:55:45 +08:00
|
|
|
ocv_module_include_directories(${EMSCRIPTEN_INCLUDE_DIR})
|
2017-09-25 21:52:07 +08:00
|
|
|
|
|
|
|
# get list of modules to wrap
|
2018-09-26 23:53:02 +08:00
|
|
|
# message(STATUS "Wrapped in js:")
|
2017-09-25 21:52:07 +08:00
|
|
|
set(OPENCV_JS_MODULES)
|
|
|
|
foreach(m ${OPENCV_MODULES_BUILD})
|
2018-09-26 23:53:02 +08:00
|
|
|
if(";${OPENCV_MODULE_${m}_WRAPPERS};" MATCHES ";js;" AND HAVE_${m})
|
2017-09-25 21:52:07 +08:00
|
|
|
list(APPEND OPENCV_JS_MODULES ${m})
|
|
|
|
# message(STATUS "\t${m}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
set(opencv_hdrs "")
|
|
|
|
foreach(m ${OPENCV_JS_MODULES})
|
|
|
|
list(APPEND opencv_hdrs ${OPENCV_MODULE_${m}_HEADERS})
|
|
|
|
endforeach(m)
|
|
|
|
|
|
|
|
# header blacklist
|
|
|
|
ocv_list_filterout(opencv_hdrs "modules/.*.h$")
|
|
|
|
ocv_list_filterout(opencv_hdrs "modules/core/.*/cuda")
|
2018-02-02 17:26:22 +08:00
|
|
|
ocv_list_filterout(opencv_hdrs "modules/core/.*/opencl")
|
2017-09-25 21:52:07 +08:00
|
|
|
ocv_list_filterout(opencv_hdrs "modules/core/include/opencv2/core/opengl.hpp")
|
|
|
|
ocv_list_filterout(opencv_hdrs "modules/core/include/opencv2/core/ocl.hpp")
|
|
|
|
ocv_list_filterout(opencv_hdrs "modules/cuda.*")
|
|
|
|
ocv_list_filterout(opencv_hdrs "modules/cudev")
|
|
|
|
ocv_list_filterout(opencv_hdrs "modules/core/.*/hal/")
|
|
|
|
ocv_list_filterout(opencv_hdrs "modules/.*/detection_based_tracker.hpp") # Conditional compilation
|
2017-10-09 21:14:01 +08:00
|
|
|
ocv_list_filterout(opencv_hdrs "modules/core/include/opencv2/core/utils/.*")
|
2017-09-25 21:52:07 +08:00
|
|
|
|
|
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/headers.txt" "${opencv_hdrs}")
|
|
|
|
|
|
|
|
set(bindings_cpp "${CMAKE_CURRENT_BINARY_DIR}/bindings.cpp")
|
|
|
|
|
|
|
|
set(scripts_hdr_parser "${CMAKE_CURRENT_SOURCE_DIR}/../python/src2/hdr_parser.py")
|
|
|
|
|
|
|
|
set(JS_HELPER "${CMAKE_CURRENT_SOURCE_DIR}/src/helpers.js")
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${bindings_cpp}
|
|
|
|
COMMAND ${PYTHON_DEFAULT_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/src/embindgen.py" ${scripts_hdr_parser} ${bindings_cpp} "${CMAKE_CURRENT_BINARY_DIR}/headers.txt" "${CMAKE_CURRENT_SOURCE_DIR}/src/core_bindings.cpp"
|
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/core_bindings.cpp
|
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/embindgen.py
|
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/templates.py
|
|
|
|
DEPENDS ${scripts_hdr_parser}
|
2018-08-31 19:48:44 +08:00
|
|
|
#(not needed - generated by CMake) DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/headers.txt
|
2017-09-25 21:52:07 +08:00
|
|
|
DEPENDS ${opencv_hdrs}
|
|
|
|
DEPENDS ${JS_HELPER})
|
|
|
|
|
|
|
|
add_definitions("-std=c++11")
|
|
|
|
|
|
|
|
link_libraries(${OPENCV_MODULE_${the_module}_DEPS})
|
|
|
|
|
|
|
|
ocv_add_executable(${the_module} ${bindings_cpp})
|
|
|
|
|
2018-09-08 14:49:39 +08:00
|
|
|
set(COMPILE_FLAGS "")
|
|
|
|
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
|
|
|
set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-missing-prototypes")
|
|
|
|
endif()
|
|
|
|
if(COMPILE_FLAGS)
|
|
|
|
set_target_properties(${the_module} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS})
|
|
|
|
endif()
|
2018-10-15 22:35:21 +08:00
|
|
|
set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} --memory-init-file 0 -s TOTAL_MEMORY=134217728 -s ALLOW_MEMORY_GROWTH=1")
|
|
|
|
set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -s MODULARIZE=1 -s SINGLE_FILE=1")
|
|
|
|
set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -s EXPORT_NAME=\"'cv'\" -s DEMANGLE_SUPPORT=1")
|
2018-10-16 04:15:42 +08:00
|
|
|
set(EMSCRIPTEN_LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS} -s FORCE_FILESYSTEM=1 --use-preload-plugins --bind --post-js ${JS_HELPER} ${COMPILE_FLAGS}")
|
2018-10-15 22:35:21 +08:00
|
|
|
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "${EMSCRIPTEN_LINK_FLAGS}")
|
2017-09-25 21:52:07 +08:00
|
|
|
|
|
|
|
# add UMD wrapper
|
|
|
|
set(MODULE_JS_PATH "${OpenCV_BINARY_DIR}/bin/${the_module}.js")
|
|
|
|
set(OCV_JS_PATH "${OpenCV_BINARY_DIR}/bin/${OPENCV_JS}")
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${OCV_JS_PATH}
|
|
|
|
COMMAND ${PYTHON_DEFAULT_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/src/make_umd.py" ${MODULE_JS_PATH} "${OCV_JS_PATH}"
|
|
|
|
DEPENDS ${the_module}
|
|
|
|
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/make_umd.py")
|
|
|
|
|
|
|
|
add_custom_target(${OPENCV_JS} ALL
|
|
|
|
DEPENDS ${OCV_JS_PATH}
|
|
|
|
DEPENDS ${the_module})
|
|
|
|
|
|
|
|
# test
|
|
|
|
set(opencv_test_js_bin_dir "${EXECUTABLE_OUTPUT_PATH}")
|
|
|
|
set(test_dir ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
|
|
|
|
|
|
|
set(opencv_test_js_file_deps "")
|
|
|
|
|
|
|
|
# message(STATUS "${opencv_test_js_bin_dir}")
|
|
|
|
|
|
|
|
# make sure the build directory exists
|
|
|
|
file(MAKE_DIRECTORY "${opencv_test_js_bin_dir}")
|
|
|
|
|
|
|
|
# gather and copy specific files for js test
|
|
|
|
file(GLOB_RECURSE test_files RELATIVE "${test_dir}" "${test_dir}/*")
|
|
|
|
foreach(f ${test_files})
|
|
|
|
# message(STATUS "copy ${test_dir}/${f} ${opencv_test_js_bin_dir}/${f}")
|
|
|
|
add_custom_command(OUTPUT "${opencv_test_js_bin_dir}/${f}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${test_dir}/${f}" "${opencv_test_js_bin_dir}/${f}"
|
|
|
|
DEPENDS "${test_dir}/${f}"
|
|
|
|
COMMENT "Copying ${f}"
|
|
|
|
)
|
|
|
|
list(APPEND opencv_test_js_file_deps "${test_dir}/${f}" "${opencv_test_js_bin_dir}/${f}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# copy test data
|
|
|
|
set(test_data "haarcascade_frontalface_default.xml")
|
|
|
|
set(test_data_path "${PROJECT_SOURCE_DIR}/../../data/haarcascades/${test_data}")
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT "${opencv_test_js_bin_dir}/${test_data}"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${test_data_path}" "${opencv_test_js_bin_dir}/${test_data}"
|
|
|
|
DEPENDS "${test_data_path}"
|
|
|
|
COMMENT "Copying ${test_data}"
|
|
|
|
)
|
|
|
|
list(APPEND opencv_test_js_file_deps "${test_data_path}" "${opencv_test_js_bin_dir}/${test_data}")
|
|
|
|
|
|
|
|
add_custom_target(${PROJECT_NAME}_test ALL
|
|
|
|
DEPENDS ${OCV_JS_PATH} ${opencv_test_js_file_deps})
|