mirror of https://github.com/qt/qtbase.git
wasm: add support for building Qt as shared libraries
This implements the build system bits required to build Qt as as separate wasm modules a.k.a Emscripten side modules. Enable by configuring with the "-shared" flag. This is the first step towards shared library support and gets us as far as being able to load QtCore and instantiate a QCoreApplication. Task-number: QTBUG-63925 Change-Id: Ib8f07f80fb5b13c8dbba65c7db735dc557b70d0e Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
20242a2549
commit
be44827240
|
@ -35,6 +35,10 @@ function(qt_auto_detect_wasm)
|
|||
__qt_internal_query_emsdk_version("${EMROOT_PATH}" TRUE CMAKE_EMSDK_REGEX_VERSION)
|
||||
set(EMCC_VERSION "${CMAKE_EMSDK_REGEX_VERSION}" CACHE STRING INTERNAL FORCE)
|
||||
|
||||
if(NOT DEFINED BUILD_SHARED_LIBS)
|
||||
qt_internal_ensure_static_qt_config()
|
||||
endif()
|
||||
|
||||
# Find toolchain file
|
||||
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
|
||||
__qt_internal_get_emscripten_cmake_toolchain_file_path_from_emsdk_env(
|
||||
|
@ -49,8 +53,6 @@ function(qt_auto_detect_wasm)
|
|||
__qt_internal_show_error_no_emscripten_toolchain_file_found_when_building_qt()
|
||||
endif()
|
||||
|
||||
qt_internal_ensure_static_qt_config()
|
||||
|
||||
__qt_internal_get_emcc_recommended_version(recommended_version)
|
||||
set(QT_EMCC_RECOMMENDED_VERSION "${recommended_version}" CACHE STRING INTERNAL FORCE)
|
||||
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
# PRIVATE_CONTENT_FILE specifies the pre-cooked content of Qt_<version>_PRIVATE_API section.
|
||||
# Requires the content file available at build time.
|
||||
function(qt_internal_add_linker_version_script target)
|
||||
if(WASM)
|
||||
return()
|
||||
endif()
|
||||
|
||||
qt_parse_all_arguments(arg "qt_internal_add_linker_version_script"
|
||||
""
|
||||
"PRIVATE_CONTENT_FILE"
|
||||
|
@ -94,7 +98,7 @@ function(qt_internal_add_linker_version_script target)
|
|||
endfunction()
|
||||
|
||||
function(qt_internal_add_link_flags_no_undefined target)
|
||||
if (NOT QT_BUILD_SHARED_LIBS)
|
||||
if (NOT QT_BUILD_SHARED_LIBS OR WASM)
|
||||
return()
|
||||
endif()
|
||||
if ((GCC OR CLANG) AND NOT MSVC)
|
||||
|
|
|
@ -530,6 +530,8 @@ endif()\n\n")
|
|||
if(target_type STREQUAL "SHARED_LIBRARY")
|
||||
if(WIN32)
|
||||
set(write_implib TRUE)
|
||||
elseif(WASM)
|
||||
# Keep write_soname at FALSE
|
||||
else()
|
||||
set(write_soname TRUE)
|
||||
endif()
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
function (qt_internal_setup_wasm_target_properties wasmTarget)
|
||||
|
||||
target_link_options("${wasmTarget}" INTERFACE
|
||||
"SHELL:-s ERROR_ON_UNDEFINED_SYMBOLS=1"
|
||||
"SHELL:-s MAX_WEBGL_VERSION=2"
|
||||
"SHELL:-s FETCH=1"
|
||||
"SHELL:-s WASM_BIGINT=1")
|
||||
|
@ -82,6 +81,25 @@ function (qt_internal_setup_wasm_target_properties wasmTarget)
|
|||
# Set ASYNCIFY_IMPORTS unconditionally in order to support enabling asyncify at link time.
|
||||
target_link_options("${wasmTarget}" INTERFACE "SHELL:-sASYNCIFY_IMPORTS=qt_asyncify_suspend_js,qt_asyncify_resume_js")
|
||||
|
||||
if(QT_FEATURE_shared)
|
||||
|
||||
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
|
||||
|
||||
# plugins are SIDE_MODULE
|
||||
target_compile_options("${wasmTarget}" INTERFACE
|
||||
"$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY>:" -s SIDE_MODULE=1>)
|
||||
target_link_options("${wasmTarget}" INTERFACE
|
||||
"$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,MODULE_LIBRARY>:" -s SIDE_MODULE=1>)
|
||||
|
||||
# shared libs are SIDE_MODULE
|
||||
target_compile_options("${wasmTarget}" INTERFACE
|
||||
"$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:" -s SIDE_MODULE=1>)
|
||||
target_link_options("${wasmTarget}" INTERFACE
|
||||
"$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:" -s SIDE_MODULE=1>)
|
||||
|
||||
else()
|
||||
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s ERROR_ON_UNDEFINED_SYMBOLS=1")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(qt_internal_wasm_add_finalizers target)
|
||||
|
|
|
@ -390,7 +390,7 @@ qt_feature("android-style-assets" PRIVATE
|
|||
)
|
||||
qt_feature("shared" PUBLIC
|
||||
LABEL "Building shared libraries"
|
||||
AUTODETECT NOT UIKIT AND NOT WASM
|
||||
AUTODETECT NOT UIKIT
|
||||
CONDITION BUILD_SHARED_LIBS
|
||||
)
|
||||
qt_feature_definition("shared" "QT_STATIC" NEGATE PREREQUISITE "!defined(QT_SHARED) && !defined(QT_STATIC)")
|
||||
|
|
|
@ -65,6 +65,7 @@ if(ANDROID_PLATFORM)
|
|||
endif()
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@QT_CMAKE_EXPORT_NAMESPACE@WasmMacros.cmake")
|
||||
endif()
|
||||
|
||||
|
|
|
@ -851,7 +851,7 @@ qt_internal_extend_target(Gui CONDITION QT_FEATURE_opengles2
|
|||
opengl/qopengles2ext.h
|
||||
)
|
||||
|
||||
qt_internal_extend_target(Gui CONDITION QT_FEATURE_egl AND QT_FEATURE_opengl
|
||||
qt_internal_extend_target(Gui CONDITION QT_FEATURE_egl AND QT_FEATURE_opengl AND NOT WASM
|
||||
SOURCES
|
||||
opengl/platform/egl/qeglpbuffer.cpp opengl/platform/egl/qeglpbuffer_p.h
|
||||
opengl/platform/egl/qeglplatformcontext.cpp opengl/platform/egl/qeglplatformcontext_p.h
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <QtGui/qregion.h>
|
||||
#include <qpa/qplatformwindow.h>
|
||||
#include <QMap>
|
||||
|
||||
#include <QtOpenGL/qopengltextureblitter.h>
|
||||
#include <QtGui/qpalette.h>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "qwasmtheme.h"
|
||||
#include <QtCore/qvariant.h>
|
||||
#include <QFontDatabase>
|
||||
#include <QList>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
Loading…
Reference in New Issue