js: use generated list of OpenCV headers
authorAlexander Alekhin <alexander.alekhin@intel.com>
Fri, 31 Aug 2018 11:48:44 +0000 (14:48 +0300)
committerAlexander Alekhin <alexander.alekhin@intel.com>
Fri, 31 Aug 2018 11:48:44 +0000 (14:48 +0300)
- replaces hand-written list

modules/js/CMakeLists.txt
modules/js/src/core_bindings.cpp
modules/js/src/embindgen.py

index 7db438b..6d713d4 100644 (file)
@@ -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})
 
index 18427d1..e8f0ee7 100644 (file)
 // 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 <emscripten/bind.h>
 
+@INCLUDES@
+
 using namespace emscripten;
 using namespace cv;
 using namespace dnn;
index a27fba2..2e9811a 100644 (file)
@@ -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))