From d52cef1719eedfb06dcd91868666d7f5841fd972 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 31 Aug 2018 14:48:44 +0300 Subject: [PATCH] js: use generated list of OpenCV headers - replaces hand-written list --- modules/js/CMakeLists.txt | 2 +- modules/js/src/core_bindings.cpp | 9 ++------- modules/js/src/embindgen.py | 5 +++++ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/js/CMakeLists.txt b/modules/js/CMakeLists.txt index 7db438b8a9..6d713d4bd9 100644 --- a/modules/js/CMakeLists.txt +++ b/modules/js/CMakeLists.txt @@ -56,7 +56,7 @@ add_custom_command( DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/embindgen.py DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/templates.py DEPENDS ${scripts_hdr_parser} - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/headers.txt + #(not needed - generated by CMake) DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/headers.txt DEPENDS ${opencv_hdrs} DEPENDS ${JS_HELPER}) diff --git a/modules/js/src/core_bindings.cpp b/modules/js/src/core_bindings.cpp index 18427d18fe..e8f0ee7f85 100644 --- a/modules/js/src/core_bindings.cpp +++ b/modules/js/src/core_bindings.cpp @@ -68,15 +68,10 @@ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //M*/ -#include "opencv2/core.hpp" -#include "opencv2/imgproc.hpp" -#include "opencv2/video/tracking.hpp" -#include "opencv2/video/background_segm.hpp" -#include "opencv2/objdetect.hpp" -#include "opencv2/dnn.hpp" - #include +@INCLUDES@ + using namespace emscripten; using namespace cv; using namespace dnn; diff --git a/modules/js/src/embindgen.py b/modules/js/src/embindgen.py index a27fba2f21..2e9811ada2 100644 --- a/modules/js/src/embindgen.py +++ b/modules/js/src/embindgen.py @@ -733,12 +733,14 @@ class JSWrapperGenerator(object): def gen(self, dst_file, src_files, core_bindings): # step 1: scan the headers and extract classes, enums and functions + headers = [] for hdr in src_files: decls = self.parser.parse(hdr) # print(hdr); # self.print_decls(decls); if len(decls) == 0: continue + headers.append(hdr[hdr.rindex('opencv2/'):]) for decl in decls: name = decl[0] type = name[:name.find(" ")] @@ -890,6 +892,9 @@ class JSWrapperGenerator(object): with open(core_bindings) as f: ret = f.read() + header_includes = '\n'.join(['#include "{}"'.format(hdr) for hdr in headers]) + ret = ret.replace('@INCLUDES@', header_includes) + defis = '\n'.join(self.wrapper_funcs) ret += wrapper_codes_template.substitute(ns=wrapper_namespace, defs=defis) ret += emscripten_binding_template.substitute(binding_name='testBinding', bindings=''.join(self.bindings))