From 09fab01205460ded0e975dd4c399d46c575751ad Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sun, 15 Oct 2023 23:55:50 +0300 Subject: [PATCH] cmake: backport support for vendored libavif from SDL3_image Hand-picked from commits d42d109b, 6ef1e21a, and c655da07. --- .github/workflows/main.yml | 15 ++++++++----- .gitmodules | 4 ++-- CMakeLists.txt | 41 ++++++++++++++++++++++++++++++---- Xcode/avif/dav1d/vcs_version.h | 2 +- Xcode/avif/dav1d/version.h | 2 +- external/dav1d | 2 +- external/libavif | 2 +- 7 files changed, 53 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1352288e..9c0415be 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -40,14 +40,15 @@ jobs: ${{ matrix.platform.msys-env }}-autotools ${{ matrix.platform.msys-env }}-cmake ${{ matrix.platform.msys-env }}-gcc + ${{ matrix.platform.msys-env }}-ninja + ${{ matrix.platform.msys-env }}-pkg-config + ${{ matrix.platform.msys-env }}-nasm ${{ matrix.platform.msys-env }}-libavif ${{ matrix.platform.msys-env }}-libjpeg-turbo ${{ matrix.platform.msys-env }}-libjxl ${{ matrix.platform.msys-env }}-libpng ${{ matrix.platform.msys-env }}-libtiff ${{ matrix.platform.msys-env }}-libwebp - ${{ matrix.platform.msys-env }}-ninja - ${{ matrix.platform.msys-env }}-pkg-config ${{ matrix.platform.msys-env }}-zlib - name: Install Ninja uses: turtlesec-no/get-ninja@main @@ -72,6 +73,7 @@ jobs: libpng \ libtiff \ libtool \ + nasm \ ninja \ pkg-config \ webp \ @@ -91,10 +93,14 @@ jobs: libtiff-dev \ libtool \ libwebp-dev \ + nasm \ ninja-build \ pkg-config \ zlib1g-dev \ ${NULL+} + - name: Set up NASM + uses: ilammy/setup-nasm@v1 + if: ${{ matrix.platform.vendored && !contains(matrix.platform.shell, 'msys2') }} - uses: actions/checkout@v3 with: @@ -123,11 +129,10 @@ jobs: -DSDL2IMAGE_SAMPLES=ON \ -DSDL2IMAGE_TESTS=ON \ -DSDL2IMAGE_TESTS_INSTALL=ON \ - -DSDL2IMAGE_AVIF=${{ !matrix.platform.vendored }} \ + -DSDL2IMAGE_AVIF=ON \ -DSDL2IMAGE_JXL=ON \ -DSDL2IMAGE_TIF=ON \ -DSDL2IMAGE_WEBP=ON \ - -DSDL2IMAGE_VENDORED=${{ !!matrix.platform.vendored }} \ -DCMAKE_INSTALL_PREFIX=prefix_cmake \ ${{ matrix.platform.cmake }} - name: Build (CMake) @@ -149,7 +154,7 @@ jobs: export PATH="$sdl_binpath:$sdlimage_binpath:$PATH" fi - export SDL_IMAGE_TEST_REQUIRE_LOAD_AVIF=${{ (matrix.platform.vendored && '0') || '1' }} + export SDL_IMAGE_TEST_REQUIRE_LOAD_AVIF=1 export SDL_IMAGE_TEST_REQUIRE_LOAD_BMP=1 export SDL_IMAGE_TEST_REQUIRE_LOAD_CUR=1 export SDL_IMAGE_TEST_REQUIRE_LOAD_GIF=1 diff --git a/.gitmodules b/.gitmodules index 5b93a7fe..48d987df 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,8 +25,8 @@ [submodule "external/libavif"] path = external/libavif url = https://github.com/libsdl-org/libavif.git - branch = v0.10.1-SDL + branch = v1.0.1-SDL [submodule "external/dav1d"] path = external/dav1d url = https://github.com/libsdl-org/dav1d.git - branch = 1.0.0-SDL + branch = 1.2.1-SDL diff --git a/CMakeLists.txt b/CMakeLists.txt index d0ce6f97..705ab0ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,19 @@ endif() cmake_dependent_option(SDL2IMAGE_AVIF_SHARED "Dynamically load AVIF support (requires shared libavif)" ${SDL2IMAGE_DEPS_SHARED} SDL2IMAGE_AVIF OFF) +if(SDL2IMAGE_AVIF_VENDORED) + set(SDL2IMAGE_DAV1D ON) + set(SDL2IMAGE_DAV1D_VENDORED ON) +else() + set(SDL2IMAGE_DAV1D OFF) + set(SDL2IMAGE_DAV1D_VENDORED OFF) +endif() +if(SDL2IMAGE_AVIF_SHARED) + set(SDL2IMAGE_DAV1D_SHARED ON) +else() + set(SDL2IMAGE_DAV1D_SHARED OFF) +endif() + if(SDL2IMAGE_VENDORED AND SDL2IMAGE_JPG AND NOT (SDL2IMAGE_BACKEND_WIC OR SDL2IMAGE_BACKEND_STB OR SDL2IMAGE_BACKEND_IMAGEIO)) set(SDL2IMAGE_JPG_VENDORED ON) else() @@ -352,20 +365,40 @@ if(SDL2IMAGE_ZLIB) endif() endif() +if(SDL2IMAGE_DAV1D) + if(SDL2IMAGE_DAV1D_VENDORED) + message(STATUS "${PROJECT_NAME}: Using vendored dav1d") + add_subdirectory(external/dav1d) + set(DAV1D_LIBRARY dav1d) + list(APPEND INSTALL_EXTRA_TARGETS dav1d) + else() + message(FATAL_ERROR "Not implemented") + endif() +endif() + if(SDL2IMAGE_AVIF) target_compile_definitions(SDL2_image PRIVATE LOAD_AVIF) if(SDL2IMAGE_AVIF_VENDORED) message(STATUS "${PROJECT_NAME}: Using vendored libavif") - message(FATAL_ERROR "libavif is not vendored (yet)") sdl_check_project_in_subfolder(external/libavif libavif SDL2IMAGE_VENDORED) set(BUILD_SHARED_LIBS ${SDL2IMAGE_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) + #FIXME: This requires upgrading vendored libwebp to >= 1.2.4. + #set(LIBAVIF_WITH_SHARPYUV_SDLIMAGE ${SDL2IMAGE_WEBP} CACHE BOOL "Build libavif with sharpyuv support (re-use sharpyuv built by libwebp)" FORCE) add_subdirectory(external/libavif EXCLUDE_FROM_ALL) - list(APPEND INSTALL_EXTRA_TARGETS libavif) - set_target_properties(libavif PROPERTIES EXPORT_NAME external_libavif) - add_library(SDL2_image::external_libavif ALIAS libavif) + list(APPEND INSTALL_EXTRA_TARGETS avif) + set_target_properties(avif PROPERTIES EXPORT_NAME external_libavif) + add_library(SDL2_image::external_libavif ALIAS avif) if(NOT SDL2IMAGE_AVIF_SHARED) list(APPEND PC_LIBS -l$) endif() + if(NOT MSVC) + check_linker_flag(C "-Wl,--no-undefined" LINKER_SUPPORTS_WL_NO_UNDEFINED) + if(LINKER_SUPPORTS_WL_NO_UNDEFINED) + target_link_options(avif PRIVATE "-Wl,--no-undefined") + endif() + endif() else() message(STATUS "${PROJECT_NAME}: Using system libavif") find_package(libavif 1.0 QUIET) diff --git a/Xcode/avif/dav1d/vcs_version.h b/Xcode/avif/dav1d/vcs_version.h index 7e0425ea..9084bcab 100644 --- a/Xcode/avif/dav1d/vcs_version.h +++ b/Xcode/avif/dav1d/vcs_version.h @@ -1,2 +1,2 @@ /* auto-generated, do not edit */ -#define DAV1D_VERSION "1.0.0-0-g99172b1" +#define DAV1D_VERSION "1.2.1-3-g5315741" diff --git a/Xcode/avif/dav1d/version.h b/Xcode/avif/dav1d/version.h index 5619d66b..176d3ac2 100644 --- a/Xcode/avif/dav1d/version.h +++ b/Xcode/avif/dav1d/version.h @@ -28,7 +28,7 @@ #define DAV1D_VERSION_H #define DAV1D_API_VERSION_MAJOR 6 -#define DAV1D_API_VERSION_MINOR 6 +#define DAV1D_API_VERSION_MINOR 9 #define DAV1D_API_VERSION_PATCH 0 #endif /* DAV1D_VERSION_H */ diff --git a/external/dav1d b/external/dav1d index 52d0c1f4..0e6d055b 160000 --- a/external/dav1d +++ b/external/dav1d @@ -1 +1 @@ -Subproject commit 52d0c1f44eff76c3773636a9805f69ec26633037 +Subproject commit 0e6d055b1165e29cfd67b39e564ead217363e6a2 diff --git a/external/libavif b/external/libavif index a3e93154..dfc14a75 160000 --- a/external/libavif +++ b/external/libavif @@ -1 +1 @@ -Subproject commit a3e9315474deb60e39b6e3aad88798eee26dadea +Subproject commit dfc14a758cb9ad398b78fd6b60ec2144e67e9651