[build][cmake] Added emscripten build options#5180
Conversation
|
@brccabral Thanks for the review and clarifications! |
|
Are you sure this is a good idea? -sASYNCIFY is not needed if you use emscripten_set_main_loop and apparently makes perf worse. |
|
IMO this should be reverted. |
|
@Peter0x44 thanks for the review and the comments! As per mi understanding, this CMake is intended only for raylib examples collection, that requires And yeah, |
|
If I'm reading this correctly, it will make sure any time you link with raylib through cmake, |
|
If the intention is that it only passes this to the examples, then IMO, it should be the examples CMakeLists.txt providing the link options, not raylib. |
|
Well, the option |
|
-sUSE_GLFW=3 is fine because it is required 100% of the time. The other two flags are not, and ASYNCIFY has negative consequences! It's unacceptable to require those flags for everyone consuming raylib through cmake. core_basic_window_web.c demonstrates how to use emscripten_set_main_loop. |
|
This line is in examples/CMakeLists.txt set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s WASM=1 -s ASYNCIFY -s ALLOW_MEMORY_GROWTH=1 --shell-file ${CMAKE_SOURCE_DIR}/src/shell.html") |
|
Where is |
|
Ray deleted it in this commit. |
|
Found something, the browser error was caused by bool WindowShouldClose(void)
{
// Emscripten Asyncify is required to run synchronous code in asynchronous JS
// REF: https://emscripten.org/docs/porting/asyncify.html
// WindowShouldClose() is not called on a web-ready raylib application if using emscripten_set_main_loop()
// and encapsulating one frame execution on a UpdateDrawFrame() function,
// allowing the browser to manage execution asynchronously
// Optionally we can manage the time we give-control-back-to-browser if required,
// but it seems below line could generate stuttering on some browsers
emscripten_sleep(12);
return false;
} |
|
This file contains a PLATFORM_WEB example projects/CMake/core_basic_window.c, but its projects/CMake/CMakeLists.txt uses |
Yeah, I'm reorganizing examples at the moment and I just deleted it temporally to place it somewhere else. It was just a few days ago, sorry for the confusion. @brccabral When building for web, it's recommended to use the When using |
* [cmake] export automatically raylib definitions and compile/link options * [cmake] pass emscripten options to consumer project
Missing options for compiling as Web.