Skip to content

Commit

Permalink
Finalize cmake build (also for wasm)
Browse files Browse the repository at this point in the history
  • Loading branch information
kovzol committed Oct 21, 2024
1 parent 6ee7c03 commit 59b48eb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,16 @@ 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}
${XaoS_ICON}
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}
Expand All @@ -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)

Expand All @@ -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)
4 changes: 2 additions & 2 deletions XaoS.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions tools/postprocess-web
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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

0 comments on commit 59b48eb

Please sign in to comment.