opencv/modules/js/generator/CMakeLists.txt

91 lines
3.8 KiB
CMake
Raw Normal View History

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
)