diff options
Diffstat (limited to 'src/corelib/Qt6WasmMacros.cmake')
-rw-r--r-- | src/corelib/Qt6WasmMacros.cmake | 114 |
1 files changed, 87 insertions, 27 deletions
diff --git a/src/corelib/Qt6WasmMacros.cmake b/src/corelib/Qt6WasmMacros.cmake index 99de3aac37..1de6e5448c 100644 --- a/src/corelib/Qt6WasmMacros.cmake +++ b/src/corelib/Qt6WasmMacros.cmake @@ -1,25 +1,74 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +# SPDX-License-Identifier: BSD-3-Clause # Copy in Qt HTML/JS launch files for apps. function(_qt_internal_wasm_add_target_helpers target) + + _qt_test_emscripten_version() get_target_property(targetType "${target}" TYPE) if("${targetType}" STREQUAL "EXECUTABLE") - set(APPNAME ${target}) - if(QT6_INSTALL_PREFIX) set(WASM_BUILD_DIR "${QT6_INSTALL_PREFIX}") elseif(QT_BUILD_DIR) set(WASM_BUILD_DIR "${QT_BUILD_DIR}") endif() - configure_file("${WASM_BUILD_DIR}/plugins/platforms/wasm_shell.html" - "${target}.html") - configure_file("${WASM_BUILD_DIR}/plugins/platforms/qtloader.js" - qtloader.js COPYONLY) - configure_file("${WASM_BUILD_DIR}/plugins/platforms/qtlogo.svg" - qtlogo.svg COPYONLY) + get_target_property(output_name ${target} OUTPUT_NAME) + if(output_name) + set(_target_output_name "${output_name}") + else() + set(_target_output_name "${target}") + endif() + + set(APPNAME ${_target_output_name}) + _qt_internal_wasm_export_name_for_target(_export_name ${target}) + set(APPEXPORTNAME ${_export_name}) + + # Shared library builds preload plugins and qml imports by default. + # The json files are generated by scripts in qtbase/util/wasm/preload + if (QT_FEATURE_shared) + set(PRELOAD "preload: ['qt_plugins.json', 'qt_qml_imports.json'],") + else() + set(PRELOAD "") + endif() + + get_target_property(target_output_directory ${target} RUNTIME_OUTPUT_DIRECTORY) + + get_target_property(is_test ${target} _qt_is_test_executable) + get_target_property(is_manual_test ${target} _qt_is_manual_test) + if(is_test AND NOT is_manual_test) + # Keep in sync with testrunner_files in testlib/CMakeLists.txt + configure_file("${WASM_BUILD_DIR}/libexec/batchedtestrunner.html" + "${target_output_directory}/${_target_output_name}.html" COPYONLY) + configure_file("${WASM_BUILD_DIR}/libexec/qtestoutputreporter.css" + "${target_output_directory}/qtestoutputreporter.css" COPYONLY) + configure_file("${WASM_BUILD_DIR}/libexec/batchedtestrunner.js" + "${target_output_directory}/batchedtestrunner.js" COPYONLY) + configure_file("${WASM_BUILD_DIR}/libexec/emrunadapter.js" + "${target_output_directory}/emrunadapter.js" COPYONLY) + configure_file("${WASM_BUILD_DIR}/libexec/qwasmjsruntime.js" + "${target_output_directory}/qwasmjsruntime.js" COPYONLY) + configure_file("${WASM_BUILD_DIR}/libexec/qwasmtestmain.js" + "${target_output_directory}/qwasmtestmain.js" COPYONLY) + configure_file("${WASM_BUILD_DIR}/libexec/qtestoutputreporter.js" + "${target_output_directory}/qtestoutputreporter.js" COPYONLY) + configure_file("${WASM_BUILD_DIR}/libexec/util.js" + "${target_output_directory}/util.js" COPYONLY) + else() + if(target_output_directory) + set(_target_directory "${target_output_directory}") + else() + set(_target_directory "${CMAKE_CURRENT_BINARY_DIR}") + endif() + + configure_file("${WASM_BUILD_DIR}/plugins/platforms/wasm_shell.html" + "${_target_directory}/${_target_output_name}.html" @ONLY) + configure_file("${WASM_BUILD_DIR}/plugins/platforms/qtloader.js" + ${_target_directory}/qtloader.js COPYONLY) + configure_file("${WASM_BUILD_DIR}/plugins/platforms/qtlogo.svg" + ${_target_directory}/qtlogo.svg COPYONLY) + endif() if(QT_FEATURE_thread) set(POOL_SIZE 4) @@ -33,29 +82,23 @@ function(_qt_internal_wasm_add_target_helpers target) message(DEBUG "Setting PTHREAD_POOL_SIZE to ${POOL_SIZE} for ${target}") endif() - # Hardcode wasm memory size. + # Set initial memory size, either from user setting or to a minimum amount required by Qt. get_target_property(_tmp_initialMemory "${target}" QT_WASM_INITIAL_MEMORY) if(_tmp_initialMemory) set(QT_WASM_INITIAL_MEMORY "${_tmp_initialMemory}") elseif(NOT DEFINED QT_WASM_INITIAL_MEMORY) - if(QT_FEATURE_thread) - # Pthreads and ALLOW_MEMORY_GROWTH can cause javascript wasm memory access to - # be slow and having to update HEAP* views. Instead, we specify the memory size - # at build time. Further, browsers limit the maximum initial memory size to 1GB. - # https://github.com/WebAssembly/design/issues/1271 - set(QT_WASM_INITIAL_MEMORY "1GB") - else() - # emscripten default is 16MB, we need slightly more sometimes - set(QT_WASM_INITIAL_MEMORY "50MB") - endif() + set(QT_WASM_INITIAL_MEMORY "50MB") endif() + target_link_options("${target}" PRIVATE "SHELL:-s INITIAL_MEMORY=${QT_WASM_INITIAL_MEMORY}") - if(DEFINED QT_WASM_INITIAL_MEMORY) - # QT_WASM_INITIAL_MEMORY must be a multiple of 65536 - target_link_options("${target}" - PRIVATE "SHELL:-s INITIAL_MEMORY=${QT_WASM_INITIAL_MEMORY}") - message(DEBUG "-- Setting INITIAL_MEMORY to ${QT_WASM_INITIAL_MEMORY} for ${target}") + # Set maximum memory size, either from user setting or to 4GB (the 32-bit maximum) + get_target_property(_tmp_maximumMemory "${target}" QT_WASM_MAXIMUM_MEMORY) + if(_tmp_maximumMemory) + set(QT_WASM_MAXIMUM_MEMORY "${_tmp_maximumMemory}") + elseif(NOT DEFINED QT_WASM_MAXIMUM_MEMORY) + set(QT_WASM_MAXIMUM_MEMORY "4GB") endif() + target_link_options("${target}" PRIVATE "SHELL:-s MAXIMUM_MEMORY=${QT_WASM_MAXIMUM_MEMORY}") endif() endfunction() @@ -63,18 +106,35 @@ endfunction() function(_qt_internal_add_wasm_extra_exported_methods target) get_target_property(wasm_extra_exported_methods "${target}" QT_WASM_EXTRA_EXPORTED_METHODS) + set(wasm_default_exported_methods "UTF16ToString,stringToUTF16,JSEvents,specialHTMLTargets,FS,callMain") + if(NOT wasm_extra_exported_methods) set(wasm_extra_exported_methods ${QT_WASM_EXTRA_EXPORTED_METHODS}) endif() if(wasm_extra_exported_methods) target_link_options("${target}" PRIVATE - "SHELL:-s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16,${wasm_extra_exported_methods}" + "SHELL:-s EXPORTED_RUNTIME_METHODS=${wasm_default_exported_methods},${wasm_extra_exported_methods}" ) else() # an errant dangling comma will break this target_link_options("${target}" PRIVATE - "SHELL:-s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16" + "SHELL:-s EXPORTED_RUNTIME_METHODS=${wasm_default_exported_methods}" ) endif() endfunction() + +function(_qt_internal_set_wasm_export_name target) + _qt_internal_wasm_export_name_for_target(export_name ${target}) + target_link_options("${target}" PRIVATE "SHELL:-s EXPORT_NAME=${export_name}") +endfunction() + +function(_qt_internal_wasm_export_name_for_target out target) + get_target_property(export_name "${target}" QT_WASM_EXPORT_NAME) + if(export_name) + set(${out} "${export_name}" PARENT_SCOPE) + else() + string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" target "${target}") + set(${out} "${target}_entry" PARENT_SCOPE) + endif() +endfunction() |