2022-07-05 11:26:52 +00:00
|
|
|
# Copyright (C) 2022 The Qt Company Ltd.
|
2022-08-19 13:21:34 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
2022-07-05 11:26:52 +00:00
|
|
|
|
2020-09-03 08:29:41 +00:00
|
|
|
|
2022-04-20 02:54:49 +00:00
|
|
|
# WARNING must keep in sync with wasm-emscripten/qmake.conf!
|
2020-09-03 08:29:41 +00:00
|
|
|
function (qt_internal_setup_wasm_target_properties wasmTarget)
|
|
|
|
|
2021-05-19 09:41:51 +00:00
|
|
|
target_link_options("${wasmTarget}" INTERFACE
|
2022-06-20 06:19:32 +00:00
|
|
|
"SHELL:-s MAX_WEBGL_VERSION=2"
|
2022-05-10 07:09:51 +00:00
|
|
|
"SHELL:-s FETCH=1"
|
2023-03-03 14:46:04 +00:00
|
|
|
"SHELL:-s WASM_BIGINT=1"
|
|
|
|
"SHELL:-s STACK_SIZE=5MB")
|
2021-05-21 09:14:34 +00:00
|
|
|
|
2022-05-29 20:56:32 +00:00
|
|
|
target_link_libraries("${wasmTarget}" INTERFACE embind)
|
|
|
|
|
2022-08-24 00:47:25 +00:00
|
|
|
## wasm64
|
|
|
|
if (WASM64)
|
|
|
|
target_compile_options("${wasmTarget}" INTERFACE "SHELL:-s MEMORY64=1" )
|
|
|
|
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s MEMORY64=1" -mwasm64)
|
|
|
|
endif()
|
2022-12-29 16:54:29 +00:00
|
|
|
# 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")
|
2021-05-21 09:14:34 +00:00
|
|
|
|
2021-04-16 05:34:57 +00:00
|
|
|
#simd
|
2022-10-07 10:00:22 +00:00
|
|
|
if (QT_FEATURE_wasm_simd128)
|
|
|
|
target_compile_options("${wasmTarget}" INTERFACE -msimd128)
|
|
|
|
endif()
|
2021-04-16 05:34:57 +00:00
|
|
|
if (QT_FEATURE_sse2)
|
|
|
|
target_compile_options("${wasmTarget}" INTERFACE -O2 -msimd128 -msse -msse2)
|
|
|
|
endif()
|
|
|
|
|
2022-10-18 12:02:02 +00:00
|
|
|
# wasm exceptions
|
2022-12-21 13:22:59 +00:00
|
|
|
if (QT_FEATURE_wasm_exceptions)
|
2022-10-18 12:02:02 +00:00
|
|
|
target_compile_options("${wasmTarget}" INTERFACE -fwasm-exceptions)
|
|
|
|
target_link_options("${wasmTarget}" INTERFACE -fwasm-exceptions)
|
2022-12-21 13:22:59 +00:00
|
|
|
else()
|
|
|
|
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s DISABLE_EXCEPTION_CATCHING=1")
|
2022-10-18 12:02:02 +00:00
|
|
|
endif()
|
|
|
|
|
2020-09-03 08:29:41 +00:00
|
|
|
if (QT_FEATURE_thread)
|
2022-01-12 21:21:07 +00:00
|
|
|
target_compile_options("${wasmTarget}" INTERFACE "SHELL:-pthread")
|
|
|
|
target_link_options("${wasmTarget}" INTERFACE "SHELL:-pthread")
|
2020-09-03 08:29:41 +00:00
|
|
|
endif()
|
|
|
|
|
2022-08-26 07:49:52 +00:00
|
|
|
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s ALLOW_MEMORY_GROWTH")
|
|
|
|
|
2020-09-03 08:29:41 +00:00
|
|
|
# debug add_compile_options
|
|
|
|
if ("QT_WASM_SOURCE_MAP=1" IN_LIST QT_QMAKE_DEVICE_OPTIONS)
|
|
|
|
set(WASM_SOURCE_MAP_BASE "http://localhost:8000/")
|
|
|
|
|
|
|
|
if(DEFINED QT_WASM_SOURCE_MAP_BASE)
|
|
|
|
set(WASM_SOURCE_MAP_BASE "${QT_WASM_SOURCE_MAP_BASE}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# 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
|
2021-11-18 00:29:46 +00:00
|
|
|
target_link_options("${wasmTarget}" INTERFACE "-gsource-map" "--source-map-base" "${WASM_SOURCE_MAP_BASE}")
|
2020-09-03 08:29:41 +00:00
|
|
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# a few good defaults to make console more verbose while debugging
|
|
|
|
target_link_options("${wasmTarget}" INTERFACE $<$<CONFIG:Debug>:
|
2021-05-25 07:52:38 +00:00
|
|
|
"SHELL:-s DEMANGLE_SUPPORT=1"
|
2020-09-03 08:29:41 +00:00
|
|
|
--profiling-funcs>)
|
|
|
|
|
|
|
|
# target_link_options("${wasmTarget}" INTERFACE "SHELL:-s LIBRARY_DEBUG=1") # print out library calls, verbose
|
|
|
|
# target_link_options("${wasmTarget}" INTERFACE "SHELL:-s SYSCALL_DEBUG=1") # print out sys calls, verbose
|
|
|
|
# target_link_options("${wasmTarget}" INTERFACE "SHELL:-s FS_LOG=1") # print out filesystem ops, verbose
|
|
|
|
# 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
|
|
|
|
# are omitted. Enable optimizations also for debug builds.
|
|
|
|
set(QT_CFLAGS_OPTIMIZE_DEBUG "-Os" CACHE STRING INTERNAL FORCE)
|
|
|
|
set(QT_FEATURE_optimize_debug ON CACHE BOOL INTERNAL FORCE)
|
|
|
|
|
2022-08-08 22:05:33 +00:00
|
|
|
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s ASYNCIFY" "-Os")
|
2020-09-03 08:29:41 +00:00
|
|
|
target_compile_definitions("${wasmTarget}" INTERFACE QT_HAVE_EMSCRIPTEN_ASYNCIFY)
|
|
|
|
endif()
|
2022-08-08 22:05:33 +00:00
|
|
|
|
|
|
|
# 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")
|
|
|
|
|
2022-08-19 12:25:49 +00:00
|
|
|
if(QT_FEATURE_shared)
|
|
|
|
|
|
|
|
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
|
|
|
|
|
2022-12-22 14:03:25 +00:00
|
|
|
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}"
|
|
|
|
)
|
|
|
|
|
2023-05-10 09:08:48 +00:00
|
|
|
# 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}/>)
|
|
|
|
|
2022-12-22 14:03:25 +00:00
|
|
|
target_compile_options("${wasmTarget}" INTERFACE "${set_shared_module_type_if_needed}")
|
|
|
|
target_link_options("${wasmTarget}" INTERFACE "${set_shared_module_type_if_needed}")
|
2022-08-19 12:25:49 +00:00
|
|
|
|
|
|
|
else()
|
|
|
|
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s ERROR_ON_UNDEFINED_SYMBOLS=1")
|
|
|
|
endif()
|
2022-08-26 08:06:36 +00:00
|
|
|
|
|
|
|
# Suppress warnings for known issues for developer builds
|
|
|
|
if(FEATURE_developer_build)
|
|
|
|
target_link_options("${wasmTarget}" INTERFACE "SHELL:-Wno-pthreads-mem-growth")
|
|
|
|
endif()
|
|
|
|
|
2020-09-03 08:29:41 +00:00
|
|
|
endfunction()
|
2022-07-14 00:07:00 +00:00
|
|
|
|
|
|
|
function(qt_internal_wasm_add_finalizers target)
|
2022-12-29 16:54:29 +00:00
|
|
|
qt_add_list_file_finalizer(_qt_internal_set_wasm_export_name ${target})
|
2022-07-14 00:07:00 +00:00
|
|
|
qt_add_list_file_finalizer(_qt_internal_add_wasm_extra_exported_methods ${target})
|
2022-09-01 15:29:44 +00:00
|
|
|
qt_add_list_file_finalizer(_qt_internal_wasm_add_target_helpers ${target})
|
2022-07-14 00:07:00 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|