diff options
Diffstat (limited to 'mkspecs/features/wasm')
-rw-r--r-- | mkspecs/features/wasm/qt.prf | 83 | ||||
-rw-r--r-- | mkspecs/features/wasm/wasm.prf | 97 |
2 files changed, 180 insertions, 0 deletions
diff --git a/mkspecs/features/wasm/qt.prf b/mkspecs/features/wasm/qt.prf new file mode 100644 index 0000000000..2f6e3f8c34 --- /dev/null +++ b/mkspecs/features/wasm/qt.prf @@ -0,0 +1,83 @@ + +qt_depends = $$resolve_depends(QT, "QT.") +!watchos:equals(TEMPLATE, app):contains(qt_depends, gui(-private)?) { + LIBS *= -L$$[QT_INSTALL_PLUGINS/get]/platforms + + lib_name = wasm + lib_path_and_base = $$[QT_INSTALL_PLUGINS/get]/platforms/lib$${lib_name}$$qtPlatformTargetSuffix() + LIBS += -l$${lib_name}$$qtPlatformTargetSuffix() $$fromfile($${lib_path_and_base}.prl, QMAKE_PRL_LIBS) + + +} + +load(qt) + +## taken from qt.prf +import_plugins { + manualplugs = $$QTPLUGIN # User may specify plugins. Mostly legacy. + autoplugs = # Auto-added plugins. + # First round: explicitly specified modules. + plugin_deps = $$all_qt_module_deps + for(ever) { + # Automatically link the default plugins for the linked Qt modules. + for (qtmod, plugin_deps) { + for (ptype, QT.$${qtmod}.plugin_types) { + nptype = $$replace(ptype, [-/], _) + isEmpty(QTPLUGIN.$$nptype) { + for (plug, QT_PLUGINS) { + equals(QT_PLUGIN.$${plug}.TYPE, $$ptype) { + for (dep, QT_PLUGIN.$${plug}.EXTENDS) { + !contains(all_qt_module_deps, $$dep) { + plug = + break() + } + } + autoplugs += $$plug + } + } + } else { + plug = $$eval(QTPLUGIN.$$nptype) + !equals(plug, -): \ + autoplugs += $$plug + } + } + } + QTPLUGIN = $$manualplugs $$autoplugs + QTPLUGIN = $$unique(QTPLUGIN) + + # Obtain the plugins' Qt dependencies ... + plugin_deps = + for (plug, QTPLUGIN): \ + plugin_deps += $$eval(QT_PLUGIN.$${plug}.DEPENDS) + plugin_deps = $$resolve_depends(plugin_deps, "QT.", ".depends" ".run_depends") + plugin_deps -= $$all_qt_module_deps + isEmpty(plugin_deps): \ + break() + # ... and start over if any new Qt modules appeared, + # as these may want to load plugins in turn. + all_qt_module_deps += $$plugin_deps + } + extraplugs = $$manualplugs + manualplugs -= $$autoplugs + extraplugs -= $$manualplugs + !isEmpty(extraplugs): \ + warning("Redundant entries in QTPLUGIN: $$extraplugs") + + !isEmpty(QTPLUGIN) { + IMPORT_FILE_CONT = \ + "// This file is autogenerated by qmake. It imports static plugin classes for" \ + "// static plugins specified using QTPLUGIN and QT_PLUGIN_CLASS.<plugin> variables." \ + "$${LITERAL_HASH}include <QtPlugin>" + for (plug, QTPLUGIN) { + plug_class = $$eval(QT_PLUGIN.$${plug}.CLASS_NAME) + !isEmpty(plug_class): \ + IMPORT_FILE_CONT += "Q_IMPORT_PLUGIN($$plug_class)" + else: \ + warning("Plugin class name could not be determined for plugin '$$plug'.") + } + IMPORT_CPP = $$OUT_PWD/$$lower($$basename(TARGET))_plugin_import.cpp + write_file($$IMPORT_CPP, IMPORT_FILE_CONT)|error() + GENERATED_SOURCES += $$IMPORT_CPP + QMAKE_DISTCLEAN += $$IMPORT_CPP + } +} diff --git a/mkspecs/features/wasm/wasm.prf b/mkspecs/features/wasm/wasm.prf new file mode 100644 index 0000000000..bea50f98f0 --- /dev/null +++ b/mkspecs/features/wasm/wasm.prf @@ -0,0 +1,97 @@ + +# DESTDIR will be emtpy if not set in the app .pro file; make sure it has a value +isEmpty(DESTDIR) : DESTDIR = $$OUT_PWD + +# Copies the given files to the destination directory +defineTest(copyToDestDir) { + files = $$1 + + for(FILE, files) { + # Replace slashes in paths with backslashes for Windows + win32:FILE ~= s,/,\\,g + win32:DDIR ~= s,/,\\,g + + QMAKE_POST_LINK += $$QMAKE_COPY $$quote($$FILE) $$quote($$DESTDIR) $$escape_expand(\\n\\t) + } + export(QMAKE_POST_LINK) +} + +# Create js and wasm files for applications +contains(TEMPLATE, .*app) { + TARGET_BASE = $${TARGET} + TARGET_HTML = $${TARGET}.html + TARGET_JS = $${TARGET}.js + + # Make the emscripten compiler generate a js file + TARGET = $$TARGET_JS + + QMAKE_INCDIR += $$(HOME)/.emscripten_ports/openssl/include + + CONFIG += static + js_file.files = TARGET_JS + js_file.path += $$target.path + isEmpty(js_file.path) + js_file.path += ./ + INSTALLS += js_file + + !contains(CONFIG,config_test):!build_pass:cross_compile: { + QMAKE_CFLAGS += -s WASM=1 -s \"BINARYEN_METHOD=\'native-wasm\'\" -s \"BINARYEN_TRAP_MODE=\'clamp\'\" + QMAKE_CXXFLAGS += -s WASM=1 -s \"BINARYEN_METHOD=\'native-wasm\'\" -s \"BINARYEN_TRAP_MODE=\'clamp\'\" + QMAKE_LFLAGS += -s WASM=1 -s \"BINARYEN_METHOD=\'native-wasm\'\" -s \"BINARYEN_TRAP_MODE=\'clamp\'\" + } + + # Copy hosting html and javascript to the application build directory. + exists($$[QT_INSTALL_PLUGINS]/platforms/wasm_shell.html) { + # dont pass this until it's installed somewhere + # otherwise makespec test fails during qt configure + WASM_PLUGIN_PATH = $$[QT_INSTALL_PLUGINS]/platforms + } else { + ## internal build. not installed + WASM_PLUGIN_PATH = $$PWD/../../../src/plugins/platforms/wasm + } + + # Copy/Generate main .html file (e.g. myapp.html) from the webassembly_shell.html by + # replacing the app name placeholder with the actual app name. + apphtml.target = $$DESTDIR/$$TARGET_HTML + apphtml.commands += sed -e s/APPNAME/$$TARGET_BASE/g $$quote($$WASM_PLUGIN_PATH/wasm_shell.html) > $$quote($$DESTDIR/$$TARGET_HTML) $$escape_expand(\\n\\t) + + # Copy qtloader.js + appjs.target = $$DESTDIR/qtloader.js + appjs.commands += $$QMAKE_COPY $$quote($$WASM_PLUGIN_PATH/qtloader.js) $$quote($$DESTDIR) $$escape_expand(\\n\\t) + + # Copy qtlogo.svg + qtlogo.target = $$DESTDIR/qtlogo.svg + qtlogo.commands += $$QMAKE_COPY $$quote($$WASM_PLUGIN_PATH/qtlogo.svg) $$quote($$DESTDIR) $$escape_expand(\\n\\t) + + QMAKE_EXTRA_TARGETS += apphtml appjs qtlogo + POST_TARGETDEPS += $$apphtml.target $$appjs.target $$qtlogo.target + + # Add manual target to make "make -B shellfiles" work. + shellfiles.target = shellfiles + shellfiles.depends = $$apphtml.target $$appjs.target $$qtlogo.target + QMAKE_EXTRA_TARGETS += shellfiles + + # emscripten ports are linked into the main module (this app), not the Qt + # libs which reference them + qt { + qt_depends = $$resolve_depends(QT, "QT.") + contains(qt_depends, core(-private)?): QMAKE_LFLAGS += \ + $$QMAKE_LIBS_THREAD $$QMAKE_LIBS_ZLIB + contains(qt_depends, gui(-private)?): QMAKE_LFLAGS += \ + $$QMAKE_LIBS_FREETYPE $$QMAKE_LIBS_LIBPNG + } +} + +# Creates the stand-alone version of the library from bitcode +!static:contains(TEMPLATE, .*lib): { + load(resolve_target) + QMAKE_POST_LINK += $$QMAKE_LINK_SHLIB $$QMAKE_RESOLVED_TARGET -o $${QMAKE_RESOLVED_TARGET}.js + + QMAKE_INCDIR += $$(HOME)/.emscripten_ports/openssl/include + + !build_pass:cross_compile: { + QMAKE_CFLAGS += -s WASM=1 -s \"BINARYEN_METHOD=\'native-wasm\'\" + QMAKE_LFLAGS += -s WASM=1 -s \"BINARYEN_METHOD=\'native-wasm\'\" + QMAKE_CXXFLAGS += -s WASM=1 -s \"BINARYEN_METHOD=\'native-wasm\'\" + } +} |