SDL_image: Work in progress adding aom support to the libavif build

From 64bb324e062b06375591a1550dcf457fe5a1ca8a Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 25 Jan 2024 08:22:06 -0800
Subject: [PATCH] Work in progress adding aom support to the libavif build

---
 .gitmodules    |  4 ++++
 CMakeLists.txt | 28 +++++++++++++++++++++++++---
 external/aom   |  1 +
 3 files changed, 30 insertions(+), 3 deletions(-)
 create mode 160000 external/aom

diff --git a/.gitmodules b/.gitmodules
index 273d2684..d8e9ac95 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -34,3 +34,7 @@
 	path = external/dav1d
 	url = https://github.com/libsdl-org/dav1d.git
 	branch = 1.2.1-SDL
+[submodule "external/aom"]
+	path = external/aom
+	url = https://github.com/libsdl-org/aom.git
+	branch = v3.6.1-SDL
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7323c5d6..7070e0ad 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -92,7 +92,7 @@ option(SDL3IMAGE_BACKEND_STB "Use stb_image for loading JPEG and PNG files" ON)
 cmake_dependent_option(SDL3IMAGE_BACKEND_WIC "Add WIC backend (Windows Imaging Component)" OFF WIN32 OFF)
 cmake_dependent_option(SDL3IMAGE_BACKEND_IMAGEIO "Use native Mac OS X frameworks for loading images" ON APPLE OFF)
 
-option(SDL3IMAGE_AVIF "Support loading AVIF images" OFF)
+option(SDL3IMAGE_AVIF "Support loading AVIF images" ON)
 option(SDL3IMAGE_BMP "Support loading BMP images" ON)
 option(SDL3IMAGE_GIF "Support loading GIF images" ON)
 option(SDL3IMAGE_JPG "Support loading JPEG images" ON)
@@ -120,19 +120,25 @@ else()
     set(SDL3IMAGE_AVIF_VENDORED OFF)
 endif()
 cmake_dependent_option(SDL3IMAGE_AVIF_SHARED "Dynamically load AVIF support (requires shared libavif)"
-    ${SDL3IMAGE_DEPS_SHARED} SDL3IMAGE_AVIF OFF)
+    ${SDL3IMAGE_DEPS_SHARED} SDL3IMAGE_AVIF ON)
 
 if(SDL3IMAGE_AVIF_VENDORED)
   set(SDL3IMAGE_DAV1D ON)
   set(SDL3IMAGE_DAV1D_VENDORED ON)
+  set(SDL3IMAGE_AOM ON)
+  set(SDL3IMAGE_AOM_VENDORED ON)
 else()
   set(SDL3IMAGE_DAV1D OFF)
   set(SDL3IMAGE_DAV1D_VENDORED OFF)
+  set(SDL3IMAGE_AOM OFF)
+  set(SDL3IMAGE_AOM_VENDORED OFF)
 endif()
 if(SDL3IMAGE_AVIF_SHARED)
   set(SDL3IMAGE_DAV1D_SHARED ON)
+  set(SDL3IMAGE_AOM_SHARED ON)
 else()
   set(SDL3IMAGE_DAV1D_SHARED OFF)
+  set(SDL3IMAGE_AOM_SHARED OFF)
 endif()
 
 if(SDL3IMAGE_VENDORED AND SDL3IMAGE_JPG AND NOT (SDL3IMAGE_BACKEND_WIC OR SDL3IMAGE_BACKEND_STB OR SDL3IMAGE_BACKEND_IMAGEIO))
@@ -417,6 +423,20 @@ if(SDL3IMAGE_DAV1D)
     endif()
 endif()
 
+if(SDL3IMAGE_AOM)
+    if(SDL3IMAGE_AOM_VENDORED)
+        message(STATUS "${PROJECT_NAME}: Using vendored aom")
+        set(BUILD_SHARED_LIBS ${SDL3IMAGE_AOM_SHARED})
+        add_subdirectory(external/aom)
+        set(AOM_LIBRARY aom)
+        if(SDL3IMAGE_AOM_SHARED OR NOT SDL3IMAGE_BUILD_SHARED_LIBS)
+            list(APPEND INSTALL_EXTRA_TARGETS aom)
+        endif()
+    else()
+        message(FATAL_ERROR "Internal error (dav1d is only required when requesting vendored dependencies)")
+    endif()
+endif()
+
 list(APPEND SDL3IMAGE_BACKENDS AVIF)
 set(SDL3IMAGE_AVIF_ENABLED FALSE)
 if(SDL3IMAGE_AVIF)
@@ -426,7 +446,9 @@ if(SDL3IMAGE_AVIF)
         sdl_check_project_in_subfolder(external/libavif libavif SDL3IMAGE_VENDORED)
         set(BUILD_SHARED_LIBS ${SDL3IMAGE_AVIF_SHARED})
         set(AVIF_CODEC_DAV1D ON CACHE BOOL "Use dav1d codec for decoding" FORCE)
-        set(AVIF_LOCAL_DAV1D OFF CACHE BOOL "Build dav1d by libaf" FORCE)
+        set(AVIF_LOCAL_DAV1D OFF CACHE BOOL "Build dav1d by libavif" FORCE)
+        set(AVIF_CODEC_AOM ON CACHE BOOL "Use aom codec for decoding" FORCE)
+        set(AVIF_LOCAL_AOM OFF CACHE BOOL "Build aom by libavif" FORCE)
         set(LIBAVIF_WITH_SHARPYUV_SDLIMAGE ${SDL3IMAGE_WEBP} CACHE BOOL "Build libavif with sharpyuv support (re-use sharpyuv built by libwebp)" FORCE)
         set(BUILD_SHARED_LIBS ${SDL3IMAGE_AVIF_SHARED})
         add_subdirectory(external/libavif EXCLUDE_FROM_ALL)
diff --git a/external/aom b/external/aom
new file mode 160000
index 00000000..7ade9617
--- /dev/null
+++ b/external/aom
@@ -0,0 +1 @@
+Subproject commit 7ade96172b95adc91a5d85bf80c90989cd543ee8