From 59b48ebda6dc3286b10fad9de9ff134dc7877e35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Kov=C3=A1cs?= Date: Mon, 21 Oct 2024 13:11:37 +0200 Subject: [PATCH] Finalize cmake build (also for wasm) --- CMakeLists.txt | 17 ++++++++++++++--- XaoS.pro | 4 ++-- tools/postprocess-web | 13 +++++++------ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e999937c..483d0df4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,7 +170,7 @@ file(GLOB CXX_FILES src/ui/*.cpp src/ui-hlp/*.cpp src/util/*.cpp src/engine/*.cp file(GLOB C_FILES src/sffe/*.c) if(EMSCRIPTEN) - qt_add_executable(XaoS + qt_add_executable(xaos ${CXX_FILES} ${C_FILES} ${QM_FILES} @@ -178,8 +178,8 @@ if(EMSCRIPTEN) src/ui/XaoS.qrc XaoS.qrc ) - target_link_libraries(XaoS PUBLIC Qt6::Widgets) - target_link_options(XaoS PUBLIC -sASYNCIFY -O3 -flto) + target_link_libraries(xaos PUBLIC Qt6::Widgets) + target_link_options(xaos PUBLIC -sASYNCIFY -O3 -flto) else() add_executable(XaoS MACOSX_BUNDLE ${CXX_FILES} @@ -199,6 +199,16 @@ if(OPENGL) target_link_libraries(XaoS Qt6::OpenGL Qt6::OpenGLWidgets) endif(OPENGL) +if (EMSCRIPTEN) + target_link_options(xaos PUBLIC "SHELL: + --preload-file '${CMAKE_SOURCE_DIR}/catalogs@/catalogs' + --preload-file '${CMAKE_SOURCE_DIR}/examples@/examples' + --preload-file '${CMAKE_SOURCE_DIR}/tutorial@/tutorial'") + add_custom_command(TARGET xaos POST_BUILD + COMMAND "${CMAKE_SOURCE_DIR}/tools/postprocess-web" "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" + COMMENT "Running postprocess-web..." + ) +else() # install bundle install(TARGETS XaoS DESTINATION bin) @@ -208,3 +218,4 @@ install(DIRECTORY catalogs tutorial DESTINATION .) # install example files file(GLOB EXAMPLE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/examples/*/*.xpf) install(FILES ${EXAMPLE_FILES} DESTINATION examples) +endif(EMSCRIPTEN) diff --git a/XaoS.pro b/XaoS.pro index e0ad1ce5..d13d0a82 100644 --- a/XaoS.pro +++ b/XaoS.pro @@ -87,8 +87,8 @@ wasm{ QMAKE_LFLAGS += --preload-file $$PWD/examples@$$DATAPATH/examples QMAKE_LFLAGS += --preload-file $$PWD/catalogs@$$DATAPATH/catalogs QMAKE_LFLAGS += --preload-file $$PWD/tutorial@$$DATAPATH/tutorial - QMAKE_LFLAGS += -sASYNCIFY -Os # This can help avoiding to get the web application hang when the user presses "s". - QMAKE_POST_LINK = $$PWD/tools/postprocess-web $$PWD/bin + QMAKE_LFLAGS += -sASYNCIFY -Os # -sASYNCIFY can help avoiding to get the web application hang when the user presses "s". + QMAKE_POST_LINK = $$PWD/tools/postprocess-web $$PWD $$PWD/bin } executable.files = bin/xaos executable.path = $$PREFIX/bin diff --git a/tools/postprocess-web b/tools/postprocess-web index 4b5983f8..b6c397e7 100755 --- a/tools/postprocess-web +++ b/tools/postprocess-web @@ -5,13 +5,13 @@ set -e -if [ "$1" = "" ]; then - echo "Usage: $0 [bin-folder]" +if [ $# != 2 ]; then + echo "Usage: $0 [source-folder] [build-folder]" exit 1 fi -test "$1/xaos.js" || { - echo "The file $1/xaos.js is missing." +test "$2/xaos.js" || { + echo "The file $2/xaos.js is missing." exit 2 } @@ -21,7 +21,8 @@ sed -i 's/Module\["print"\]/\ let statustext = "STATUS: ";\ if (t.startsWith(statustext)) document.title = t.substring(statustext.length);\ }\ -/' "$1/xaos.js" +/' "$2/xaos.js" # For a workaround on macOS, see https://stackoverflow.com/questions/12696125/sed-edit-file-in-place -cp "$1/../src/ui/images/qtlogo.svg" "$1" +cp "$1/src/ui/images/qtlogo.svg" "$2" +exit 0