From 03e8a2bb9b78b90aed848dbd2f0a3d0643b0cdef Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Wed, 29 Apr 2026 16:21:39 +0200
Subject: [PATCH] cmake: map embedded resource paths to local paths on
emscripten
---
test/CMakeLists.txt | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 8cb9b476..3751c504 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -36,7 +36,8 @@ set(RESOURCE_FILES
)
function(add_sdl_image_test_executable TARGET)
- add_executable(${TARGET} ${ARGN})
+ cmake_parse_arguments(ARGS "RESOURCES" "" "SOURCES" ${ARGN})
+ add_executable(${TARGET} ${ARGS_SOURCES})
if (EMSCRIPTEN)
set_property(TARGET ${TARGET} PROPERTY SUFFIX ".html")
@@ -68,8 +69,18 @@ function(add_sdl_image_test_executable TARGET)
)
endif()
endif()
-
- add_dependencies(${TARGET} copy-sdl_image-test-resources)
+ if(ARGS_RESOURCES)
+ if(EMSCRIPTEN)
+ foreach(res_file_name IN LISTS RESOURCE_FILES)
+ target_link_options(${TARGET} PRIVATE "SHELL:--embed-file \"${CMAKE_CURRENT_SOURCE_DIR}/${res_file_name}@${res_file_name}\"")
+ endforeach()
+ else()
+ add_dependencies(${TARGET} copy-sdl_image-test-resources)
+ endif()
+ endif()
+ if(EMSCRIPTEN)
+ target_link_options(${TARGET} PRIVATE -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=1gb)
+ endif()
endfunction()
function(add_sdl_image_test NAME)
@@ -125,23 +136,13 @@ foreach(res_file_name IN LISTS RESOURCE_FILES)
endforeach()
add_custom_target(copy-sdl_image-test-resources DEPENDS "${RESOURCE_FILES_BIN_ABS}")
-function(link_embed_resources TARGET)
- foreach(res_file_name IN LISTS RESOURCE_FILES)
- target_link_options(${TARGET} PRIVATE "SHELL:--embed-file \"${res_file_name}\"")
- endforeach()
-endfunction()
-
-add_sdl_image_test_executable(testimage testimage.c)
-add_sdl_image_test_executable(testanimation testanimation.c)
+add_sdl_image_test_executable(testimage SOURCES testimage.c RESOURCES)
+add_sdl_image_test_executable(testanimation SOURCES testanimation.c RESOURCES)
add_sdl_image_test(testimage COMMAND testimage)
add_sdl_image_test(testanimation_dummy_metadata COMMAND testanimation)
add_sdl_image_test(testanimation COMMAND testanimation --no-dummy-metadata)
-if(EMSCRIPTEN)
- link_embed_resources(testimage)
- link_embed_resources(testanimation)
-endif()
if(SDLIMAGE_TESTS_INSTALL)
if(NOT EMSCRIPTEN)