From f7ce882698307cad524603b9d528ce70c0d0d299 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Tue, 21 Nov 2023 11:24:29 +0100 Subject: [PATCH] Set some dependency options to be multi-choice. (#1758) * Set some dependency options to be multi-choice. The current options are complex: - you want a local AOM, you need to set to variables (AVIF_CODEC_AOM and AVIF_LOCAL_AOM to ON) - they can be confusing: some work in best effort, e.g. if you do not AVIF_LOCAL_LIBYUV, it tries to find libyuv if not, oh well, too bad let's move on. - you cannot disable some options: if libyuv is found, use it! Oh wait, I actually never asked for it (causing issues like https://github.com/AOMediaCodec/libavif/issues/1732) That's why I propose to set dependency options to: OFF: it will never be used whether it is findable or in ext LOCAL: it has to use the version in ext/ and will fail if not found SYSTEM: it will find_package it and fail if not found An AUTO version (that uses a dependency if found) should not be added as it will create more confusion for developers or package building. --- .github/workflows/ci-disable-gtest.yml | 9 +- .github/workflows/ci-linux-golden-tests.yml | 3 +- .../workflows/ci-unix-shared-installed.yml | 8 +- .github/workflows/ci-unix-shared-local.yml | 9 +- .github/workflows/ci-unix-static-av2.yml | 14 +-- .github/workflows/ci-unix-static.yml | 11 +- .github/workflows/ci-windows.yml | 11 +- CHANGELOG.md | 2 + CMakeLists.txt | 105 ++++++++++-------- README.md | 16 +-- android_jni/README.md | 6 +- .../src/main/jni/CMakeLists.txt | 6 +- appveyor.yml | 2 +- ext/aom.cmd | 2 +- ext/avm.cmd | 2 +- ext/dav1d.cmd | 2 +- ext/libgav1.cmd | 2 +- ext/libsharpyuv.cmd | 2 +- ext/libyuv.cmd | 2 +- ext/rav1e.cmd | 2 +- ext/svt.cmd | 2 +- ext/svt.sh | 2 +- tests/CMakeLists.txt | 6 +- tests/oss-fuzz/build.sh | 3 +- 24 files changed, 117 insertions(+), 112 deletions(-) diff --git a/.github/workflows/ci-disable-gtest.yml b/.github/workflows/ci-disable-gtest.yml index 31764a7707..3a5b1e49de 100644 --- a/.github/workflows/ci-disable-gtest.yml +++ b/.github/workflows/ci-disable-gtest.yml @@ -86,12 +86,9 @@ jobs: cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF - -DAVIF_CODEC_AOM=ON -DAVIF_LOCAL_AOM=ON - -DAVIF_CODEC_DAV1D=ON -DAVIF_LOCAL_DAV1D=ON - -DAVIF_CODEC_RAV1E=ON -DAVIF_LOCAL_RAV1E=ON - -DAVIF_CODEC_SVT=ON -DAVIF_LOCAL_SVT=ON - -DAVIF_LOCAL_LIBYUV=ON - -DAVIF_LOCAL_LIBSHARPYUV=ON + -DAVIF_CODEC_AOM=LOCAL -DAVIF_CODEC_DAV1D=LOCAL + -DAVIF_CODEC_RAV1E=LOCAL -DAVIF_CODEC_SVT=LOCAL + -DAVIF_LIBYUV=LOCAL -DAVIF_LIBSHARPYUV=LOCAL -DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON -DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=OFF - name: Build libavif (ninja) diff --git a/.github/workflows/ci-linux-golden-tests.yml b/.github/workflows/ci-linux-golden-tests.yml index 8e0e7e944d..3bb66aa3ba 100644 --- a/.github/workflows/ci-linux-golden-tests.yml +++ b/.github/workflows/ci-linux-golden-tests.yml @@ -69,8 +69,7 @@ jobs: cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF - -DAVIF_CODEC_AOM=ON -DAVIF_LOCAL_AOM=ON - -DAVIF_LOCAL_LIBYUV=ON + -DAVIF_CODEC_AOM=LOCAL -DAVIF_LIBYUV=LOCAL -DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON -DAVIF_ENABLE_EXPERIMENTAL_GAIN_MAP=ON -DAVIF_LOCAL_LIBXML2=ON diff --git a/.github/workflows/ci-unix-shared-installed.yml b/.github/workflows/ci-unix-shared-installed.yml index 634582d153..dadcc89d5c 100644 --- a/.github/workflows/ci-unix-shared-installed.yml +++ b/.github/workflows/ci-unix-shared-installed.yml @@ -66,9 +66,9 @@ jobs: cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON - -DAVIF_CODEC_AOM=ON + -DAVIF_CODEC_AOM=SYSTEM -DAVIF_CODEC_AOM_DECODE=OFF -DAVIF_CODEC_AOM_ENCODE=ON - -DAVIF_CODEC_DAV1D=ON + -DAVIF_CODEC_DAV1D=SYSTEM -DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON -DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_LOCAL_GTEST=ON -DAVIF_BUILD_GDK_PIXBUF=ON -DCMAKE_INSTALL_PREFIX=./install @@ -103,9 +103,9 @@ jobs: cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON - -DAVIF_CODEC_AOM=ON + -DAVIF_CODEC_AOM=SYSTEM -DAVIF_CODEC_AOM_DECODE=OFF -DAVIF_CODEC_AOM_ENCODE=ON - -DAVIF_CODEC_DAV1D=ON + -DAVIF_CODEC_DAV1D=SYSTEM -DAVIF_ENABLE_WUNUSED_RESULT=ON -DAVIF_ENABLE_WERROR=ON -DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON -DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_LOCAL_GTEST=ON diff --git a/.github/workflows/ci-unix-shared-local.yml b/.github/workflows/ci-unix-shared-local.yml index 554b03c53a..891fee487e 100644 --- a/.github/workflows/ci-unix-shared-local.yml +++ b/.github/workflows/ci-unix-shared-local.yml @@ -21,7 +21,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - libyuv: [ON, OFF] + libyuv: [OFF, LOCAL] name: build-shared-local (${{ matrix.os }}, libyuv ${{ matrix.libyuv }}) @@ -81,10 +81,9 @@ jobs: cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON - -DAVIF_CODEC_AOM=ON -DAVIF_LOCAL_AOM=ON - -DAVIF_CODEC_DAV1D=ON -DAVIF_LOCAL_DAV1D=ON - -DAVIF_LOCAL_LIBYUV=${{ matrix.libyuv }} - -DAVIF_LOCAL_LIBSHARPYUV=ON + -DAVIF_CODEC_AOM=LOCAL -DAVIF_CODEC_DAV1D=LOCAL + -DAVIF_LIBYUV=${{ matrix.libyuv }} + -DAVIF_LIBSHARPYUV=LOCAL -DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON -DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_LOCAL_GTEST=ON - name: Build libavif (ninja) diff --git a/.github/workflows/ci-unix-static-av2.yml b/.github/workflows/ci-unix-static-av2.yml index 3681627d35..ba08d9bc05 100644 --- a/.github/workflows/ci-unix-static-av2.yml +++ b/.github/workflows/ci-unix-static-av2.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - also-enable-av1-codecs: [ON, OFF] # On top of enabling AV2 codecs. + also-enable-av1-codecs: [OFF, LOCAL] # On top of enabling AV2 codecs. steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 @@ -85,12 +85,12 @@ jobs: cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF - -DAVIF_CODEC_AVM=ON -DAVIF_LOCAL_AVM=ON - -DAVIF_CODEC_DAV1D=${{ matrix.also-enable-av1-codecs }} -DAVIF_LOCAL_DAV1D=ON - -DAVIF_CODEC_RAV1E=${{ matrix.also-enable-av1-codecs }} -DAVIF_LOCAL_RAV1E=ON - -DAVIF_CODEC_SVT=${{ matrix.also-enable-av1-codecs }} -DAVIF_LOCAL_SVT=ON - -DAVIF_LOCAL_LIBYUV=ON - -DAVIF_LOCAL_LIBSHARPYUV=ON + -DAVIF_CODEC_AVM=LOCAL + -DAVIF_CODEC_DAV1D=${{ matrix.also-enable-av1-codecs }} + -DAVIF_CODEC_RAV1E=${{ matrix.also-enable-av1-codecs }} + -DAVIF_CODEC_SVT=${{ matrix.also-enable-av1-codecs }} + -DAVIF_LIBYUV=LOCAL + -DAVIF_LIBSHARPYUV=LOCAL -DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON -DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_LOCAL_GTEST=ON - name: Build libavif (ninja) diff --git a/.github/workflows/ci-unix-static.yml b/.github/workflows/ci-unix-static.yml index a22743884c..9508448935 100644 --- a/.github/workflows/ci-unix-static.yml +++ b/.github/workflows/ci-unix-static.yml @@ -92,13 +92,10 @@ jobs: cmake .. -G Ninja -DCMAKE_BUILD_TYPE=${{ runner.build-type }} -DBUILD_SHARED_LIBS=OFF - -DAVIF_CODEC_AOM=ON -DAVIF_LOCAL_AOM=ON - -DAVIF_CODEC_DAV1D=ON -DAVIF_LOCAL_DAV1D=ON - -DAVIF_CODEC_RAV1E=ON -DAVIF_LOCAL_RAV1E=ON - -DAVIF_CODEC_SVT=ON -DAVIF_LOCAL_SVT=ON - -DAVIF_CODEC_LIBGAV1=ON -DAVIF_LOCAL_LIBGAV1=ON - -DAVIF_LOCAL_LIBYUV=ON - -DAVIF_LOCAL_LIBSHARPYUV=ON + -DAVIF_CODEC_AOM=LOCAL -DAVIF_CODEC_DAV1D=LOCAL + -DAVIF_CODEC_RAV1E=LOCAL -DAVIF_CODEC_SVT=LOCAL + -DAVIF_CODEC_LIBGAV1=LOCAL -DAVIF_LIBYUV=LOCAL + -DAVIF_LIBSHARPYUV=LOCAL -DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON -DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_LOCAL_GTEST=ON -DAVIF_ENABLE_EXPERIMENTAL_YCGCO_R=ON diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index f48a1ac451..ed06f4ab3f 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -105,13 +105,10 @@ jobs: cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF - -DAVIF_CODEC_AOM=ON -DAVIF_LOCAL_AOM=ON - -DAVIF_CODEC_DAV1D=ON -DAVIF_LOCAL_DAV1D=ON - -DAVIF_CODEC_RAV1E=ON -DAVIF_LOCAL_RAV1E=ON - -DAVIF_CODEC_SVT=ON -DAVIF_LOCAL_SVT=ON - -DAVIF_CODEC_LIBGAV1=ON -DAVIF_LOCAL_LIBGAV1=ON - -DAVIF_LOCAL_LIBYUV=ON -DAVIF_LOCAL_JPEG=ON - -DAVIF_LOCAL_LIBSHARPYUV=ON + -DAVIF_CODEC_AOM=LOCAL -DAVIF_CODEC_DAV1D=LOCAL + -DAVIF_CODEC_RAV1E=LOCAL -DAVIF_CODEC_SVT=LOCAL + -DAVIF_CODEC_LIBGAV1=LOCAL -DAVIF_LIBYUV=LOCAL + -DAVIF_LOCAL_JPEG=ON -DAVIF_LIBSHARPYUV=LOCAL -DAVIF_LOCAL_ZLIBPNG=ON -DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON -DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_LOCAL_GTEST=ON diff --git a/CHANGELOG.md b/CHANGELOG.md index 313f08ede3..08a77e768b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 first II or MM tag in the Exif metadata payload will now fail to be decoded. Set decoder->ignoreExif to true to skip the issue and decode the image. * Fix memory errors reported in crbug.com/1501766 and crbug.com/1501770. +* For codecs, AVIF_CODEC_* and AVIF_LOCAL_* are now merged into AVIF_CODEC_* + that can only take the values: OFF, LOCAL or SYSTEM. ## [1.0.2] - 2023-11-16 diff --git a/CMakeLists.txt b/CMakeLists.txt index 61c515c587..6e12619d1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,30 +40,52 @@ option(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP ) option(AVIF_ENABLE_EXPERIMENTAL_AVIR "Enable experimental reduced header" OFF) -option(AVIF_CODEC_AOM "Use the AOM codec for encoding/decoding (see AVIF_CODEC_AOM_DECODE/AVIF_CODEC_AOM_ENCODE)" OFF) -option(AVIF_CODEC_DAV1D "Use the dav1d codec for decoding" OFF) -option(AVIF_CODEC_LIBGAV1 "Use the libgav1 codec for decoding" OFF) -option(AVIF_CODEC_RAV1E "Use the rav1e codec for encoding" OFF) -option(AVIF_CODEC_SVT "Use the SVT-AV1 codec for encoding" OFF) -option(AVIF_CODEC_AVM "Use the AVM (AV2) codec for encoding/decoding (EXPERIMENTAL)" OFF) +function(set_local_or_system_option VAR DEFAULT TEXT) + # Deal with the older way of setting options. + if(DEFINED AVIF_LOCAL_${VAR}) + if(AVIF_LOCAL_${CODEC}) + set(DEFAULT "LOCAL") + else() + set(DEFAULT "SYSTEM") + endif() + elseif(DEFINED AVIF_${VAR}) + set(DEFAULT ${AVIF_${VAR}}) + endif() + set(AVIF_${VAR} ${DEFAULT} CACHE STRING ${TEXT} FORCE) + set_property(CACHE AVIF_${VAR} PROPERTY STRINGS OFF LOCAL SYSTEM) +endfunction() +function(set_codec_option CODEC NAME ENCDEC EXTRA) + # Deal with the older way of setting options. + if(DEFINED AVIF_CODEC_${CODEC}) + set(DEFAULT ${AVIF_CODEC_${CODEC}}) + if(AVIF_CODEC_${CODEC} STREQUAL "ON") + if(AVIF_LOCAL_${CODEC}) + set(DEFAULT "LOCAL") + else() + set(DEFAULT "SYSTEM") + endif() + endif() + else() + set(DEFAULT "OFF") + endif() + set_local_or_system_option("CODEC_${CODEC}" ${DEFAULT} "Use the ${NAME} codec for ${ENCDEC}${EXTRA}") +endfunction() +set_codec_option(AOM "AOM" "encoding/decoding" " (see AVIF_CODEC_AOM_DECODE/AVIF_CODEC_AOM_ENCODE)") +set_codec_option(DAV1D "dav1d" "decoding" "") +set_codec_option(LIBGAV1 "libgav1" "decoding" "") +set_codec_option(RAV1E "rav1e" "encoding" "") +set_codec_option(SVT "SVT-AV1" "encoding" "") +set_codec_option(AVM "AVM (AV2)" "encoding/decoding" " (EXPERIMENTAL)") # These options allow libavif to only link against / use libaom's encoder or decoder, instead of being forced to use both -option(AVIF_CODEC_AOM_DECODE "if AVIF_CODEC_AOM is on, use/offer libaom's decoder" ON) -option(AVIF_CODEC_AOM_ENCODE "if AVIF_CODEC_AOM is on, use/offer libaom's encoder" ON) - -option(AVIF_LOCAL_AOM "Build the AOM codec by providing your own copy of the repo in ext/aom (see Local Builds in README)" OFF) -option(AVIF_LOCAL_DAV1D "Build the dav1d codec by providing your own copy of the repo in ext/dav1d (see Local Builds in README)" - OFF -) -option(AVIF_LOCAL_LIBGAV1 - "Build the libgav1 codec by providing your own copy of the repo in ext/libgav1 (see Local Builds in README)" OFF -) -option(AVIF_LOCAL_RAV1E "Build the rav1e codec by providing your own copy of the repo in ext/rav1e (see Local Builds in README)" - OFF +include(CMakeDependentOption) +cmake_dependent_option( + AVIF_CODEC_AOM_DECODE "if AVIF_CODEC_AOM is on, use/offer libaom's decoder" ON "NOT AVIF_CODEC_AOM STREQUAL OFF" OFF ) -option(AVIF_LOCAL_SVT - "Build the SVT-AV1 codec by providing your own copy of the repo in ext/SVT-AV1 (see Local Builds in README)" OFF +cmake_dependent_option( + AVIF_CODEC_AOM_ENCODE "if AVIF_CODEC_AOM is on, use/offer libaom's encoder" ON "NOT AVIF_CODEC_AOM STREQUAL OFF" OFF ) + option(AVIF_LOCAL_GTEST "Build the GoogleTest framework by providing your own copy of the repo in ext/googletest (see Local Builds in README)" OFF ) @@ -71,9 +93,6 @@ option(AVIF_LOCAL_FUZZTEST "Build the Google FuzzTest framework by providing your own copy of the repo in ext/fuzztest (see Local Builds in README)" OFF ) -option(AVIF_LOCAL_AVM "Build the AVM (AV2) codec by providing your own copy of the repo in ext/avm (see Local Builds in README)" - OFF -) option( AVIF_ENABLE_COMPLIANCE_WARDEN @@ -86,7 +105,7 @@ set(AVIF_USE_CXX OFF) if(AVIF_BUILD_APPS OR AVIF_ENABLE_FUZZTEST OR AVIF_ENABLE_GTEST - OR AVIF_LOCAL_LIBGAV1 + OR AVIF_CODEC_LIBGAV1 STREQUAL "LOCAL" ) set(AVIF_USE_CXX ON) endif() @@ -173,8 +192,8 @@ if(AVIF_LOCAL_JPEG) endif() endif() -option(AVIF_LOCAL_LIBYUV "Build libyuv by providing your own copy inside the ext subdir." OFF) -if(AVIF_LOCAL_LIBYUV) +set_local_or_system_option("LIBYUV" "OFF" "Use libyuv.") +if(AVIF_LIBYUV STREQUAL "LOCAL") set(AVIF_LIBYUV_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/libyuv/build") # If ${ANDROID_ABI} is set, look for the library under that subdirectory. @@ -184,7 +203,7 @@ if(AVIF_LOCAL_LIBYUV) set(LIB_FILENAME "${AVIF_LIBYUV_BUILD_DIR}/${AVIF_LIBRARY_PREFIX}yuv${CMAKE_STATIC_LIBRARY_SUFFIX}") if(NOT EXISTS "${LIB_FILENAME}") - message(FATAL_ERROR "libavif(AVIF_LOCAL_LIBYUV): ${LIB_FILENAME} is missing, bailing out") + message(FATAL_ERROR "libavif(AVIF_LIBYUV=LOCAL): ${LIB_FILENAME} is missing, bailing out") endif() if(("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") OR (DEFINED ANDROID_ABI)) set(LIBYUV_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/libyuv/include") @@ -195,8 +214,8 @@ if(AVIF_LOCAL_LIBYUV) endif() set(libyuv_FOUND TRUE) message(STATUS "libavif: local libyuv found; libyuv-based fast paths enabled.") -else(AVIF_LOCAL_LIBYUV) - find_package_libavif(libyuv QUIET) # not required +elseif(AVIF_LIBYUV STREQUAL "SYSTEM") + find_package_libavif(libyuv REQUIRED) if(libyuv_FOUND) # libyuv 1755 exposed all of the I*Matrix() functions, which libavif relies on. # libyuv 1774 exposed ScalePlane_12 function, which libavif can use for some additional optimizations. @@ -213,8 +232,6 @@ else(AVIF_LOCAL_LIBYUV) message(STATUS "libavif: some libyuv optimizations require at least version 1813 to work.") endif() endif() - else() - message(STATUS "libavif: libyuv not found; libyuv-based fast paths disabled.") endif() endif() if(libyuv_FOUND) @@ -223,11 +240,11 @@ if(libyuv_FOUND) set(AVIF_PLATFORM_LIBRARIES ${AVIF_PLATFORM_LIBRARIES} ${LIBYUV_LIBRARY}) endif(libyuv_FOUND) -option(AVIF_LOCAL_LIBSHARPYUV "Build libsharpyuv by providing your own copy inside the ext subdir." OFF) -if(AVIF_LOCAL_LIBSHARPYUV) +set_local_or_system_option("LIBSHARPYUV" "OFF" "Use libsharpyuv.") +if(AVIF_LIBSHARPYUV STREQUAL "LOCAL") set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/libwebp/build/libsharpyuv${CMAKE_STATIC_LIBRARY_SUFFIX}") if(NOT EXISTS "${LIB_FILENAME}") - message(FATAL_ERROR "libavif(AVIF_LOCAL_LIBSHARPYUV): ${LIB_FILENAME} is missing, bailing out") + message(FATAL_ERROR "libavif(AVIF_LIBSHARPYUV=LOCAL): ${LIB_FILENAME} is missing, bailing out") endif() if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") set(LIBSHARPYUV_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/libwebp") @@ -237,20 +254,18 @@ if(AVIF_LOCAL_LIBSHARPYUV) set(LIBSHARPYUV_LIBRARY ${LIB_FILENAME} PARENT_SCOPE) endif() set(libsharpyuv_FOUND TRUE) -else(AVIF_LOCAL_LIBSHARPYUV) - find_package_libavif(libsharpyuv QUIET) # not required +elseif(AVIF_LIBSHARPYUV STREQUAL "SYSTEM") + find_package_libavif(libsharpyuv REQUIRED) endif() if(libsharpyuv_FOUND) message(STATUS "libavif: libsharpyuv found; sharp rgb to yuv conversion enabled.") set(AVIF_PLATFORM_DEFINITIONS ${AVIF_PLATFORM_DEFINITIONS} -DAVIF_LIBSHARPYUV_ENABLED=1) - if(AVIF_LOCAL_LIBSHARPYUV) + if(AVIF_LIBSHARPYUV STREQUAL "LOCAL") set(AVIF_PLATFORM_INCLUDES ${AVIF_PLATFORM_INCLUDES} ${LIBSHARPYUV_INCLUDE_DIR}) else() set(AVIF_PLATFORM_SYSTEM_INCLUDES ${AVIF_PLATFORM_SYSTEM_INCLUDES} ${LIBSHARPYUV_INCLUDE_DIR}) endif() set(AVIF_PLATFORM_LIBRARIES ${AVIF_PLATFORM_LIBRARIES} ${LIBSHARPYUV_LIBRARY}) -else(libsharpyuv_FOUND) - message(STATUS "libavif: libsharpyuv not found") endif(libsharpyuv_FOUND) option(AVIF_LOCAL_LIBXML2 "Build libxml2 by providing your own copy inside the ext subdir. \ @@ -445,7 +460,7 @@ if(AVIF_CODEC_DAV1D) set(AVIF_CODEC_DEFINITIONS ${AVIF_CODEC_DEFINITIONS} -DAVIF_CODEC_DAV1D=1) set(AVIF_SRCS ${AVIF_SRCS} src/codec_dav1d.c) - if(AVIF_LOCAL_DAV1D) + if(AVIF_CODEC_DAV1D STREQUAL "LOCAL") set(AVIF_DAV1D_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/dav1d/build") # If ${ANDROID_ABI} is set, look for the library under that subdirectory. if(DEFINED ANDROID_ABI) @@ -491,7 +506,7 @@ if(AVIF_CODEC_LIBGAV1) set(AVIF_CODEC_DEFINITIONS ${AVIF_CODEC_DEFINITIONS} -DAVIF_CODEC_LIBGAV1=1) set(AVIF_SRCS ${AVIF_SRCS} src/codec_libgav1.c) - if(AVIF_LOCAL_LIBGAV1) + if(AVIF_CODEC_LIBGAV1 STREQUAL "LOCAL") set(AVIF_LIBGAV1_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/libgav1/build") # If ${ANDROID_ABI} is set, look for the library under that subdirectory. if(DEFINED ANDROID_ABI) @@ -520,7 +535,7 @@ if(AVIF_CODEC_RAV1E) set(AVIF_CODEC_DEFINITIONS ${AVIF_CODEC_DEFINITIONS} -DAVIF_CODEC_RAV1E=1) set(AVIF_SRCS ${AVIF_SRCS} src/codec_rav1e.c) - if(AVIF_LOCAL_RAV1E) + if(AVIF_CODEC_RAV1E STREQUAL "LOCAL") set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/rav1e/build.libavif/usr/lib/${AVIF_LIBRARY_PREFIX}rav1e${CMAKE_STATIC_LIBRARY_SUFFIX}" ) @@ -553,7 +568,7 @@ if(AVIF_CODEC_SVT) set(AVIF_CODEC_DEFINITIONS ${AVIF_CODEC_DEFINITIONS} -DAVIF_CODEC_SVT=1) set(AVIF_SRCS ${AVIF_SRCS} src/codec_svt.c) - if(AVIF_LOCAL_SVT) + if(AVIF_CODEC_SVT STREQUAL "LOCAL") set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/SVT-AV1/Bin/Release/${AVIF_LIBRARY_PREFIX}SvtAv1Enc${CMAKE_STATIC_LIBRARY_SUFFIX}" ) @@ -593,7 +608,7 @@ if(AVIF_CODEC_AOM) ) endif() set(AVIF_SRCS ${AVIF_SRCS} src/codec_aom.c) - if(AVIF_LOCAL_AOM) + if(AVIF_CODEC_AOM STREQUAL "LOCAL") set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/aom/build.libavif/${AVIF_LIBRARY_PREFIX}aom${CMAKE_STATIC_LIBRARY_SUFFIX}" ) @@ -626,7 +641,7 @@ if(AVIF_CODEC_AVM) set(AVIF_CODEC_DEFINITIONS ${AVIF_CODEC_DEFINITIONS} -DAVIF_CODEC_AVM=1) set(AVIF_SRCS ${AVIF_SRCS} src/codec_avm.c) - if(AVIF_LOCAL_AVM) + if(AVIF_CODEC_AVM STREQUAL "LOCAL") # Building the avm repository generates files such as "libaom.a" because it is a fork of aom. set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/avm/build.libavif/${AVIF_LIBRARY_PREFIX}aom${CMAKE_STATIC_LIBRARY_SUFFIX}" diff --git a/README.md b/README.md index bc2a2572f3..babbb51a96 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,9 @@ run the examples too. Building libavif requires [CMake](https://cmake.org/). -No AV1 codecs are enabled by default. Enable them by enabling any of the -following CMake options (e.g. `-DAVIF_CODEC_AOM=ON`): +No AV1 codecs are enabled by default. Enable them by setting any of the +following CMake options to `LOCAL` or `SYSTEM` whether you want to use a +locally built or a system installed version (e.g. `-DAVIF_CODEC_AOM=LOCAL`): * `AVIF_CODEC_AOM` for [libaom](https://aomedia.googlesource.com/aom/) (encoder and decoder) @@ -36,9 +37,9 @@ following CMake options (e.g. `-DAVIF_CODEC_AOM=ON`): * `AVIF_CODEC_SVT` for [SVT-AV1](https://gitlab.com/AOMediaCodec/SVT-AV1) (encoder) -These libraries (in their C API form) must be externally available -(discoverable via CMake's `FIND_LIBRARY`) to use them, or if libavif is -a child CMake project, the appropriate CMake target must already exist +When set to `SYSTEM`, these libraries (in their C API form) must be externally +available (discoverable via CMake's `FIND_LIBRARY`) to use them, or if libavif +is a child CMake project, the appropriate CMake target must already exist by the time libavif's CMake scripts are executed. ### Local / Static Builds @@ -51,8 +52,9 @@ list of requirements. If you want to statically link any codec into your local (static) build of libavif, building using one of these scripts and then enabling the associated -`AVIF_LOCAL_*` is a convenient method, but you must make sure to disable -`BUILD_SHARED_LIBS` in CMake to instruct it to make a static libavif library. +`AVIF_LOCAL_*` and setting `AVIF_CODEC_*` to `LOCAL` is a convenient method, +but you must make sure to disable `BUILD_SHARED_LIBS` in CMake to instruct it +to make a static libavif library. If you want to build/install shared libraries for AV1 codecs, you can still peek inside of each script to see where the current known-good SHA is for each diff --git a/android_jni/README.md b/android_jni/README.md index 047b6cc233..f7a15c41cd 100644 --- a/android_jni/README.md +++ b/android_jni/README.md @@ -48,8 +48,8 @@ $ cd .. ``` Update [CMakeLists.txt](avifandroidjni/src/main/jni/CMakeLists.txt) as follows: - * Set `AVIF_LOCAL_DAV1D` and `AVIF_CODEC_DAV1D` to `OFF`. - * Set `AVIF_LOCAL_LIBGAV1` and `AVIF_CODEC_LIBGAV1` to `ON`. + * Set `AVIF_CODEC_DAV1D` to `OFF` + * Set `AVIF_CODEC_LIBGAV1` to `LOCAL`. Step 4 - Checkout and build libyuv @@ -61,7 +61,7 @@ $ cd .. If you do not want to use libyuv, then update [CMakeLists.txt](avifandroidjni/src/main/jni/CMakeLists.txt) as follows: - * Set `AVIF_LOCAL_LIBYUV` to `OFF`. + * Set `AVIF_LIBYUV` to `OFF`. Step 5 - Build the JNI Wrapper and generate the AAR package diff --git a/android_jni/avifandroidjni/src/main/jni/CMakeLists.txt b/android_jni/avifandroidjni/src/main/jni/CMakeLists.txt index 7c385b1b8a..185a2b3e27 100644 --- a/android_jni/avifandroidjni/src/main/jni/CMakeLists.txt +++ b/android_jni/avifandroidjni/src/main/jni/CMakeLists.txt @@ -17,15 +17,13 @@ project(avif_android_jni) set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) # To disable dav1d, change the following two variables to OFF. -set(AVIF_CODEC_DAV1D ON CACHE BOOL "" FORCE) -set(AVIF_LOCAL_DAV1D ON CACHE BOOL "" FORCE) +set(AVIF_CODEC_DAV1D "LOCAL" CACHE STRING "" FORCE) # To disable libyuv, change this variable to OFF. -set(AVIF_LOCAL_LIBYUV ON CACHE BOOL "" FORCE) +set(AVIF_LIBYUV "LOCAL" CACHE STRING "" FORCE) # To enable libgav1, change the following two variables to ON. set(AVIF_CODEC_LIBGAV1 OFF CACHE BOOL "" FORCE) -set(AVIF_LOCAL_LIBGAV1 OFF CACHE BOOL "" FORCE) # The current CMake file lives in: # $LIBAVIF_ROOT/android_jni/avifandroidjni/src/main/jni. diff --git a/appveyor.yml b/appveyor.yml index 37995e71da..3f81f0d5ec 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,7 +30,7 @@ install: - mkdir build - cd build - cmake --version - - cmake .. -DAVIF_CODEC_AOM=ON -DAVIF_LOCAL_AOM=ON -DAVIF_CODEC_DAV1D=ON -DAVIF_LOCAL_DAV1D=ON -DBUILD_SHARED_LIBS=OFF -DAVIF_LOCAL_JPEG=ON -DAVIF_LOCAL_ZLIBPNG=ON -DAVIF_LOCAL_LIBYUV=ON -DAVIF_BUILD_APPS=ON + - cmake .. -DAVIF_CODEC_AOM=LOCAL -DAVIF_CODEC_DAV1D=LOCAL -DBUILD_SHARED_LIBS=OFF -DAVIF_LOCAL_JPEG=ON -DAVIF_LOCAL_ZLIBPNG=ON -DAVIF_LIBYUV=LOCAL -DAVIF_BUILD_APPS=ON build: project: build/libavif.sln diff --git a/ext/aom.cmd b/ext/aom.cmd index a8ba9cfca8..9404f5ab92 100755 --- a/ext/aom.cmd +++ b/ext/aom.cmd @@ -1,4 +1,4 @@ -: # If you want to use a local build of libaom, you must clone the aom repo in this directory first, then enable CMake's AVIF_CODEC_AOM and AVIF_LOCAL_AOM options. +: # If you want to use a local build of libaom, you must clone the aom repo in this directory first, then set CMake's AVIF_CODEC_AOM to LOCAL options. : # The git SHA below is known to work, and will occasionally be updated. Feel free to use a more recent commit. : # The odd choice of comment style in this file is to try to share this script between *nix and win32. diff --git a/ext/avm.cmd b/ext/avm.cmd index a3528aa36c..50412d592c 100755 --- a/ext/avm.cmd +++ b/ext/avm.cmd @@ -1,4 +1,4 @@ -: # If you want to use a local build of libavm, you must clone the avm repo in this directory first, then enable CMake's AVIF_CODEC_AVM and AVIF_LOCAL_AVM options. +: # If you want to use a local build of libavm, you must clone the avm repo in this directory first, then set CMake's AVIF_CODEC_AVM to LOCAL. : # The git SHA below is known to work, and will occasionally be updated. Feel free to use a more recent commit. : # The odd choice of comment style in this file is to try to share this script between *nix and win32. diff --git a/ext/dav1d.cmd b/ext/dav1d.cmd index 02d2b35938..cf9cc77b9b 100755 --- a/ext/dav1d.cmd +++ b/ext/dav1d.cmd @@ -1,4 +1,4 @@ -: # If you want to use a local build of dav1d, you must clone the dav1d repo in this directory first, then enable CMake's AVIF_CODEC_DAV1D and AVIF_LOCAL_DAV1D options. +: # If you want to use a local build of dav1d, you must clone the dav1d repo in this directory first, then set CMake's AVIF_CODEC_DAV1D to LOCAL. : # The git SHA below is known to work, and will occasionally be updated. Feel free to use a more recent commit. : # The odd choice of comment style in this file is to try to share this script between *nix and win32. diff --git a/ext/libgav1.cmd b/ext/libgav1.cmd index a819252eef..d5b5a3cc51 100755 --- a/ext/libgav1.cmd +++ b/ext/libgav1.cmd @@ -1,4 +1,4 @@ -: # If you want to use a local build of libgav1, you must clone the libgav1 repo in this directory first, then enable CMake's AVIF_CODEC_LIBGAV1 and AVIF_LOCAL_LIBGAV1 options. +: # If you want to use a local build of libgav1, you must clone the libgav1 repo in this directory first, then set CMake's AVIF_CODEC_LIBGAV1 to LOCAL. : # The git SHA below is known to work, and will occasionally be updated. Feel free to use a more recent commit. : # The odd choice of comment style in this file is to try to share this script between *nix and win32. diff --git a/ext/libsharpyuv.cmd b/ext/libsharpyuv.cmd index 9f823b6c57..0e05410f3b 100755 --- a/ext/libsharpyuv.cmd +++ b/ext/libsharpyuv.cmd @@ -1,5 +1,5 @@ : # If you want to use a local build of libsharpyuv, you must clone the libwebp repo in this directory first, -: # then enable CMake's AVIF_LOCAL_LIBSHARPYUV option. +: # then set CMake's AVIF_LIBSHARPYUV to LOCAL. : # The odd choice of comment style in this file is to try to share this script between *nix and win32. diff --git a/ext/libyuv.cmd b/ext/libyuv.cmd index 86bc64343d..59179e6ed9 100755 --- a/ext/libyuv.cmd +++ b/ext/libyuv.cmd @@ -1,4 +1,4 @@ -: # If you want to use a local build of libyuv, you must clone the libyuv repo in this directory first, then enable CMake's AVIF_LOCAL_LIBYUV option. +: # If you want to use a local build of libyuv, you must clone the libyuv repo in this directory first, then set CMake's AVIF_LIBYUV to LOCAL. : # The odd choice of comment style in this file is to try to share this script between *nix and win32. diff --git a/ext/rav1e.cmd b/ext/rav1e.cmd index 3f44d89ccf..eaaeb803eb 100755 --- a/ext/rav1e.cmd +++ b/ext/rav1e.cmd @@ -1,4 +1,4 @@ -: # If you want to use a local build of rav1e, you must clone the rav1e repo in this directory first, then enable CMake's AVIF_CODEC_RAV1E and AVIF_LOCAL_RAV1E options. +: # If you want to use a local build of rav1e, you must clone the rav1e repo in this directory first, then set CMake's AVIF_CODEC_RAV1E to LOCAL. : # The git SHA below is known to work, and will occasionally be updated. Feel free to use a more recent commit. : # The odd choice of comment style in this file is to try to share this script between *nix and win32. diff --git a/ext/svt.cmd b/ext/svt.cmd index 411d54ebad..5794ce4baa 100755 --- a/ext/svt.cmd +++ b/ext/svt.cmd @@ -1,5 +1,5 @@ : # If you want to use a local build of SVT-AV1, you must clone the SVT-AV1 repo in this directory first, -: # then enable CMake's AVIF_CODEC_SVT and AVIF_LOCAL_SVT options. +: # then set CMake's AVIF_CODEC_SVT to LOCAL. : # cmake and ninja must be in your PATH. : # The odd choice of comment style in this file is to try to share this script between *nix and win32. diff --git a/ext/svt.sh b/ext/svt.sh index b6142ba080..39171443d9 100644 --- a/ext/svt.sh +++ b/ext/svt.sh @@ -1,5 +1,5 @@ # If you want to use a local build of SVT-AV1, you must clone the SVT-AV1 repo in this directory first, -# then enable CMake's AVIF_CODEC_SVT and AVIF_LOCAL_SVT options. +# then set CMake's AVIF_CODEC_SVT to LOCAL. # cmake and ninja must be in your PATH. set -e diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b12d18476b..6c594646a3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,7 +9,7 @@ enable_testing() # C tests and tools add_executable(aviftest aviftest.c) -if(AVIF_LOCAL_LIBGAV1) +if(AVIF_CODEC_LIBGAV1 STREQUAL "LOCAL") set_target_properties(aviftest PROPERTIES LINKER_LANGUAGE "CXX") endif() target_link_libraries(aviftest avif ${AVIF_PLATFORM_LIBRARIES}) @@ -31,7 +31,7 @@ if(AVIF_ENABLE_COVERAGE) endif() add_executable(avifyuv avifyuv.c) -if(AVIF_LOCAL_LIBGAV1) +if(AVIF_CODEC_LIBGAV1 STREQUAL "LOCAL") set_target_properties(avifyuv PROPERTIES LINKER_LANGUAGE "CXX") endif() target_link_libraries(avifyuv avif ${AVIF_PLATFORM_LIBRARIES}) @@ -46,7 +46,7 @@ endif() # Fuzz target without any fuzzing engine dependency. For easy reproduction of oss-fuzz issues. add_executable(repro_avif_decode_fuzzer oss-fuzz/avif_decode_fuzzer.cc oss-fuzz/repro_fuzz.cc) -if(AVIF_LOCAL_LIBGAV1) +if(AVIF_CODEC_LIBGAV1 STREQUAL "LOCAL") set_target_properties(repro_avif_decode_fuzzer PROPERTIES LINKER_LANGUAGE "CXX") endif() target_link_libraries(repro_avif_decode_fuzzer avif ${AVIF_PLATFORM_LIBRARIES}) diff --git a/tests/oss-fuzz/build.sh b/tests/oss-fuzz/build.sh index 4002bbe715..e7f6738d46 100755 --- a/tests/oss-fuzz/build.sh +++ b/tests/oss-fuzz/build.sh @@ -26,8 +26,7 @@ cd ext && bash dav1d.cmd && bash libyuv.cmd && cd .. mkdir build cd build cmake -G Ninja -DBUILD_SHARED_LIBS=OFF \ - -DAVIF_CODEC_DAV1D=ON -DAVIF_LOCAL_DAV1D=ON \ - -DAVIF_LOCAL_LIBYUV=ON .. + -DAVIF_CODEC_DAV1D=LOCAL -DAVIF_LIBYUV=LOCAL .. ninja # build fuzzer