Skip to content

Commit fd0df5a

Browse files
committed
Merge pull request opencv#12469 from cv3d:fix/js/python3_msvc
2 parents 40b1dc1 + b487e2d commit fd0df5a

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

modules/js/CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,14 @@ link_libraries(${OPENCV_MODULE_${the_module}_DEPS})
6666

6767
ocv_add_executable(${the_module} ${bindings_cpp})
6868

69-
set_target_properties(${the_module} PROPERTIES COMPILE_FLAGS "-Wno-missing-prototypes")
70-
71-
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "--memory-init-file 0 -s TOTAL_MEMORY=134217728 -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s EXPORT_NAME=\"'cv'\" -s DEMANGLE_SUPPORT=1 -s FORCE_FILESYSTEM=1 --use-preload-plugins --bind --post-js ${JS_HELPER} -Wno-missing-prototypes")
69+
set(COMPILE_FLAGS "")
70+
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
71+
set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-missing-prototypes")
72+
endif()
73+
if(COMPILE_FLAGS)
74+
set_target_properties(${the_module} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS})
75+
endif()
76+
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "--memory-init-file 0 -s TOTAL_MEMORY=134217728 -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 -s EXPORT_NAME=\"'cv'\" -s DEMANGLE_SUPPORT=1 -s FORCE_FILESYSTEM=1 --use-preload-plugins --bind --post-js ${JS_HELPER} ${COMPILE_FLAGS}")
7277

7378
# add UMD wrapper
7479
set(MODULE_JS_PATH "${OpenCV_BINARY_DIR}/bin/${the_module}.js")

modules/js/src/embindgen.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
from __future__ import print_function
7171
import sys, re, os
7272
from templates import *
73-
from sets import Set
7473

7574
if sys.version_info[0] >= 3:
7675
from io import StringIO
@@ -185,7 +184,7 @@ def __init__(self, name, decl=None):
185184
self.consts = {}
186185
customname = False
187186
self.jsfuncs = {}
188-
self.constructor_arg_num = Set()
187+
self.constructor_arg_num = set()
189188

190189
self.has_smart_ptr = False
191190

@@ -369,21 +368,36 @@ def split_decl_name(self, name):
369368
return namespace, classes, chunks[-1]
370369

371370
def add_enum(self, decl):
372-
name = decl[1]
371+
name = decl[0].rsplit(" ", 1)[1]
373372
namespace, classes, val = self.split_decl_name(name)
374373
namespace = '.'.join(namespace)
374+
ns = self.namespaces.setdefault(namespace, Namespace())
375+
if len(name) == 0: name = "<unnamed>"
376+
if name.endswith("<unnamed>"):
377+
i = 0
378+
while True:
379+
i += 1
380+
candidate_name = name.replace("<unnamed>", "unnamed_%u" % i)
381+
if candidate_name not in ns.enums:
382+
name = candidate_name
383+
break;
375384
val = '_'.join(classes + [name])
376385
cname = name.replace('.', '::')
377-
ns = self.namespaces.setdefault(namespace, Namespace())
378386
if name in ns.enums:
379-
print("Generator warning: constant %s (cname=%s) already exists" \
387+
print("Generator warning: enum %s (cname=%s) already exists" \
380388
% (name, cname))
381389
# sys.exit(-1)
382390
else:
383391
ns.enums[name] = []
384392
for item in decl[3]:
385393
ns.enums[name].append(item)
386394

395+
const_decls = decl[3]
396+
397+
for decl in const_decls:
398+
name = decl[0]
399+
self.add_const(name.replace("const ", "").strip(), decl)
400+
387401
def add_const(self, name, decl):
388402
cname = name.replace('.','::')
389403
namespace, classes, name = self.split_decl_name(name)
@@ -803,7 +817,7 @@ def gen(self, dst_file, src_files, core_bindings):
803817
continue
804818

805819
# Generate bindings for methods
806-
for method_name, method in class_info.methods.iteritems():
820+
for method_name, method in class_info.methods.items():
807821
if method.cname in ignore_list:
808822
continue
809823
if not method.name in white_list[method.class_name]:
@@ -833,7 +847,7 @@ def gen(self, dst_file, src_files, core_bindings):
833847
class_bindings.append(smart_ptr_reg_template.substitute(cname=class_info.cname, name=class_info.name))
834848

835849
# Attach external constructors
836-
# for method_name, method in class_info.ext_constructors.iteritems():
850+
# for method_name, method in class_info.ext_constructors.items():
837851
# print("ext constructor", method_name)
838852
#if class_info.ext_constructors:
839853

0 commit comments

Comments
 (0)