# patch-libwebp-simd.cmake — portable, idempotent FetchContent patch for libwebp. # # libwebp's cmake/cpu.cmake compiles its scalar *reference* DSP files with the # SSE-disable flags "-mno-sse4.1;-mno-sse2" whenever it can't positively detect # SSE support. Under a macOS *universal* build (-arch arm64;x86_64) the per-arch # SSE flag probe fails (a flag valid for x86_64 is invalid for arm64), so those # disable flags get applied to the x86_64 slice. clang gates the _Float16 type on # SSE2 for x86_64, and the macOS 15+/26 SDK's declares _Float16 math # functions unconditionally — so any TU including fails to compile with # "_Float16 is not supported on this target". # # SSE2 is part of the x86_64 baseline ABI, so disabling it on the reference files # is unnecessary on every platform we target. Blanking the SSE entries (indices # must stay aligned with WEBP_SIMD_FLAGS) fixes the universal build and is a no-op # for single-arch Linux/Windows/x86_64 builds. Idempotent: re-running is a no-op. if(NOT DEFINED CPU_CMAKE OR NOT EXISTS "${CPU_CMAKE}") message(FATAL_ERROR "patch-libwebp-simd: cpu.cmake not found at '${CPU_CMAKE}'") endif() file(READ "${CPU_CMAKE}" _contents) string(REPLACE "set(SIMD_DISABLE_FLAGS \"-mno-sse4.1;-mno-sse2;;-mno-dspr2;;-mno-msa\")" "set(SIMD_DISABLE_FLAGS \";;;-mno-dspr2;;-mno-msa\")" _patched "${_contents}") if(_patched STREQUAL _contents) message(STATUS "patch-libwebp-simd: no change (already patched or pattern absent)") else() file(WRITE "${CPU_CMAKE}" "${_patched}") message(STATUS "patch-libwebp-simd: neutralized x86 SSE-disable flags in cpu.cmake") endif()