Thank you @jaswantp.
I modified CmakeLists and the compilation script, like above:
cmake_minimum_required(VERSION 3.13)
project(Cone)
# -----------------------------------------------------------------------------
# EMSCRIPTEN only
# -----------------------------------------------------------------------------
if (NOT EMSCRIPTEN)
message("Skipping example: This needs to run inside an Emscripten build environment")
return ()
endif ()
# -----------------------------------------------------------------------------
# Handle VTK dependency
# -----------------------------------------------------------------------------
find_package(Threads REQUIRED)
find_package(VTK
COMPONENTS
FiltersSources # VTK pipeline
InteractionStyle # Mouse handling
RenderingOpenGL2 # For Rendering
RenderingUI # For SDL2 Window
)
if (NOT VTK_FOUND)
message("Skipping example: ${VTK_NOT_FOUND_MESSAGE}")
return ()
endif ()
# -----------------------------------------------------------------------------
# Compile example code
# -----------------------------------------------------------------------------
add_executable(Cone Cone.cxx)
target_link_libraries(Cone
PRIVATE
VTK::FiltersSources
VTK::InteractionStyle
VTK::RenderingOpenGL2
VTK::RenderingUI
)
# -----------------------------------------------------------------------------
# WebAssembly build options
# -----------------------------------------------------------------------------
set(emscripten_link_options)
set(emscripten_compile_options)
list(APPEND emscripten_link_options
"SHELL:-s WASM=1"
)
set(emscripten_debug_options)
set(DEBUGINFO "PROFILE" CACHE STRING "Type of debug info")
set_property(CACHE DEBUGINFO PROPERTY
STRINGS
NONE # -g0
READABLE_JS # -g1
PROFILE # -g2
DEBUG_NATIVE # -g3
)
if(DEBUGINFO STREQUAL "NONE")
list(APPEND emscripten_debug_options
"-g0"
)
elseif(DEBUGINFO STREQUAL "READABLE_JS")
list(APPEND emscripten_debug_options
"-g1"
)
list(APPEND emscripten_link_options
"SHELL:-s DEMANGLE_SUPPORT=1"
)
elseif(DEBUGINFO STREQUAL "PROFILE")
list(APPEND emscripten_debug_options
"-g2"
)
list(APPEND emscripten_link_options
"SHELL:-s DEMANGLE_SUPPORT=1"
)
elseif(DEBUGINFO STREQUAL "DEBUG_NATIVE")
list(APPEND emscripten_debug_options
"-g3"
)
list(APPEND emscripten_link_options
"SHELL:-s ASSERTIONS=1"
"SHELL:-s DEMANGLE_SUPPORT=1"
)
endif()
# -----------------------------------------------------------------------------
# Build options
# -----------------------------------------------------------------------------
set(emscripten_optimizations)
set(OPTIMIZE "SMALLEST_WITH_CLOSURE" CACHE STRING "Emscripten optimization")
set_property(CACHE OPTIMIZE PROPERTY
STRINGS
NO_OPTIMIZATION # -O0
LITTLE # -O1
MORE # -O2
BEST # -O3
SMALL # -Os
SMALLEST # -Oz
SMALLEST_WITH_CLOSURE # -Oz --closure 1
)
if(OPTIMIZE STREQUAL "NO_OPTIMIZATION")
list(APPEND emscripten_optimizations
"-O0"
)
elseif(OPTIMIZE STREQUAL "LITTLE")
list(APPEND emscripten_optimizations
"-O1"
)
elseif(OPTIMIZE STREQUAL "MORE")
list(APPEND emscripten_optimizations
"-O2"
)
elseif(OPTIMIZE STREQUAL "BEST")
list(APPEND emscripten_optimizations
"-O3"
)
elseif(OPTIMIZE STREQUAL "SMALL")
list(APPEND emscripten_optimizations
"-Os"
)
elseif(OPTIMIZE STREQUAL "SMALLEST")
list(APPEND emscripten_optimizations
"-Oz"
)
elseif(OPTIMIZE STREQUAL "SMALLEST_WITH_CLOSURE")
list(APPEND emscripten_optimizations
"-Oz"
)
list(APPEND emscripten_link_options
"--closure 1"
)
endif()
target_compile_options(Cone
PUBLIC
${emscripten_compile_options}
${emscripten_optimizations}
${emscripten_debug_options}
)
target_link_options(Cone
PUBLIC
${emscripten_link_options}
${emscripten_optimizations}
${emscripten_debug_options}
)
### ---------- according vtk-wasm-sdk/.gitlab/ci/docker/tests/basic/CMakeLists.txt -------
target_compile_options(Cone PRIVATE "-sMEMORY64" "-Wno-experimental")
target_link_options(Cone PRIVATE "-sMEMORY64" "-Wno-experimental" "-sMAXIMUM_MEMORY=16GB")
target_compile_options(Cone PRIVATE "-pthread")
target_link_options(Cone PRIVATE "-pthread")
### -------------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# VTK modules initialization
# -----------------------------------------------------------------------------
vtk_module_autoinit(
TARGETS Cone
MODULES ${VTK_LIBRARIES}
)
# -----------------------------------------------------------------------------
# Copy HTML to build directory
# -----------------------------------------------------------------------------
add_custom_command(
TARGET Cone
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/index.html"
$<TARGET_FILE_DIR:Cone>
)
$erroractionpreference = "stop"
$sdk_version="wasm64-threads-v9.3.1-3657-gfd3dc37e8e-20240728"
$sdk_image="kitware/vtk-wasm-sdk"
$sdk_config="Release"
$sdk_dir="/VTK-install/$sdk_config/lib/cmake/vtk"
docker run `
--rm `
-v"$pwd/Cone":/Cone `
${sdk_image}:${sdk_version} `
emcmake cmake -GNinja -S /Cone -B /Cone/build -DCMAKE_BUILD_TYPE="$sdk_config" `
-DVTK_DIR="$sdk_dir" `
# ------------------ add as the table -----------------------------
-DCMAKE_C_FLAGS="-sMEMORY64=1 -pthread" `
-DCMAKE_CXX_FLAGS="-sMEMORY64=1 -pthread" `
-DCMAKE_EXE_LINKER_FLAGS="-sMEMORY64=1 -pthread" `
-DCMAKE_STATIC_LINKER_FLAGS="-sMEMORY64=1 -pthread"
docker run `
--rm `
-v"$pwd/Cone":/Cone `
${sdk_image}:${sdk_version} `
cmake --build /Cone/build
then compilation is completed.
But, when I tried to run the example, show nothing and output error in console:
Cone.js:313 Uncaught ReferenceError: SharedArrayBuffer is not defined
at Cone.js:313:40
:8080/favicon.ico:1
Failed to load resource: the server responded with a status of 404 (File not found)
What’s the issue? Have any suggestions?