blob: 001b01efa67e4d5f44a2440a2f4cf7da99a12db9 [file] [log] [blame]
set(AVIF_AVM_GIT_TAG research-v13.0.0)
message(CHECK_START "libavif(AVIF_CODEC_AVM=LOCAL): fetching and configuring avm")
# avm sets its compile options by setting variables like CMAKE_C_FLAGS_RELEASE using
# CACHE FORCE, which effectively adds those flags to all targets. We stash and restore
# the original values and call avif_set_avm_compile_options to instead set the flags on all avm
# targets
function(avif_set_avm_compile_options target config)
string(REPLACE " " ";" AVM_C_FLAGS_LIST "${CMAKE_C_FLAGS_${config}}")
string(REPLACE " " ";" AVM_CXX_FLAGS_LIST "${CMAKE_CXX_FLAGS_${config}}")
foreach(flag ${AVM_C_FLAGS_LIST})
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:C>:${flag}>)
endforeach()
foreach(flag ${AVM_CXX_FLAGS_LIST})
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${flag}>)
endforeach()
get_target_property(sources ${target} SOURCES)
foreach(src ${sources})
if(src MATCHES "TARGET_OBJECTS:")
string(REGEX REPLACE "\\$<TARGET_OBJECTS:(.*)>" "\\1" source_target ${src})
avif_set_avm_compile_options(${source_target} ${config})
endif()
endforeach()
endfunction()
set(AVM_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/avm-build")
if(ANDROID_ABI)
set(AVM_BINARY_DIR "${AVM_BINARY_DIR}/${ANDROID_ABI}")
endif()
FetchContent_Declare(
libavm
GIT_REPOSITORY "https://gitlab.com/AOMediaCodec/avm.git"
BINARY_DIR "${AVM_BINARY_DIR}"
GIT_TAG ${AVIF_AVM_GIT_TAG}
GIT_PROGRESS ON
GIT_SHALLOW OFF
UPDATE_COMMAND ""
# Avoid the following error when both aom and avm are built:
# CMake Error at build/_deps/libavm-src/CMakeLists.txt:1103 (add_custom_target):
# add_custom_target cannot create target "dist" because another target with
# the same name already exists. The existing target is a custom target
# created in source directory "libavif/build/_deps/libaom-src". See CMP0002.
# The patch LocalAvm.diff was generated by running:
# git clone -b research-v13.0.0 https://gitlab.com/AOMediaCodec/avm.git
# cd avm
# sed -i -e 's/ dist/ avm_dist/g' CMakeLists.txt
# git diff > LocalAvm.diff
# TODO: b/398931194 - Remove the patch when using a libavm version past
# https://gitlab.com/AOMediaCodec/avm/-/merge_requests/2985
PATCH_COMMAND git apply ${AVIF_SOURCE_DIR}/cmake/Modules/LocalAvm.diff
)
# There can be a duplicate cpuinfo in SVT so find_package has to be used.
set(RUY_FIND_CPUINFO ON CACHE INTERNAL "")
# TODO(vrabaud) Remove once libavm properly depends on flatbuffers.
include_directories(${CMAKE_CURRENT_BINARY_DIR}/flatbuffers/include/)
set(CONFIG_PIC 1 CACHE INTERNAL "")
if(libyuv_FOUND)
set(CONFIG_LIBYUV 0 CACHE INTERNAL "")
else()
set(CONFIG_LIBYUV 1 CACHE INTERNAL "")
endif()
set(CONFIG_WEBM_IO 0 CACHE INTERNAL "")
set(ENABLE_DOCS 0 CACHE INTERNAL "")
set(ENABLE_EXAMPLES 0 CACHE INTERNAL "")
set(ENABLE_TESTDATA 0 CACHE INTERNAL "")
set(ENABLE_TESTS 0 CACHE INTERNAL "")
set(ENABLE_TOOLS 0 CACHE INTERNAL "")
if(CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
set(AVM_TARGET_CPU "arm64")
endif()
if(NOT libavm_POPULATED)
# Guard against the project setting cmake variables that would affect the parent build
# See comment above for avif_set_avm_compile_options
foreach(_config_setting CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS)
foreach(_config_type DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
set(${_config_setting}_${_config_type}_ORIG ${${_config_setting}_${_config_type}})
endforeach()
endforeach()
avif_fetchcontent_populate_cmake(libavm)
set(_avm_config RELEASE)
if(CMAKE_BUILD_TYPE)
string(TOUPPER ${CMAKE_BUILD_TYPE} _avm_config)
endif()
list(LENGTH CMAKE_CONFIGURATION_TYPES num_configs)
if(${num_configs} GREATER 0)
list(GET CMAKE_CONFIGURATION_TYPES 0 _avm_config_type)
string(TOUPPER ${_avm_config_type} _avm_config)
endif()
avif_set_avm_compile_options(avm ${_avm_config})
# Restore the variables.
foreach(_config_setting CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS)
foreach(_config_type DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
unset(${_config_setting}_${_config_type} CACHE)
set(${_config_setting}_${_config_type} ${${_config_setting}_${_config_type}_ORIG} CACHE STRING "" FORCE)
unset(${_config_setting}_${_config_type}_ORIG)
endforeach()
endforeach()
unset(_config_type)
unset(_config_setting)
endif()
# If we have libyuv, we disable CONFIG_LIBYUV so that avm does not include the libyuv
# sources from its third-party vendor library. But we still want AVM to have libyuv, only
# linked against this project's target. Here we update the value in avm_config.h and add libyuv
# to AVM's link libraries
if(libyuv_FOUND)
file(READ ${AVM_BINARY_DIR}/config/avm_config.h AVM_CONFIG_H)
if("${AVM_CONFIG_H}" MATCHES "CONFIG_LIBYUV 0")
string(REPLACE "CONFIG_LIBYUV 0" "CONFIG_LIBYUV 1" AVM_CONFIG_H "${AVM_CONFIG_H}")
file(WRITE ${AVM_BINARY_DIR}/config/avm_config.h "${AVM_CONFIG_H}")
endif()
target_link_libraries(avm PRIVATE $<TARGET_FILE:yuv::yuv>)
endif()
# TODO(vrabaud) Remove once libavm properly depends on tensorflow-lite.
target_link_libraries(avm PRIVATE tensorflow-lite)
set_property(TARGET avm PROPERTY AVIF_LOCAL ON)
target_include_directories(avm INTERFACE $<BUILD_INTERFACE:$<PATH:ABSOLUTE_PATH,${libavm_SOURCE_DIR},/>>)
# libavm-src/avm/avm_encoder.h includes config/avm_config.h which is generated by the local build of avm.
target_include_directories(avm INTERFACE $<BUILD_INTERFACE:${AVM_BINARY_DIR}>)
message(CHECK_PASS "complete")