# Copyright 2019 Joe Drago. All rights reserved. # SPDX-License-Identifier: BSD-2-Clause cmake_minimum_required(VERSION 3.22) # New in CMake version 3.15. MSVC warning flags are not in CMAKE__FLAGS by default. if(POLICY CMP0092) cmake_policy(SET CMP0092 NEW) endif() # New in CMake version 3.19. Support the Xcode "new build system" for ExternalProject_Add(). if(POLICY CMP0114) cmake_policy(SET CMP0114 NEW) endif() # Prevent warnings in CMake>=3.24 for ExternalProject_Add() # see https://cmake.org/cmake/help/latest/policy/CMP0135.html if(POLICY CMP0135) cmake_policy(SET CMP0135 NEW) # valid for DOWNLOAD_EXTRACT_TIMESTAMP option in CMake 3.24 and later endif() # New in CMake version 3.30. FetchContent_Populate() is deprecated, call # FetchContent_MakeAvailable() instead. if(POLICY CMP0169) cmake_policy(SET CMP0169 OLD) endif() project(libavif LANGUAGES C VERSION 1.3.0) # The root directory of the avif source set(AVIF_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") # Specify search path for CMake modules to be loaded by include() and find_package() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") include(ExternalProject) include(FetchContent) include(FindPkgConfig) include(AvifExternalProjectUtils) include(GNUInstallDirs) option(AVIF_ENABLE_NODISCARD "Add [[nodiscard]] to some functions. CMake must be at least 3.21 to force C23." OFF) # Set C99 as the default if(AVIF_ENABLE_NODISCARD) # [[nodiscard]] requires C23. if(CMAKE_VERSION VERSION_LESS 3.21.0) message(FATAL_ERROR "CMake must be at least 3.21 to force C23, bailing out") endif() set(CMAKE_C_STANDARD 23) set(CMAKE_C_STANDARD_REQUIRED ON) else() set(CMAKE_C_STANDARD 99) endif() # SOVERSION scheme: MAJOR.MINOR.PATCH # If there was an incompatible interface change: # Increment MAJOR. Set MINOR and PATCH to 0 # If there was a compatible interface change: # Increment MINOR. Set PATCH to 0 # If the source code was changed, but there were no interface changes: # Increment PATCH. set(LIBRARY_VERSION_MAJOR 16) set(LIBRARY_VERSION_MINOR 3) set(LIBRARY_VERSION_PATCH 0) set(LIBRARY_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}") set(LIBRARY_SOVERSION ${LIBRARY_VERSION_MAJOR}) option(BUILD_SHARED_LIBS "Build shared avif library" ON) option(AVIF_ENABLE_WERROR "Treat all compiler warnings as errors" OFF) option(AVIF_ENABLE_EXPERIMENTAL_MINI "Enable experimental reduced header" OFF) option(AVIF_ENABLE_EXPERIMENTAL_SAMPLE_TRANSFORM "Enable experimental sample transform code" OFF) option(AVIF_ENABLE_EXPERIMENTAL_EXTENDED_PIXI "Enable experimental PixelInformationProperty syntax from HEIF 3rd Ed. Amd2" OFF) set(AVIF_PKG_CONFIG_EXTRA_LIBS_PRIVATE "") set(AVIF_PKG_CONFIG_EXTRA_REQUIRES_PRIVATE "") # Creates an option that can take the values 'OFF', 'SYSTEM' or 'LOCAL'. # The prefix 'AVIF_' is added to the option name automatically. function(set_local_or_system_option VAR DEFAULT TEXT) if(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) if(DEFINED AVIF_CODEC_${CODEC}) set(DEFAULT ${AVIF_CODEC_${CODEC}}) else() set(DEFAULT "OFF") endif() set(AVIF_CODEC_${CODEC} ${DEFAULT} CACHE STRING "Use the ${NAME} codec for ${ENCDEC}${EXTRA}" FORCE) set_property(CACHE AVIF_CODEC_${CODEC} PROPERTY STRINGS OFF LOCAL SYSTEM) 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 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 ) 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 ) set_local_or_system_option( "GTEST" OFF "Use the GoogleTest framework. Enables avif C++ tests that depend on GoogleTest. Has no effect unless AVIF_BUILD_TESTS is ON." ) option(AVIF_BUILD_APPS "Build avif apps." OFF) option(AVIF_BUILD_TESTS "Build avif tests." OFF) option( AVIF_ENABLE_COMPLIANCE_WARDEN "Check all avifEncoderFinish() output for AVIF specification compliance. Depends on gpac/ComplianceWarden which can be added with ext/compliance_warden.sh" OFF ) option( AVIF_ENABLE_GOLDEN_TESTS "Build tests that compare encoding outputs to golden files. Needs AVIF_BUILD_APPS=ON and AVIF_BUILD_TESTS=ON, and depends on MP4box which can be built with ext/mp4box.sh" OFF ) set_local_or_system_option( "FUZZTEST" OFF "Build the Google FuzzTest framework. Only OFF and LOCAL are supported. CMake must be at least 3.25." ) # Whether the libavif library uses c++ indirectly (e.g. through linking to libyuv). set(AVIF_LIB_USE_CXX OFF) if(APPLE) set(XCRUN xcrun) else() set(XCRUN) endif() # This is also needed to get shared libraries (e.g. pixbufloader-avif) to compile against a static libavif. set(CMAKE_POSITION_INDEPENDENT_CODE ON) if(BUILD_SHARED_LIBS) set(AVIF_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}") else() set(AVIF_LIBRARY_PREFIX "${CMAKE_STATIC_LIBRARY_PREFIX}") endif() add_library(avif_obj OBJECT) add_library(avif) # Adds to avif_obj's public link libraries for build, and adds # the library as an install link library for export in case a consumer # needs to include that library alongside libavif when statically linking. function(avif_target_link_library target) target_link_libraries(avif_obj PUBLIC $) get_target_property(target_is_local ${target} AVIF_LOCAL) if(target_is_local) return() endif() get_target_property(install_target ${target} IMPORTED_SONAME) if(NOT install_target) set(install_target ${target}) endif() # The transitive dependency needs to be an export link library in a static build. if(NOT BUILD_SHARED_LIBS) target_link_libraries(avif PUBLIC $) endif() endfunction() #[[ check_avif_option(