Unsolved CMake project builds target WebAssembly?
-
official tutorial is about qmake, so is it possiable to build target WebAssembly with CMake? If Yes, howto?
-
No it's not possible yet.
-
Hi @sierdzio, do you have any information on if it's planned and if there is a confirmed date on the functionality to build WebAssembly with CMake?
-
No I don't have that information. Search the blog posts (I think it was mentioned in comments there), or ask on one of Qt's mailing lists.
I'm pretty sure cmake support will be added at some point, because Qt is moving to cmake as the main build platform. But when/ how I don't know.
-
Still under development:
29. August 2019 ... - Some investigation into WebAssembly support (qtbase is built without tests / and examples on local machine, not everything upstreamed yet) ...
-
Actually, it is possible, at least from the commandline. In the early stages of qt webassembly development, cmake was used to compile a clients target application. I have not tested it for any months.
Emscripten comes with a cmake toolchain file:
CMAKE_TOOLCHAIN_FILE=/path/to/emsdk/emscripten/1.38.27/cmake/Modules/Platform/Emscripten.cmake
From memory I had to edit that file a bit, you need to make sure to use a static build.
I tried this and I added (to the tool chain file):
set(Qt5_DIR "~/Qt/5.13.0/wasm_32/lib/cmake/Qt5")
set(Qt5Widgets_DIR "~/Qt/5.13.0/wasm_32/lib/cmake/Qt5Widgets")
set(Qt5Gui_DIR "~/Qt/5.13.0/wasm_32/lib/cmake/Qt5Gui")
set(Qt5Core_DIR "~/Qt/5.13.0/wasm_32/lib/cmake/Qt5Core")cmake -DCMAKE_TOOLCHAIN_FILE=$HOME/emsdk/emscripten/1.38.27/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles" ~/path/to/CMakeLists.txt
Probably a better way of doing this, but this seemed to work.
I have started a bug report:
https://bugreports.qt.io/browse/QTBUG-78647 -
@lorn-potter I've tried this and the suggestion in the https://bugreports.qt.io/browse/QTBUG-78647 with Qt5.13 and 5.14 but no luck. I also had to compile Qt with system-zlib(compiled zlib with emscripten first), with qt-zlib Qt's cmake config files can't find zlib. There is no static lib with qt-zlib, only the Qt5Zlib.la and libQt5Zlib.prl in the lib directory of Qt installation.
I also had to add this in every Qt's module cmake config file which is requesting the zlib library, the "elseif" after threads it's around line 60:
if (_lib_is_default_linked) unset(_lib_is_default_linked) elseif(_lib MATCHES "^pthread$") find_package(Threads REQUIRED) list(APPEND _lib_deps Threads::Threads) elseif(_lib MATCHES "z") list(APPEND _lib_deps "/home/alex/extsrc/emscripten_ports/lib/libz.a")
By the end I have compiled a test project with cmake but it's not running in any browser. Just stuck at Downloading/Compiling in the browser. Also noticed the generated project.js file is much smaller(qmake~2.6MB, cmake~700kB) than cimpiled the same project with qmake and same Qt installation(Kit).
-
Successfully build a sample Cmake project from here https://bugreports.qt.io/browse/QTBUG-79547 with Qt-5.13.1