Skip to content

Commit b145409

Browse files
committed
cmake: add emscripten specific flags
1 parent 6567a67 commit b145409

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,30 @@ target_sources(infinisim PUBLIC
216216
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
217217
# Special case for SDL2 dependency, goal is to find a config that exports SDL2::SDL2 target
218218
# libsdl2-dev has a `sdl2-config.cmake` that doesn't export this, but vcpkg does..
219+
if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
220+
# emcmake cmake -S . -B _build_em
221+
set(USE_FLAGS "-s USE_PTHREADS=1 -pthread")
222+
set(USE_FLAGS "${USE_FLAGS} -s USE_SDL=2")
223+
set(USE_FLAGS "${USE_FLAGS} -fwasm-exceptions")
224+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${USE_FLAGS}")
225+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${USE_FLAGS}")
226+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${USE_FLAGS}")
227+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s PTHREAD_POOL_SIZE=4 -s PROXY_TO_PTHREAD=1")
228+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s INITIAL_MEMORY=30736384") # 30MB memory
229+
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1")
230+
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ABORTING_MALLOC=0")
231+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXPORTED_RUNTIME_METHODS=[\"printErr\"]")
232+
set(CMAKE_EXECUTABLE_SUFFIX .html)
233+
target_include_directories(infinisim PRIVATE ${SDL2_INCLUDE_DIRS})
234+
target_link_libraries(infinisim PRIVATE ${SDL2_LIBRARIES})
235+
#set_target_properties(infinisim PROPERTIES LINK_FLAGS "--shell-file ${PROJECT_SOURCE_DIR}/lvgl_shell.html")
236+
else()
219237
find_package(SDL2 CONFIG QUIET)
220238
if(NOT TARGET SDL2::SDL2)
221239
find_package(SDL2 MODULE REQUIRED)
222240
endif()
223241
target_link_libraries(infinisim PRIVATE SDL2::SDL2)
242+
endif()
224243

225244
# Get the latest abbreviated commit hash of the working branch
226245
execute_process(

0 commit comments

Comments
 (0)