How to compile a cmakelists based QT project for web-assembly?
-
I have a project that uses C++ and QT (QtWidgets, QtCore, QtGui only). The project comes with CMakelists.txt for each folder in the project. How do I compile this project for wasm? I have compiled qt6.6 for wasm that provides a qt-cmake (and qmake also)
Do I need to
-
convert CMakeLists.txt to .pro files and then use => qmake=>make
-
OR
-
can I use qt-cmake(from qt for wasm build) with the cmakelists.txt using =>qt-cmake . => make
I tried to compile the example gui_webgltest using the second method. It compiled but it failed to provide a wasm or html file.
I had added find_package(Qt6 REQUIRED COMPONENTS Widgets OpenGLWidgets) to the existing cmakelists.txt
cmake_minimum_required(VERSION 3.16) project(openglwindow LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL Widgets OpenGLWidgets) qt_standard_project_setup() qt_add_executable(openglwindow main.cpp trianglerenderer.cpp trianglerenderer.h ) target_link_libraries(openglwindow PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets Qt6::OpenGL Qt6::OpenGLWidgets )
-
-
For windows, visual studio build with Qt 6.6.2 installed in C:\Qt
Note the two different ways of running cmake
- vcvars64 (for msvc build)
- git clone https://github.com/msorvig/qt-webassembly-examples.git
- cd qt-webassembly-examples\gui_webgltest
- C:\Qt\6.6.2\wasm_singlethread\bin\qt-cmake .
(creates openglwindow.html) - cmake --build .
(creates .js, .wasm) - start emrun openglwindow.html