diff options
Diffstat (limited to 'src/corelib/Qt6WasmMacros.cmake')
-rw-r--r-- | src/corelib/Qt6WasmMacros.cmake | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/src/corelib/Qt6WasmMacros.cmake b/src/corelib/Qt6WasmMacros.cmake index 5cb8b73a8e..b590d89396 100644 --- a/src/corelib/Qt6WasmMacros.cmake +++ b/src/corelib/Qt6WasmMacros.cmake @@ -22,6 +22,16 @@ function(_qt_internal_wasm_add_target_helpers 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) @@ -53,7 +63,7 @@ function(_qt_internal_wasm_add_target_helpers target) endif() configure_file("${WASM_BUILD_DIR}/plugins/platforms/wasm_shell.html" - "${_target_directory}/${_target_output_name}.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" @@ -81,13 +91,22 @@ function(_qt_internal_wasm_add_target_helpers target) endif() target_link_options("${target}" PRIVATE "SHELL:-s INITIAL_MEMORY=${QT_WASM_INITIAL_MEMORY}") + # 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() 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") + 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}) @@ -104,3 +123,44 @@ function(_qt_internal_add_wasm_extra_exported_methods target) ) 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 MODULARIZE=1") + 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() + # Modify target name to remove characters which are not valid in + # JavaScript identifiers. + + # Prefix leading digit with '_' (2dpaint -> _2dpaint) + if("${target}" MATCHES "^[0-9]") + set(targ "_${target}") + else() + set(targ "${target}") + endif() + + # Replace remaining non-legal chars with '_' (target-foo -> target_foo) + string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" targ "${targ}") + + # Append "_entry" and return + set(${out} "${targ}_entry" PARENT_SCOPE) + endif() +endfunction() + +function(_qt_internal_set_wasm_embind_option target) + target_link_libraries("${target}" PRIVATE embind) +endfunction() + +function(_qt_internal_finalize_wasm_app target) + _qt_internal_set_wasm_export_name("${target}") + _qt_internal_add_wasm_extra_exported_methods("${target}") + _qt_internal_wasm_add_target_helpers("${target}") + _qt_internal_set_wasm_embind_option("${target}") +endfunction() + |