From e2c8f233ef4c0fd4cfdb3959d12181e54199d74e Mon Sep 17 00:00:00 2001 From: James Zern Date: Thu, 28 Mar 2024 17:51:39 -0700 Subject: [PATCH] cmake,wasm: simplify SDL2 related flags Use the result of find_package(SDL2); the cmake module is available prior to downloading the port. Previously the result of this call was ignored. This also updates the flags to use the results of SDL2_LIBRARIES which may be more future proof than specifying them manually. SDL2_INCLUDE_DIRS do not appear to be necessary with -sUSE_SDL2. Based in part on: https://github.com/microsoft/vcpkg/blob/d0b3e8efe3a885dcd5b764bf578e73c0bb83cc9f/ports/libwebp/0008-sdl.patch Bug: b:301040580 Change-Id: I83386b6c3d9628e3f0d9d17f20d47338d0db044a --- CMakeLists.txt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8310de6..b785a8e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -694,13 +694,10 @@ if(WEBP_BUILD_WEBP_JS) else() set(emscripten_stack_size "-sTOTAL_STACK=5MB") endif() - # Set SDL2 flags so that ports are downloaded by emscripten. - set(EMSCRIPTEN_SDL2_FLAGS "-sUSE_SDL=2 -sUSE_SDL_IMAGE=2") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EMSCRIPTEN_SDL2_FLAGS}") + find_package(SDL2 REQUIRED) # wasm2js does not support SIMD. if(NOT WEBP_ENABLE_SIMD) # JavaScript version - find_package(SDL2 QUIET) add_executable(webp_js ${CMAKE_CURRENT_SOURCE_DIR}/extras/webp_to_sdl.c) target_link_libraries(webp_js webpdecoder SDL2) target_include_directories(webp_js PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) @@ -708,10 +705,13 @@ if(WEBP_BUILD_WEBP_JS) set_target_properties( webp_js PROPERTIES + # Emscripten puts -sUSE_SDL2=1 in this variable, though it's needed at + # compile time to ensure the headers are downloaded. + COMPILE_OPTIONS "${SDL2_LIBRARIES}" LINK_FLAGS "-sWASM=0 ${emscripten_stack_size} \ -sEXPORTED_FUNCTIONS=_WebPToSDL -sINVOKE_RUN=0 \ - -sEXPORTED_RUNTIME_METHODS=cwrap ${EMSCRIPTEN_SDL2_FLAGS} \ + -sEXPORTED_RUNTIME_METHODS=cwrap ${SDL2_LIBRARIES} \ -sALLOW_MEMORY_GROWTH") set_target_properties(webp_js PROPERTIES OUTPUT_NAME webp) target_compile_definitions(webp_js PUBLIC EMSCRIPTEN WEBP_HAVE_SDL) @@ -724,10 +724,13 @@ if(WEBP_BUILD_WEBP_JS) set_target_properties( webp_wasm PROPERTIES + # Emscripten puts -sUSE_SDL2=1 in this variable, though it's needed at + # compile time to ensure the headers are downloaded. + COMPILE_OPTIONS "${SDL2_LIBRARIES}" LINK_FLAGS "-sWASM=1 ${emscripten_stack_size} \ -sEXPORTED_FUNCTIONS=_WebPToSDL -sINVOKE_RUN=0 \ - -sEXPORTED_RUNTIME_METHODS=cwrap ${EMSCRIPTEN_SDL2_FLAGS} \ + -sEXPORTED_RUNTIME_METHODS=cwrap ${SDL2_LIBRARIES} \ -sALLOW_MEMORY_GROWTH") target_compile_definitions(webp_wasm PUBLIC EMSCRIPTEN WEBP_HAVE_SDL)