summaryrefslogtreecommitdiffstats
path: root/cmake/QtWasmHelpers.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/QtWasmHelpers.cmake')
-rw-r--r--cmake/QtWasmHelpers.cmake128
1 files changed, 75 insertions, 53 deletions
diff --git a/cmake/QtWasmHelpers.cmake b/cmake/QtWasmHelpers.cmake
index 240eaa0540..41ef5cb0ba 100644
--- a/cmake/QtWasmHelpers.cmake
+++ b/cmake/QtWasmHelpers.cmake
@@ -1,68 +1,48 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+# WARNING must keep in sync with wasm-emscripten/qmake.conf!
function (qt_internal_setup_wasm_target_properties wasmTarget)
target_link_options("${wasmTarget}" INTERFACE
- "SHELL:-s ERROR_ON_UNDEFINED_SYMBOLS=1"
- "SHELL:-s EXTRA_EXPORTED_RUNTIME_METHODS=[UTF16ToString,stringToUTF16]"
- "SHELL:-s USE_WEBGL2=1"
- "--bind"
- "SHELL:-s FETCH=1")
-
- # Enable MODULARIZE and set EXPORT_NAME, which makes it possible to
- # create application instances using a global constructor function,
- # e.g. let app_instance = await createQtAppInstance().
- # (as opposed to MODULARIZE=0, where Emscripten creates a global app
- # instance object at Javascript eval time)
- target_link_options("${wasmTarget}" INTERFACE
- "SHELL:-s MODULARIZE=1"
- "SHELL:-s EXPORT_NAME=createQtAppInstance")
+ "SHELL:-s MAX_WEBGL_VERSION=2"
+ "SHELL:-s FETCH=1"
+ "SHELL:-s WASM_BIGINT=1"
+ "SHELL:-s STACK_SIZE=5MB")
- target_compile_options("${wasmTarget}" INTERFACE --bind)
+ target_link_libraries("${wasmTarget}" INTERFACE embind)
- # Hardcode wasm memory size. Emscripten does not currently support memory growth
- # (ALLOW_MEMORY_GROWTH) in pthreads mode, and requires specifying the memory size
- # at build time. Further, browsers limit the maximum initial memory size to 1GB.
- # QT_WASM_INITIAL_MEMORY must be a multiple of 64KB (i.e. 65536)
- if(NOT DEFINED QT_WASM_INITIAL_MEMORY AND QT_FEATURE_thread)
- set(QT_WASM_INITIAL_MEMORY "1GB")
+ ## wasm64
+ if (WASM64)
+ target_compile_options("${wasmTarget}" INTERFACE "SHELL:-s MEMORY64=1" )
+ target_link_options("${wasmTarget}" INTERFACE "SHELL:-s MEMORY64=1" -mwasm64)
endif()
+ # Enable MODULARIZE so that we are able to set EXPORT_NAME later and instantiate on demand (with
+ # MODULARIZE=0, emscripten creates a global app instance object at Javascript eval time)
+ target_link_options("${wasmTarget}" INTERFACE "SHELL:-s MODULARIZE=1")
- if(DEFINED QT_WASM_INITIAL_MEMORY)
- target_link_options("${wasmTarget}" INTERFACE "SHELL:-s INITIAL_MEMORY=${QT_WASM_INITIAL_MEMORY}")
- message("Setting INITIAL_MEMORY to ${QT_WASM_INITIAL_MEMORY}")
+ #simd
+ if (QT_FEATURE_wasm_simd128)
+ target_compile_options("${wasmTarget}" INTERFACE -msimd128)
endif()
-
- if (QT_FEATURE_opengles3)
- target_link_options("${wasmTarget}" INTERFACE "SHELL:-s FULL_ES3=1")
-
- target_link_options("${wasmTarget}" INTERFACE "SHELL:-s FULL_ES3=1"
- "SHELL:-s MAX_WEBGL_VERSION=2"
- "SHELL:-s WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION=1")
- else()
- target_link_options("${wasmTarget}" INTERFACE "SHELL:-s FULL_ES2=1")
+ if (QT_FEATURE_sse2)
+ target_compile_options("${wasmTarget}" INTERFACE -O2 -msimd128 -msse -msse2)
endif()
- set(disable_exceptions_catching 1)
- if (QT_FEATURE_exceptions)
- set(disable_exceptions_catching 0)
+ # wasm exceptions
+ if (QT_FEATURE_wasm_exceptions)
+ target_compile_options("${wasmTarget}" INTERFACE -fwasm-exceptions)
+ target_link_options("${wasmTarget}" INTERFACE -fwasm-exceptions)
endif()
- target_link_options("${wasmTarget}" INTERFACE "SHELL:-s DISABLE_EXCEPTION_CATCHING=${disable_exceptions_catching}")
if (QT_FEATURE_thread)
- target_compile_options("${wasmTarget}" INTERFACE "SHELL:-s USE_PTHREADS=1")
- target_link_options("${wasmTarget}" INTERFACE "SHELL:-s USE_PTHREADS=1")
-
- set(POOL_SIZE 4)
- if(DEFINED QT_WASM_PTHREAD_POOL_SIZE)
- set(POOL_SIZE ${QT_WASM_PTHREAD_POOL_SIZE})
- endif()
- target_link_options("${wasmTarget}" INTERFACE "SHELL:-s PTHREAD_POOL_SIZE=${POOL_SIZE}")
- message("Setting PTHREAD_POOL_SIZE to ${POOL_SIZE}")
-
- else()
- target_link_options("${wasmTarget}" INTERFACE "SHELL:-s ALLOW_MEMORY_GROWTH=1")
+ target_compile_options("${wasmTarget}" INTERFACE "SHELL:-pthread")
+ target_link_options("${wasmTarget}" INTERFACE "SHELL:-pthread")
endif()
+ target_link_options("${wasmTarget}" INTERFACE "SHELL:-s ALLOW_MEMORY_GROWTH")
+
# debug add_compile_options
if ("QT_WASM_SOURCE_MAP=1" IN_LIST QT_QMAKE_DEVICE_OPTIONS)
set(WASM_SOURCE_MAP_BASE "http://localhost:8000/")
@@ -74,15 +54,13 @@ function (qt_internal_setup_wasm_target_properties wasmTarget)
# Pass --source-map-base on the linker line. This informs the
# browser where to find the source files when debugging.
# -g4 to make source maps for debugging
- target_link_options("${wasmTarget}" INTERFACE "-g4" "--source-map-base" "${WASM_SOURCE_MAP_BASE}")
+ target_link_options("${wasmTarget}" INTERFACE "-gsource-map" "--source-map-base" "${WASM_SOURCE_MAP_BASE}")
endif()
# a few good defaults to make console more verbose while debugging
target_link_options("${wasmTarget}" INTERFACE $<$<CONFIG:Debug>:
"SHELL:-s DEMANGLE_SUPPORT=1"
- "SHELL:-s GL_DEBUG=1"
- "SHELL:-s ASSERTIONS=2"
--profiling-funcs>)
# target_link_options("${wasmTarget}" INTERFACE "SHELL:-s LIBRARY_DEBUG=1") # print out library calls, verbose
@@ -91,7 +69,6 @@ function (qt_internal_setup_wasm_target_properties wasmTarget)
# target_link_options("${wasmTarget}" INTERFACE "SHELL:-s SOCKET_DEBUG") # print out socket,network data transfer
if ("QT_EMSCRIPTEN_ASYNCIFY=1" IN_LIST QT_QMAKE_DEVICE_OPTIONS)
-
# Emscripten recommends building with optimizations when using asyncify
# in order to reduce wasm file size, and may also generate broken wasm
# (with "wasm validation error: too many locals" type errors) if optimizations
@@ -102,4 +79,49 @@ function (qt_internal_setup_wasm_target_properties wasmTarget)
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s ASYNCIFY" "-Os")
target_compile_definitions("${wasmTarget}" INTERFACE QT_HAVE_EMSCRIPTEN_ASYNCIFY)
endif()
+
+ # 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)
+
+ set(side_modules
+ MODULE_LIBRARY SHARED_LIBRARY)
+ set(enable_side_module_if_needed
+ "$<$<IN_LIST:$<TARGET_PROPERTY:TYPE>,${side_modules}>:SHELL:-s SIDE_MODULE=1>")
+ set(enable_main_module_if_needed
+ "$<$<IN_LIST:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:SHELL:-s MAIN_MODULE=1>")
+ set(set_shared_module_type_if_needed
+ "${enable_side_module_if_needed}"
+ "${enable_main_module_if_needed}"
+ )
+
+ # Add Qt libdir to linker library paths
+ set(qt_lib_location
+ "${QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX}/${INSTALL_LIBDIR}")
+ target_link_options("${wasmTarget}" INTERFACE
+ "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:SHELL:" -L${qt_lib_location}/>)
+
+ target_compile_options("${wasmTarget}" INTERFACE "${set_shared_module_type_if_needed}")
+ target_link_options("${wasmTarget}" INTERFACE "${set_shared_module_type_if_needed}")
+
+ else()
+ target_link_options("${wasmTarget}" INTERFACE "SHELL:-s ERROR_ON_UNDEFINED_SYMBOLS=1")
+ endif()
+
+ # Suppress warnings for known issues for developer builds
+ if(FEATURE_developer_build)
+ target_link_options("${wasmTarget}" INTERFACE "SHELL:-Wno-pthreads-mem-growth")
+ endif()
+
+endfunction()
+
+function(qt_internal_wasm_add_finalizers target)
+ qt_add_list_file_finalizer(_qt_internal_set_wasm_export_name ${target})
+ qt_add_list_file_finalizer(_qt_internal_add_wasm_extra_exported_methods ${target})
+ qt_add_list_file_finalizer(_qt_internal_wasm_add_target_helpers ${target})
endfunction()
+
+