File: LocalAvm.cmake

package info (click to toggle)
libavif 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,648 kB
  • sloc: ansic: 30,743; cpp: 14,606; xml: 1,507; sh: 1,296; java: 307; makefile: 57
file content (125 lines) | stat: -rw-r--r-- 5,613 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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()

FetchContent_Declare(
    libavm
    EXCLUDE_FROM_ALL
    GIT_REPOSITORY "https://gitlab.com/AOMediaCodec/avm.git"
    GIT_TAG ${AVIF_AVM_GIT_TAG}
    GIT_PROGRESS ON
    GIT_SHALLOW ON
    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_makeavailable_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 ${libavm_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 ${libavm_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:${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:${libavm_BINARY_DIR}>)

message(CHECK_PASS "complete")