mirror of
https://github.com/opencv/opencv.git
synced 2024-12-15 09:49:13 +08:00
6c6d5cd7b2
Split Javascript white-list to support contrib modules #25986 Single whitelist converted to several per-module json files. They are concatenated automatically and can be overriden by user config. Related to https://github.com/opencv/opencv/pull/25656 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
91 lines
3.8 KiB
CMake
91 lines
3.8 KiB
CMake
set(MODULE_NAME "js_bindings_generator")
|
|
set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE)
|
|
ocv_add_module(${MODULE_NAME} INTERNAL)
|
|
|
|
set(OPENCV_JS_BINDINGS_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "")
|
|
file(REMOVE_RECURSE "${OPENCV_JS_BINDINGS_DIR}/gen")
|
|
file(MAKE_DIRECTORY "${OPENCV_JS_BINDINGS_DIR}/gen")
|
|
file(REMOVE "${OPENCV_DEPHELPER}/gen_opencv_js_source") # force re-run after CMake
|
|
|
|
# This file is included from a subdirectory
|
|
set(JS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
|
include(${JS_SOURCE_DIR}/common.cmake) # fill OPENCV_JS_MODULES
|
|
|
|
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")
|
|
ocv_list_filterout(opencv_hdrs "modules/core/.*/opencl")
|
|
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
|
|
ocv_list_filterout(opencv_hdrs "modules/core/include/opencv2/core/utils/*.private.*")
|
|
ocv_list_filterout(opencv_hdrs "modules/core/include/opencv2/core/utils/instrumentation.hpp")
|
|
ocv_list_filterout(opencv_hdrs "modules/core/include/opencv2/core/utils/trace*")
|
|
|
|
ocv_update_file("${CMAKE_CURRENT_BINARY_DIR}/headers.txt" "${opencv_hdrs}")
|
|
|
|
set(bindings_cpp "${OPENCV_JS_BINDINGS_DIR}/gen/bindings.cpp")
|
|
|
|
set(scripts_hdr_parser "${JS_SOURCE_DIR}/../python/src2/hdr_parser.py")
|
|
|
|
if(DEFINED ENV{OPENCV_JS_WHITELIST})
|
|
set(OPENCV_JS_WHITELIST_FILE "$ENV{OPENCV_JS_WHITELIST}")
|
|
message(STATUS "Use white list from environment ${OPENCV_JS_WHITELIST_FILE}")
|
|
else()
|
|
#generate white list from modules/<module_name>/misc/js/whitelist.json
|
|
set(OPENCV_JS_WHITELIST_FILE "${CMAKE_CURRENT_BINARY_DIR}/whitelist.json")
|
|
foreach(m in ${OPENCV_JS_MODULES})
|
|
set(js_whitelist "${OPENCV_MODULE_${m}_LOCATION}/misc/js/gen_dict.json")
|
|
if (EXISTS "${js_whitelist}")
|
|
file(READ "${js_whitelist}" whitelist_content)
|
|
list(APPEND OPENCV_JS_WHITELIST_CONTENT "\"${m}\": ${whitelist_content}")
|
|
endif()
|
|
endforeach(m)
|
|
string(REPLACE ";" ", \n" OPENCV_JS_WHITELIST_CONTENT_STRING "${OPENCV_JS_WHITELIST_CONTENT}")
|
|
set(OPENCV_JS_WHITELIST_CONTENT_STRING "{\n${OPENCV_JS_WHITELIST_CONTENT_STRING}}\n")
|
|
ocv_update_file("${OPENCV_JS_WHITELIST_FILE}" "${OPENCV_JS_WHITELIST_CONTENT_STRING}")
|
|
message(STATUS "Use autogenerated whitelist ${OPENCV_JS_WHITELIST_FILE}")
|
|
endif()
|
|
|
|
add_custom_command(
|
|
OUTPUT ${bindings_cpp} "${OPENCV_DEPHELPER}/gen_opencv_js_source"
|
|
COMMAND
|
|
${PYTHON_DEFAULT_EXECUTABLE}
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/embindgen.py"
|
|
"${scripts_hdr_parser}"
|
|
"${bindings_cpp}"
|
|
"${CMAKE_CURRENT_BINARY_DIR}/headers.txt"
|
|
"${JS_SOURCE_DIR}/src/core_bindings.cpp"
|
|
"${OPENCV_JS_WHITELIST_FILE}"
|
|
COMMAND
|
|
${CMAKE_COMMAND} -E touch "${OPENCV_DEPHELPER}/gen_opencv_js_source"
|
|
WORKING_DIRECTORY
|
|
"${CMAKE_CURRENT_BINARY_DIR}/gen"
|
|
DEPENDS
|
|
${JS_SOURCE_DIR}/src/core_bindings.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/embindgen.py
|
|
${CMAKE_CURRENT_SOURCE_DIR}/templates.py
|
|
"${OPENCV_JS_WHITELIST_FILE}"
|
|
${scripts_hdr_parser}
|
|
#(not needed - generated by CMake) ${CMAKE_CURRENT_BINARY_DIR}/headers.txt
|
|
${opencv_hdrs}
|
|
COMMENT "Generate source files for JavaScript bindings"
|
|
)
|
|
|
|
add_custom_target(gen_opencv_js_source
|
|
# excluded from all: ALL
|
|
DEPENDS ${bindings_cpp} "${OPENCV_DEPHELPER}/gen_opencv_js_source"
|
|
SOURCES
|
|
${JS_SOURCE_DIR}/src/core_bindings.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/embindgen.py
|
|
${CMAKE_CURRENT_SOURCE_DIR}/templates.py
|
|
)
|