Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. CMake project builds target WebAssembly?
Forum Updated to NodeBB v4.3 + New Features

CMake project builds target WebAssembly?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 3.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • tracymaT Offline
    tracymaT Offline
    tracyma
    wrote on last edited by
    #1

    official tutorial is about qmake, so is it possiable to build target WebAssembly with CMake? If Yes, howto?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      No it's not possible yet.

      (Z(:^

      1 Reply Last reply
      0
      • marweM Offline
        marweM Offline
        marwe
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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.

          (Z(:^

          1 Reply Last reply
          0
          • tracymaT Offline
            tracymaT Offline
            tracyma
            wrote on last edited by
            #5

            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)
              ...
            
            1 Reply Last reply
            1
            • lorn.potterL Offline
              lorn.potterL Offline
              lorn.potter
              wrote on last edited by lorn.potter
              #6

              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

              Freelance Software Engineer, Platform Maintainer QtWebAssembly, Maintainer QtSensors
              Author, Hands-On Mobile and Embedded Development with Qt 5 http://bit.ly/HandsOnMobileEmbedded

              1 Reply Last reply
              0
              • A Offline
                A Offline
                arpio
                wrote on last edited by
                #7

                @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).

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  arpio
                  wrote on last edited by
                  #8

                  Successfully build a sample Cmake project from here https://bugreports.qt.io/browse/QTBUG-79547 with Qt-5.13.1

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved