Skip to content

Commit

Permalink
cmake: backport support for vendored libavif from SDL3_image
Browse files Browse the repository at this point in the history
Hand-picked from commits d42d109, 6ef1e21, and c655da0.
  • Loading branch information
sezero committed Oct 16, 2023
1 parent b8e9dd3 commit 09fab01
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 15 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -72,6 +73,7 @@ jobs:
libpng \
libtiff \
libtool \
nasm \
ninja \
pkg-config \
webp \
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 37 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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$<TARGET_FILE_BASE_NAME:avif>)
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)
Expand Down
2 changes: 1 addition & 1 deletion Xcode/avif/dav1d/vcs_version.h
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion Xcode/avif/dav1d/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
2 changes: 1 addition & 1 deletion external/dav1d
Submodule dav1d updated 151 files
2 changes: 1 addition & 1 deletion external/libavif
Submodule libavif updated 196 files

0 comments on commit 09fab01

Please sign in to comment.