2

I am trying to build a Qt6 GUI project for WebAssembly using Emscripten.

I managed to build the project successfully with nlohmann_json and spdlog. Now I also want to add the cpr library to use an HTTP client but since then the whole project no longer builds.

I use:

  • Qt 6.8.3 (wasm_singlethread)
  • Emscripten SDK (latest, emcc/em++)
  • CMake 3.31 (via CLion 2025.1.3)
  • Using Qt’s qt.toolchain.cmake and chaining Conan’s toolchain for dependencies (spdlog, cpr, nlohmann_json, …)

My CMakeLists.txt adds dummy GLESv2/EGL targets for WebAssembly:

cmake_minimum_required(VERSION 3.21)
project(qt3d_wasm_project VERSION 0.1 LANGUAGES CXX)
message(STATUS "CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}")
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
    if(NOT TARGET emscripten_flags)
        add_library(emscripten_flags INTERFACE)
        target_link_options(emscripten_flags INTERFACE
                "SHELL:-sUSE_ZLIB=1"
                # "SHELL:-sFETCH=1"
        )
    endif()

    if(NOT TARGET GLESv2::GLESv2)
        add_library(GLESv2::GLESv2 INTERFACE IMPORTED GLOBAL)
        target_link_options(GLESv2::GLESv2 INTERFACE "SHELL:-sUSE_WEBGL2=1")
    endif()
    if(NOT TARGET EGL::EGL)
        add_library(EGL::EGL INTERFACE IMPORTED GLOBAL)
        target_link_options(EGL::EGL INTERFACE "SHELL:-sUSE_WEBGL2=1")
    endif()
endif()

add_subdirectory(libraries/material_data_lib)

if(ENABLE_GUI)
    find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Quick3D Qml Quick3DHelpers Network)

    qt_add_executable(appqt3d
            resources.qrc
            main.cpp
            libraries/material_data_lib/include/IMaterialDataFetcher.h
            libraries/material_data_lib/src/MaterialDataFactory.cpp
    )

    if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
        target_link_libraries(appqt3d PRIVATE emscripten_flags  GLESv2::GLESv2 EGL::EGL)
    endif()

    target_link_libraries(appqt3d PRIVATE
            Qt6::Core Qt6::Gui Qt6::Quick Qt6::Quick3D Qt6::Quick3DHelpers Qt6::Network
    )
endif()

I use the following CMake Options:

-DCMAKE_TOOLCHAIN_FILE=/home/emmynoether/Qt/6.8.3/wasm_singlethread/lib/cmake/Qt6/qt.toolchain.cmake
-DQT_CHAINLOAD_TOOLCHAIN_FILE=/home/emmynoether/Dokumente/Webseite/MaterialStack/build_wasm/build/Release/generators/conan_toolchain.cmake
-DENABLE_GUI=ON
-DBUILD_TESTING=OFF
-DQt6_DIR=/home/emmynoether/Qt/6.8.3/wasm_singlethread/lib/cmake/Qt6
-DQT_HOST_PATH=/home/emmynoether/Qt/6.8.3/gcc_64
-DQT_DEBUG_FIND_PACKAGE=ON

The output is always:


-- Could NOT find EGL (missing: HAVE_EGL) (found version "1.5")
-- Could NOT find GLESv2 (missing: GLESv2_INCLUDE_DIR GLESv2_LIBRARY HAVE_GLESv2 HAVE_GLESv2) 
CMake Warning at /home/emmynoether/Qt/6.8.3/wasm_singlethread/lib/cmake/Qt6/Qt6Config.cmake:196 (find_package):
  Found package configuration file:

    /home/emmynoether/Qt/6.8.3/wasm_singlethread/lib/cmake/Qt6Gui/Qt6GuiConfig.cmake

  but it set Qt6Gui_FOUND to FALSE so package "Qt6Gui" is considered to be
  NOT FOUND.  Reason given by package:

  Qt6Gui could not be found because dependency GLESv2 could not be found.

  Configuring with --debug-find-pkg=GLESv2 might reveal details why the
  package was not found.

Why does Qt6GuiConfig.cmake for WebAssembly still insist on real GLESv2/EGL libraries, even though WebAssembly uses WebGL via Emscripten?

1 Answer 1

0

I had to run:

#prepare the emscription environment  
source ~/emsdk/emsdk_env.sh
#then i had to build the required GL ports:
embuilder build libGL
#embuilder:INFO: building libGL
#embuilder:INFO: ...success. Took (0.00s)

I learnt that embuilder compiles the WebGL/EGL stubs into static archives located in
$EMSDK/upstream/emscripten/system/lib. Without them the CMake find_package(Qt6Gui) call fails, because the Qt 6 Gui module depends on the OpenGL ES 2 symbols.

then i could go to my build folder and perform the conan install to resolve 3-party dependencies and configure the project with cmake .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.