Skip to content

Commit

Permalink
feat: ugly hack in pre-js file to enable multi thread on browser
Browse files Browse the repository at this point in the history
  • Loading branch information
tolstenko committed Dec 13, 2022
1 parent 1590cf1 commit ceb6f1c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ add_library(${PROJECT_NAME} ${headers} ${sources})
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)

if(EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Oz -s WASM=2 -pthread -s USE_PTHREADS=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Oz -s WASM=2 -pthread -s USE_PTHREADS=1 --extern-pre-js ${CMAKE_CURRENT_SOURCE_DIR}/cmake/pre.js")
endif()

# being a cross-platform target, we enforce standards conformance on MSVC
Expand Down
3 changes: 3 additions & 0 deletions cmake/pre.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// todo: move this to a better place
// ugly hack for crossOriginIsolated not enabled and SharedArrayBuffer not available
if(typeof(window)=='object' && (typeof(crossOriginIsolated)=='undefined'||!crossOriginIsolated))SharedArrayBuffer = ArrayBuffer;
2 changes: 1 addition & 1 deletion standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(EMSCRIPTEN)
# todo: add pre js to have this if (!crossOriginIsolated) SharedArrayBuffer = ArrayBuffer;
set(CMAKE_EXECUTABLE_SUFFIX ".html") # todo: we should not need this!
message(STATUS "EMSCRIPTEN BUILD")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Oz -s WASM=2 -pthread -s USE_PTHREADS=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Oz -s WASM=2 -pthread -s USE_PTHREADS=1 --extern-pre-js ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/pre.js")
endif()

message(STATUS "CMAKE_EXECUTABLE_SUFFIX: ${CMAKE_EXECUTABLE_SUFFIX}")
Expand Down

0 comments on commit ceb6f1c

Please sign in to comment.