CMakeLists.txt 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. set(MODULE_NAME "js_bindings_generator")
  2. set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE)
  3. ocv_add_module(${MODULE_NAME} INTERNAL)
  4. set(OPENCV_JS_BINDINGS_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "")
  5. file(REMOVE_RECURSE "${OPENCV_JS_BINDINGS_DIR}/gen")
  6. file(MAKE_DIRECTORY "${OPENCV_JS_BINDINGS_DIR}/gen")
  7. file(REMOVE "${OPENCV_DEPHELPER}/gen_opencv_js_source") # force re-run after CMake
  8. # This file is included from a subdirectory
  9. set(JS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
  10. include(${JS_SOURCE_DIR}/common.cmake) # fill OPENCV_JS_MODULES
  11. set(opencv_hdrs "")
  12. foreach(m ${OPENCV_JS_MODULES})
  13. list(APPEND opencv_hdrs ${OPENCV_MODULE_${m}_HEADERS})
  14. endforeach(m)
  15. # header blacklist
  16. ocv_list_filterout(opencv_hdrs "modules/.*.h$")
  17. ocv_list_filterout(opencv_hdrs "modules/core/.*/cuda")
  18. ocv_list_filterout(opencv_hdrs "modules/core/.*/opencl")
  19. ocv_list_filterout(opencv_hdrs "modules/core/include/opencv2/core/opengl.hpp")
  20. ocv_list_filterout(opencv_hdrs "modules/core/include/opencv2/core/ocl.hpp")
  21. ocv_list_filterout(opencv_hdrs "modules/cuda.*")
  22. ocv_list_filterout(opencv_hdrs "modules/cudev")
  23. ocv_list_filterout(opencv_hdrs "modules/core/.*/hal/")
  24. ocv_list_filterout(opencv_hdrs "modules/.*/detection_based_tracker.hpp") # Conditional compilation
  25. ocv_list_filterout(opencv_hdrs "modules/core/include/opencv2/core/utils/*.private.*")
  26. ocv_list_filterout(opencv_hdrs "modules/core/include/opencv2/core/utils/instrumentation.hpp")
  27. ocv_list_filterout(opencv_hdrs "modules/core/include/opencv2/core/utils/trace*")
  28. ocv_update_file("${CMAKE_CURRENT_BINARY_DIR}/headers.txt" "${opencv_hdrs}")
  29. set(bindings_cpp "${OPENCV_JS_BINDINGS_DIR}/gen/bindings.cpp")
  30. set(scripts_hdr_parser "${JS_SOURCE_DIR}/../python/src2/hdr_parser.py")
  31. if(DEFINED ENV{OPENCV_JS_WHITELIST})
  32. set(OPENCV_JS_WHITELIST_FILE "$ENV{OPENCV_JS_WHITELIST}")
  33. else()
  34. set(OPENCV_JS_WHITELIST_FILE "${OpenCV_SOURCE_DIR}/platforms/js/opencv_js.config.py")
  35. endif()
  36. add_custom_command(
  37. OUTPUT ${bindings_cpp} "${OPENCV_DEPHELPER}/gen_opencv_js_source"
  38. COMMAND
  39. ${PYTHON_DEFAULT_EXECUTABLE}
  40. "${CMAKE_CURRENT_SOURCE_DIR}/embindgen.py"
  41. "${scripts_hdr_parser}"
  42. "${bindings_cpp}"
  43. "${CMAKE_CURRENT_BINARY_DIR}/headers.txt"
  44. "${JS_SOURCE_DIR}/src/core_bindings.cpp"
  45. "${OPENCV_JS_WHITELIST_FILE}"
  46. COMMAND
  47. ${CMAKE_COMMAND} -E touch "${OPENCV_DEPHELPER}/gen_opencv_js_source"
  48. WORKING_DIRECTORY
  49. "${CMAKE_CURRENT_BINARY_DIR}/gen"
  50. DEPENDS
  51. ${JS_SOURCE_DIR}/src/core_bindings.cpp
  52. ${CMAKE_CURRENT_SOURCE_DIR}/embindgen.py
  53. ${CMAKE_CURRENT_SOURCE_DIR}/templates.py
  54. "${OPENCV_JS_WHITELIST_FILE}"
  55. ${scripts_hdr_parser}
  56. #(not needed - generated by CMake) ${CMAKE_CURRENT_BINARY_DIR}/headers.txt
  57. ${opencv_hdrs}
  58. COMMENT "Generate source files for JavaScript bindings"
  59. )
  60. add_custom_target(gen_opencv_js_source
  61. # excluded from all: ALL
  62. DEPENDS ${bindings_cpp} "${OPENCV_DEPHELPER}/gen_opencv_js_source"
  63. SOURCES
  64. ${JS_SOURCE_DIR}/src/core_bindings.cpp
  65. ${CMAKE_CURRENT_SOURCE_DIR}/embindgen.py
  66. ${CMAKE_CURRENT_SOURCE_DIR}/templates.py
  67. )