tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CMakeLists.txt (46975B)


      1 #
      2 # Copyright (c) 2016, Alliance for Open Media. All rights reserved.
      3 #
      4 # This source code is subject to the terms of the BSD 2 Clause License and the
      5 # Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
      6 # not distributed with this source code in the LICENSE file, you can obtain it
      7 # at www.aomedia.org/license/software. If the Alliance for Open Media Patent
      8 # License 1.0 was not distributed with this source code in the PATENTS file, you
      9 # can obtain it at www.aomedia.org/license/patent.
     10 #
     11 cmake_minimum_required(VERSION 3.16)
     12 
     13 set(AOM_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
     14 set(AOM_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
     15 if("${AOM_ROOT}" STREQUAL "${AOM_CONFIG_DIR}")
     16  message(
     17    FATAL_ERROR "Building from within the aom source tree is not supported.\n"
     18                "Hint: Run these commands\n"
     19                "$ rm -rf CMakeCache.txt CMakeFiles\n"
     20                "$ mkdir -p ../aom_build\n" "$ cd ../aom_build\n"
     21                "And re-run CMake from the aom_build directory.")
     22 endif()
     23 
     24 # VERSION is the release version of the library. It should be updated at the
     25 # same time as the LT_* variables.
     26 project(AOM LANGUAGES C CXX VERSION 3.13.1)
     27 
     28 # GENERATED source property global visibility.
     29 if(POLICY CMP0118)
     30  cmake_policy(SET CMP0118 NEW)
     31 endif()
     32 
     33 if(NOT EMSCRIPTEN)
     34  if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
     35    set(CMAKE_BUILD_TYPE
     36        "Release"
     37        CACHE STRING "Build type: Debug, Release, RelWithDebInfo or MinSizeRel"
     38              FORCE)
     39  endif()
     40 endif()
     41 
     42 if(MSVC AND MSVC_VERSION LESS 1920)
     43  message(
     44    WARNING
     45      "MSVC versions prior to 2019 (v16) are not supported and may generate"
     46      " incorrect code!")
     47 endif()
     48 
     49 # Library version info. Update LT_CURRENT, LT_REVISION and LT_AGE when making a
     50 # public release by following the guidelines in the libtool document:
     51 # https://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
     52 #
     53 # c=<current>, r=<revision>, a=<age>
     54 #
     55 # libtool generates a .so file as .so.[c-a].a.r, while -version-info c:r:a is
     56 # passed to libtool.
     57 #
     58 # We set SO_FILE_VERSION = [c-a].a.r
     59 #
     60 # The VERSION number in project() should be updated when these variables are.
     61 set(LT_CURRENT 16)
     62 set(LT_REVISION 1)
     63 set(LT_AGE 13)
     64 math(EXPR SO_VERSION "${LT_CURRENT} - ${LT_AGE}")
     65 set(SO_FILE_VERSION "${SO_VERSION}.${LT_AGE}.${LT_REVISION}")
     66 unset(LT_CURRENT)
     67 unset(LT_REVISION)
     68 unset(LT_AGE)
     69 
     70 # Enable generators like Xcode and Visual Studio to place projects in folders.
     71 set_property(GLOBAL PROPERTY USE_FOLDERS TRUE)
     72 
     73 include("${AOM_ROOT}/build/cmake/aom_configure.cmake")
     74 if(CONFIG_THREE_PASS)
     75  include("${AOM_ROOT}/common/ivf_dec.cmake")
     76 endif()
     77 include("${AOM_ROOT}/aom_dsp/aom_dsp.cmake")
     78 include("${AOM_ROOT}/aom_mem/aom_mem.cmake")
     79 include("${AOM_ROOT}/aom_ports/aom_ports.cmake")
     80 include("${AOM_ROOT}/aom_scale/aom_scale.cmake")
     81 include("${AOM_ROOT}/aom_util/aom_util.cmake")
     82 include("${AOM_ROOT}/av1/av1.cmake")
     83 include("${AOM_ROOT}/build/cmake/aom_install.cmake")
     84 include("${AOM_ROOT}/build/cmake/sanitizers.cmake")
     85 include("${AOM_ROOT}/build/cmake/util.cmake")
     86 include("${AOM_ROOT}/test/test.cmake")
     87 
     88 list(APPEND AOM_RTCD_SOURCES
     89            "${AOM_CONFIG_DIR}/config/aom_dsp_rtcd.h"
     90            "${AOM_CONFIG_DIR}/config/aom_scale_rtcd.h"
     91            "${AOM_CONFIG_DIR}/config/av1_rtcd.h"
     92            "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd_defs.pl"
     93            "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd.c"
     94            "${AOM_ROOT}/aom_scale/aom_scale_rtcd.pl"
     95            "${AOM_ROOT}/aom_scale/aom_scale_rtcd.c"
     96            "${AOM_ROOT}/av1/common/av1_rtcd_defs.pl"
     97            "${AOM_ROOT}/av1/common/av1_rtcd.c"
     98            "${AOM_ROOT}/build/cmake/rtcd.pl")
     99 
    100 list(APPEND AOM_LIBWEBM_SOURCES
    101            "${AOM_ROOT}/third_party/libwebm/common/hdr_util.cc"
    102            "${AOM_ROOT}/third_party/libwebm/common/hdr_util.h"
    103            "${AOM_ROOT}/third_party/libwebm/common/webmids.h"
    104            "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxer.cc"
    105            "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxer.h"
    106            "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxertypes.h"
    107            "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxerutil.cc"
    108            "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxerutil.h"
    109            "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvwriter.cc"
    110            "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvwriter.h"
    111            "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvparser.cc"
    112            "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvparser.h"
    113            "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvreader.cc"
    114            "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvreader.h")
    115 
    116 list(APPEND AOM_LIBYUV_SOURCES
    117            "${AOM_ROOT}/third_party/libyuv/include/libyuv/basic_types.h"
    118            "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert.h"
    119            "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert_argb.h"
    120            "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert_from.h"
    121            "${AOM_ROOT}/third_party/libyuv/include/libyuv/cpu_id.h"
    122            "${AOM_ROOT}/third_party/libyuv/include/libyuv/planar_functions.h"
    123            "${AOM_ROOT}/third_party/libyuv/include/libyuv/rotate.h"
    124            "${AOM_ROOT}/third_party/libyuv/include/libyuv/row.h"
    125            "${AOM_ROOT}/third_party/libyuv/include/libyuv/scale.h"
    126            "${AOM_ROOT}/third_party/libyuv/include/libyuv/scale_row.h"
    127            "${AOM_ROOT}/third_party/libyuv/source/convert_argb.cc"
    128            "${AOM_ROOT}/third_party/libyuv/source/cpu_id.cc"
    129            "${AOM_ROOT}/third_party/libyuv/source/planar_functions.cc"
    130            "${AOM_ROOT}/third_party/libyuv/source/row_any.cc"
    131            "${AOM_ROOT}/third_party/libyuv/source/row_common.cc"
    132            "${AOM_ROOT}/third_party/libyuv/source/row_gcc.cc"
    133            "${AOM_ROOT}/third_party/libyuv/source/row_mips.cc"
    134            "${AOM_ROOT}/third_party/libyuv/source/row_neon.cc"
    135            "${AOM_ROOT}/third_party/libyuv/source/row_neon64.cc"
    136            "${AOM_ROOT}/third_party/libyuv/source/row_win.cc"
    137            "${AOM_ROOT}/third_party/libyuv/source/scale.cc"
    138            "${AOM_ROOT}/third_party/libyuv/source/scale_any.cc"
    139            "${AOM_ROOT}/third_party/libyuv/source/scale_common.cc"
    140            "${AOM_ROOT}/third_party/libyuv/source/scale_gcc.cc"
    141            "${AOM_ROOT}/third_party/libyuv/source/scale_mips.cc"
    142            "${AOM_ROOT}/third_party/libyuv/source/scale_neon.cc"
    143            "${AOM_ROOT}/third_party/libyuv/source/scale_neon64.cc"
    144            "${AOM_ROOT}/third_party/libyuv/source/scale_win.cc"
    145            "${AOM_ROOT}/third_party/libyuv/source/scale_uv.cc")
    146 
    147 list(APPEND AOM_SOURCES
    148            "${AOM_CONFIG_DIR}/config/aom_config.c"
    149            "${AOM_CONFIG_DIR}/config/aom_config.h"
    150            "${AOM_ROOT}/aom/aom.h"
    151            "${AOM_ROOT}/aom/aom_codec.h"
    152            "${AOM_ROOT}/aom/aom_decoder.h"
    153            "${AOM_ROOT}/aom/aom_encoder.h"
    154            "${AOM_ROOT}/aom/aom_external_partition.h"
    155            "${AOM_ROOT}/aom/aom_frame_buffer.h"
    156            "${AOM_ROOT}/aom/aom_image.h"
    157            "${AOM_ROOT}/aom/aom_integer.h"
    158            "${AOM_ROOT}/aom/aomcx.h"
    159            "${AOM_ROOT}/aom/aomdx.h"
    160            "${AOM_ROOT}/aom/internal/aom_codec_internal.h"
    161            "${AOM_ROOT}/aom/internal/aom_image_internal.h"
    162            "${AOM_ROOT}/aom/src/aom_codec.c"
    163            "${AOM_ROOT}/aom/src/aom_decoder.c"
    164            "${AOM_ROOT}/aom/src/aom_encoder.c"
    165            "${AOM_ROOT}/aom/src/aom_image.c"
    166            "${AOM_ROOT}/aom/src/aom_integer.c")
    167 
    168 list(APPEND AOM_COMMON_APP_UTIL_SOURCES
    169            "${AOM_ROOT}/av1/arg_defs.c"
    170            "${AOM_ROOT}/av1/arg_defs.h"
    171            "${AOM_ROOT}/common/args_helper.c"
    172            "${AOM_ROOT}/common/args_helper.h"
    173            "${AOM_ROOT}/common/args.c"
    174            "${AOM_ROOT}/common/args.h"
    175            "${AOM_ROOT}/common/av1_config.c"
    176            "${AOM_ROOT}/common/av1_config.h"
    177            "${AOM_ROOT}/common/md5_utils.c"
    178            "${AOM_ROOT}/common/md5_utils.h"
    179            "${AOM_ROOT}/common/tools_common.c"
    180            "${AOM_ROOT}/common/tools_common.h"
    181            "${AOM_ROOT}/common/video_common.h"
    182            "${AOM_ROOT}/common/rawenc.c"
    183            "${AOM_ROOT}/common/rawenc.h"
    184            "${AOM_ROOT}/common/y4menc.c"
    185            "${AOM_ROOT}/common/y4menc.h"
    186            "${AOM_ROOT}/common/ivfdec.c"
    187            "${AOM_ROOT}/common/ivfdec.h")
    188 
    189 list(APPEND AOM_DECODER_APP_UTIL_SOURCES "${AOM_ROOT}/common/obudec.c"
    190            "${AOM_ROOT}/common/obudec.h" "${AOM_ROOT}/common/video_reader.c"
    191            "${AOM_ROOT}/common/video_reader.h")
    192 
    193 list(APPEND AOM_ENCODER_APP_UTIL_SOURCES
    194            "${AOM_ROOT}/common/ivfenc.c"
    195            "${AOM_ROOT}/common/ivfenc.h"
    196            "${AOM_ROOT}/common/video_writer.c"
    197            "${AOM_ROOT}/common/video_writer.h"
    198            "${AOM_ROOT}/common/warnings.c"
    199            "${AOM_ROOT}/common/warnings.h"
    200            "${AOM_ROOT}/common/y4minput.c"
    201            "${AOM_ROOT}/common/y4minput.h"
    202            "${AOM_ROOT}/examples/encoder_util.h"
    203            "${AOM_ROOT}/examples/encoder_util.c"
    204            "${AOM_ROOT}/examples/multilayer_metadata.h"
    205            "${AOM_ROOT}/examples/multilayer_metadata.cc")
    206 
    207 list(APPEND AOM_ENCODER_STATS_SOURCES "${AOM_ROOT}/stats/aomstats.c"
    208            "${AOM_ROOT}/stats/aomstats.h" "${AOM_ROOT}/stats/rate_hist.c"
    209            "${AOM_ROOT}/stats/rate_hist.h")
    210 
    211 list(APPEND AOM_VERSION_SOURCES "${AOM_CONFIG_DIR}/config/aom_version.h")
    212 
    213 list(APPEND AOM_WEBM_DECODER_SOURCES "${AOM_ROOT}/common/webmdec.cc"
    214            "${AOM_ROOT}/common/webmdec.h")
    215 
    216 list(APPEND AOM_WEBM_ENCODER_SOURCES "${AOM_ROOT}/common/webmenc.cc"
    217            "${AOM_ROOT}/common/webmenc.h")
    218 
    219 include_directories(${AOM_ROOT} ${AOM_CONFIG_DIR} ${AOM_ROOT}/apps
    220                    ${AOM_ROOT}/common ${AOM_ROOT}/examples ${AOM_ROOT}/stats)
    221 
    222 # Targets
    223 add_library(aom_version ${AOM_VERSION_SOURCES})
    224 add_no_op_source_file_to_target(aom_version c)
    225 add_custom_command(OUTPUT "${AOM_CONFIG_DIR}/config/aom_version.h"
    226                   COMMAND ${CMAKE_COMMAND} ARGS
    227                           -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
    228                           -DAOM_ROOT=${AOM_ROOT}
    229                           -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
    230                           -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
    231                           "${AOM_ROOT}/build/cmake/version.cmake"
    232                   COMMENT "Writing aom_version.h"
    233                   VERBATIM)
    234 
    235 add_custom_target(aom_version_check
    236                  COMMAND ${CMAKE_COMMAND}
    237                          -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
    238                          -DAOM_ROOT=${AOM_ROOT}
    239                          -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
    240                          -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
    241                          "${AOM_ROOT}/build/cmake/version.cmake"
    242                  COMMENT "Updating version info if necessary."
    243                  VERBATIM)
    244 
    245 if(BUILD_SHARED_LIBS AND NOT MSVC)
    246  # Generate version file immediately for non-MSVC shared builds: The version
    247  # string is needed for the aom target.
    248  execute_process(COMMAND ${CMAKE_COMMAND}
    249                          -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
    250                          -DAOM_ROOT=${AOM_ROOT}
    251                          -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
    252                          -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
    253                          "${AOM_ROOT}/build/cmake/version.cmake")
    254 endif()
    255 
    256 add_dependencies(aom_version aom_version_check)
    257 
    258 # TODO(tomfinegan): Move rtcd target setup where it belongs for each rtcd
    259 # source.
    260 add_rtcd_build_step("${AOM_ROOT}/aom_dsp/aom_dsp_rtcd_defs.pl"
    261                    "${AOM_CONFIG_DIR}/config/aom_dsp_rtcd.h"
    262                    "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd.c" "aom_dsp_rtcd")
    263 add_rtcd_build_step("${AOM_ROOT}/aom_scale/aom_scale_rtcd.pl"
    264                    "${AOM_CONFIG_DIR}/config/aom_scale_rtcd.h"
    265                    "${AOM_ROOT}/aom_scale/aom_scale_rtcd.c" "aom_scale_rtcd")
    266 add_rtcd_build_step("${AOM_ROOT}/av1/common/av1_rtcd_defs.pl"
    267                    "${AOM_CONFIG_DIR}/config/av1_rtcd.h"
    268                    "${AOM_ROOT}/av1/common/av1_rtcd.c" "av1_rtcd")
    269 
    270 add_library(aom_rtcd OBJECT ${AOM_RTCD_SOURCES})
    271 add_dependencies(aom_rtcd aom_version)
    272 
    273 if(CONFIG_HIGHWAY)
    274  list(APPEND AOM_HIGHWAY_SOURCES
    275              "${AOM_ROOT}/third_party/highway/hwy/abort.h"
    276              "${AOM_ROOT}/third_party/highway/hwy/aligned_allocator.h"
    277              "${AOM_ROOT}/third_party/highway/hwy/base.h"
    278              "${AOM_ROOT}/third_party/highway/hwy/cache_control.h"
    279              "${AOM_ROOT}/third_party/highway/hwy/per_target.h"
    280              "${AOM_ROOT}/third_party/highway/hwy/print.h"
    281              "${AOM_ROOT}/third_party/highway/hwy/foreach_target.h"
    282              "${AOM_ROOT}/third_party/highway/hwy/highway_export.h"
    283              "${AOM_ROOT}/third_party/highway/hwy/highway.h"
    284              "${AOM_ROOT}/third_party/highway/hwy/print-inl.h"
    285              "${AOM_ROOT}/third_party/highway/hwy/timer-inl.h"
    286              "${AOM_ROOT}/third_party/highway/hwy/detect_compiler_arch.h"
    287              "${AOM_ROOT}/third_party/highway/hwy/detect_targets.h"
    288              "${AOM_ROOT}/third_party/highway/hwy/targets.h"
    289              "${AOM_ROOT}/third_party/highway/hwy/ops/arm_neon-inl.h"
    290              "${AOM_ROOT}/third_party/highway/hwy/ops/arm_sve-inl.h"
    291              "${AOM_ROOT}/third_party/highway/hwy/ops/emu128-inl.h"
    292              "${AOM_ROOT}/third_party/highway/hwy/ops/generic_ops-inl.h"
    293              "${AOM_ROOT}/third_party/highway/hwy/ops/scalar-inl.h"
    294              "${AOM_ROOT}/third_party/highway/hwy/ops/set_macros-inl.h"
    295              "${AOM_ROOT}/third_party/highway/hwy/ops/shared-inl.h"
    296              "${AOM_ROOT}/third_party/highway/hwy/ops/x86_128-inl.h"
    297              "${AOM_ROOT}/third_party/highway/hwy/ops/x86_256-inl.h"
    298              "${AOM_ROOT}/third_party/highway/hwy/ops/x86_512-inl.h"
    299              "${AOM_ROOT}/third_party/highway/hwy/ops/x86_avx3-inl.h"
    300              "${AOM_ROOT}/third_party/highway/hwy/contrib/algo/copy-inl.h"
    301              "${AOM_ROOT}/third_party/highway/hwy/contrib/algo/find-inl.h"
    302              "${AOM_ROOT}/third_party/highway/hwy/contrib/algo/transform-inl.h"
    303              "${AOM_ROOT}/third_party/highway/hwy/contrib/dot/dot-inl.h"
    304              "${AOM_ROOT}/third_party/highway/hwy/contrib/image/image.h"
    305              "${AOM_ROOT}/third_party/highway/hwy/contrib/math/math-inl.h")
    306  add_definitions(-DHWY_HEADER_ONLY)
    307  add_library(aom_hwy OBJECT ${AOM_HIGHWAY_SOURCES})
    308  set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_hwy)
    309 endif()
    310 
    311 if(ENABLE_EXAMPLES)
    312  add_library(aom_encoder_stats OBJECT ${AOM_ENCODER_STATS_SOURCES})
    313  set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_encoder_stats)
    314 endif()
    315 
    316 # Xcode generator cannot take a library composed solely of objects. See
    317 # https://gitlab.kitware.com/cmake/cmake/-/issues/17500
    318 if(XCODE)
    319  set(target_objs_aom ${AOM_SOURCES})
    320 else()
    321  add_library(aom_obj OBJECT ${AOM_SOURCES})
    322  set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_obj)
    323  set(target_objs_aom $<TARGET_OBJECTS:aom_obj>)
    324 endif()
    325 add_library(aom ${target_objs_aom} $<TARGET_OBJECTS:aom_rtcd>)
    326 target_include_directories(aom PUBLIC $<INSTALL_INTERFACE:include>)
    327 
    328 if(BUILD_SHARED_LIBS)
    329  add_library(aom_static STATIC ${target_objs_aom} $<TARGET_OBJECTS:aom_rtcd>)
    330  target_include_directories(aom_static PUBLIC $<INSTALL_INTERFACE:include>)
    331  set_target_properties(aom_static PROPERTIES OUTPUT_NAME aom)
    332  if(MSVC OR (WIN32 AND NOT MINGW))
    333    # Fix race condition between the import library and the static library.
    334    # Affects MSVC in all three flavors (stock, clang-cl, LLVM -- the latter
    335    # sets MSVC and MINGW both to FALSE).
    336    set_target_properties(aom PROPERTIES ARCHIVE_OUTPUT_NAME "aom_dll")
    337  endif()
    338 
    339  if(NOT MSVC)
    340    # Extract version string and set VERSION/SOVERSION for the aom target.
    341    extract_version_string("${AOM_CONFIG_DIR}/config/aom_version.h"
    342                           aom_version_triple)
    343 
    344    # Strip any trailing version information, if present.
    345    string(FIND "${aom_version_triple}" "-" dash_pos)
    346    if(NOT dash_pos EQUAL -1)
    347      string(SUBSTRING "${aom_version_triple}" 0 ${dash_pos} aom_version_triple)
    348    endif()
    349 
    350    # cmake-format: off
    351    # VERSION is embedded in the .so file name.
    352    # libaom.so -> libaom.so.SOVERSION
    353    # libaom.so.SOVERSION -> libaom.so.VERSION
    354    # libaom.so.VERSION
    355    # cmake-format: on
    356    set_target_properties(aom PROPERTIES SOVERSION ${SO_VERSION})
    357    set_target_properties(aom PROPERTIES VERSION ${SO_FILE_VERSION})
    358  endif()
    359 endif()
    360 
    361 if(NOT WIN32 AND NOT APPLE)
    362  target_link_libraries(aom ${AOM_LIB_LINK_TYPE} m)
    363  if(BUILD_SHARED_LIBS)
    364    target_link_libraries(aom_static ${AOM_LIB_LINK_TYPE} m)
    365  endif()
    366 endif()
    367 
    368 if(CONFIG_AV1_ENCODER)
    369  list(APPEND AOM_AV1_RC_SOURCES "${AOM_ROOT}/av1/ratectrl_rtc.h"
    370              "${AOM_ROOT}/av1/ratectrl_rtc.cc")
    371  add_library(aom_av1_rc ${AOM_AV1_RC_SOURCES})
    372  # aom_av1_rc calls libaom's internal functions, so it must be linked with the
    373  # libaom static library.
    374  if(BUILD_SHARED_LIBS)
    375    target_link_libraries(aom_av1_rc ${AOM_LIB_LINK_TYPE} aom_static)
    376    # TODO: https://aomedia.issues.chromium.org/391715078 - This condition can
    377    # be removed after aom_av1_rc restricts its symbol visibility.
    378    if(CYGWIN OR MINGW)
    379      target_link_options(aom_av1_rc ${AOM_LIB_LINK_TYPE}
    380                          LINKER:--allow-multiple-definition)
    381    endif()
    382  else()
    383    target_link_libraries(aom_av1_rc ${AOM_LIB_LINK_TYPE} aom)
    384  endif()
    385  if(BUILD_SHARED_LIBS)
    386    # On Windows, global symbols are not exported from a DLL by default. Enable
    387    # the WINDOWS_EXPORT_ALL_SYMBOLS property to export all global symbols from
    388    # the aom_av1_rc DLL on Windows, to match the default behavior on other
    389    # platforms.
    390    set_target_properties(aom_av1_rc PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
    391    # The aom_av1_rc library and its header "av1/ratectrl_rtc.h" are not
    392    # installed by the "install" command, so we don't need to worry about
    393    # versioning the aom_av1_rc shared library. If we start to install the
    394    # aom_av1_rc library, the library should be versioned.
    395  endif()
    396  if(NOT WIN32 AND NOT APPLE)
    397    target_link_libraries(aom_av1_rc ${AOM_LIB_LINK_TYPE} m)
    398  endif()
    399  set_target_properties(aom_av1_rc PROPERTIES LINKER_LANGUAGE CXX)
    400 endif()
    401 
    402 # List of object and static library targets.
    403 set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_rtcd aom_mem aom_scale aom)
    404 if(CONFIG_AV1_ENCODER)
    405  set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_av1_rc)
    406 endif()
    407 if(BUILD_SHARED_LIBS)
    408  set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_static)
    409 endif()
    410 
    411 # Setup dependencies.
    412 if(CONFIG_THREE_PASS)
    413  setup_ivf_dec_targets()
    414 endif()
    415 setup_aom_dsp_targets()
    416 setup_aom_mem_targets()
    417 setup_aom_ports_targets()
    418 setup_aom_util_targets()
    419 setup_aom_scale_targets()
    420 setup_av1_targets()
    421 
    422 # Make all library targets depend on aom_rtcd to make sure it builds first.
    423 foreach(aom_lib ${AOM_LIB_TARGETS})
    424  if(NOT "${aom_lib}" STREQUAL "aom_rtcd")
    425    add_dependencies(${aom_lib} aom_rtcd)
    426  endif()
    427 endforeach()
    428 
    429 # Generate a C file containing the function usage_exit(). Users of the
    430 # aom_common_app_util library must define this function. This is a convenience
    431 # to allow omission of the function from applications that might want to use
    432 # other pieces of the util support without defining usage_exit().
    433 file(WRITE "${AOM_GEN_SRC_DIR}/usage_exit.c"
    434     "#include <stdlib.h>\n\n#include \"common/tools_common.h\"\n\n"
    435     "void usage_exit(void) { exit(EXIT_FAILURE); }\n")
    436 
    437 #
    438 # Application and application support targets.
    439 #
    440 if(ENABLE_EXAMPLES OR ENABLE_TESTS OR ENABLE_TOOLS)
    441  add_library(aom_common_app_util OBJECT ${AOM_COMMON_APP_UTIL_SOURCES})
    442  add_library(aom_usage_exit OBJECT "${AOM_GEN_SRC_DIR}/usage_exit.c")
    443  set_property(TARGET ${example} PROPERTY FOLDER examples)
    444  if(CONFIG_AV1_DECODER)
    445    add_library(aom_decoder_app_util OBJECT ${AOM_DECODER_APP_UTIL_SOURCES})
    446    set_property(TARGET ${example} PROPERTY FOLDER examples)
    447    # obudec depends on internal headers that require *rtcd.h
    448    add_dependencies(aom_decoder_app_util aom_rtcd)
    449  endif()
    450  if(CONFIG_AV1_ENCODER)
    451    add_library(aom_encoder_app_util OBJECT ${AOM_ENCODER_APP_UTIL_SOURCES})
    452    set_property(TARGET ${example} PROPERTY FOLDER examples)
    453  endif()
    454 endif()
    455 
    456 if(CONFIG_AV1_DECODER AND ENABLE_EXAMPLES)
    457  add_executable(aomdec "${AOM_ROOT}/apps/aomdec.c"
    458                        $<TARGET_OBJECTS:aom_common_app_util>
    459                        $<TARGET_OBJECTS:aom_decoder_app_util>)
    460  add_executable(decode_to_md5 "${AOM_ROOT}/examples/decode_to_md5.c"
    461                               $<TARGET_OBJECTS:aom_common_app_util>
    462                               $<TARGET_OBJECTS:aom_decoder_app_util>)
    463  add_executable(decode_with_drops "${AOM_ROOT}/examples/decode_with_drops.c"
    464                                   $<TARGET_OBJECTS:aom_common_app_util>
    465                                   $<TARGET_OBJECTS:aom_decoder_app_util>)
    466  add_executable(simple_decoder "${AOM_ROOT}/examples/simple_decoder.c"
    467                                $<TARGET_OBJECTS:aom_common_app_util>
    468                                $<TARGET_OBJECTS:aom_decoder_app_util>)
    469  add_executable(scalable_decoder "${AOM_ROOT}/examples/scalable_decoder.c"
    470                                  $<TARGET_OBJECTS:aom_common_app_util>
    471                                  $<TARGET_OBJECTS:aom_decoder_app_util>)
    472 
    473  if(CONFIG_ANALYZER)
    474    add_executable(analyzer "${AOM_ROOT}/examples/analyzer.cc"
    475                            $<TARGET_OBJECTS:aom_common_app_util>
    476                            $<TARGET_OBJECTS:aom_decoder_app_util>)
    477    target_link_libraries(analyzer ${AOM_LIB_LINK_TYPE} ${wxWidgets_LIBRARIES})
    478    list(APPEND AOM_APP_TARGETS analyzer)
    479    list(APPEND AOM_DECODER_EXAMPLE_TARGETS analyzer)
    480  endif()
    481 
    482  if(CONFIG_INSPECTION)
    483    add_executable(inspect "${AOM_ROOT}/examples/inspect.c"
    484                           $<TARGET_OBJECTS:aom_common_app_util>
    485                           $<TARGET_OBJECTS:aom_decoder_app_util>)
    486    list(APPEND AOM_DECODER_EXAMPLE_TARGETS inspect)
    487 
    488    if(EMSCRIPTEN)
    489      add_preproc_definition(_POSIX_SOURCE)
    490      append_link_flag_to_target("inspect" "--emrun")
    491      append_link_flag_to_target("inspect" "-s USE_PTHREADS=0")
    492      append_link_flag_to_target("inspect" "-s WASM=1")
    493      append_link_flag_to_target("inspect" "-s MODULARIZE=1")
    494      append_link_flag_to_target("inspect" "-s ALLOW_MEMORY_GROWTH=1")
    495      append_link_flag_to_target(
    496        "inspect" "-s \'EXTRA_EXPORTED_RUNTIME_METHODS=[\"UTF8ToString\"]\'")
    497      append_link_flag_to_target("inspect"
    498                                 "-s EXPORT_NAME=\"\'DecoderModule\'\"")
    499      append_link_flag_to_target("inspect" "--memory-init-file 0")
    500 
    501      if("${CMAKE_BUILD_TYPE}" STREQUAL "")
    502 
    503        # Default to -O3 when no build type is specified.
    504        append_compiler_flag("-O3")
    505      endif()
    506 
    507      em_link_post_js(inspect "${AOM_ROOT}/tools/inspect-post.js")
    508    endif()
    509  endif()
    510 
    511  # Maintain a list of decoder example targets.
    512  list(APPEND AOM_DECODER_EXAMPLE_TARGETS aomdec decode_to_md5 decode_with_drops
    513              scalable_decoder simple_decoder)
    514 
    515  # Add decoder examples to the app targets list.
    516  list(APPEND AOM_APP_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS})
    517 endif()
    518 
    519 if(CONFIG_LIBYUV OR CONFIG_TUNE_BUTTERAUGLI)
    520  add_library(yuv OBJECT ${AOM_LIBYUV_SOURCES})
    521  if(NOT MSVC)
    522    target_compile_options(yuv PRIVATE -Wno-shadow)
    523    # Many functions in libyuv trigger this warning when enabled with gcc and
    524    # clang.
    525    is_flag_present(AOM_CXX_FLAGS "-Wmissing-declarations" flag_present)
    526    if(flag_present)
    527      target_compile_options(yuv PRIVATE -Wno-missing-declarations)
    528    endif()
    529    # Many functions in libyuv trigger this warning when enabled with clang.
    530    is_flag_present(AOM_CXX_FLAGS "-Wmissing-prototypes" flag_present)
    531    if(flag_present)
    532      target_compile_options(yuv PRIVATE -Wno-missing-prototypes)
    533    endif()
    534  endif()
    535  include_directories("${AOM_ROOT}/third_party/libyuv/include")
    536 endif()
    537 
    538 if(CONFIG_AV1_ENCODER)
    539  if(ENABLE_EXAMPLES)
    540    add_executable(aomenc "${AOM_ROOT}/apps/aomenc.c"
    541                          $<TARGET_OBJECTS:aom_common_app_util>
    542                          $<TARGET_OBJECTS:aom_encoder_app_util>
    543                          $<TARGET_OBJECTS:aom_encoder_stats>)
    544    add_executable(lossless_encoder "${AOM_ROOT}/examples/lossless_encoder.c"
    545                                    $<TARGET_OBJECTS:aom_common_app_util>
    546                                    $<TARGET_OBJECTS:aom_encoder_app_util>)
    547    add_executable(set_maps "${AOM_ROOT}/examples/set_maps.c"
    548                            $<TARGET_OBJECTS:aom_common_app_util>
    549                            $<TARGET_OBJECTS:aom_encoder_app_util>)
    550    add_executable(simple_encoder "${AOM_ROOT}/examples/simple_encoder.c"
    551                                  $<TARGET_OBJECTS:aom_common_app_util>
    552                                  $<TARGET_OBJECTS:aom_encoder_app_util>)
    553    add_executable(twopass_encoder "${AOM_ROOT}/examples/twopass_encoder.c"
    554                                   $<TARGET_OBJECTS:aom_common_app_util>
    555                                   $<TARGET_OBJECTS:aom_encoder_app_util>)
    556    if(NOT BUILD_SHARED_LIBS AND NOT CONFIG_REALTIME_ONLY)
    557      add_executable(noise_model "${AOM_ROOT}/examples/noise_model.c"
    558                                 $<TARGET_OBJECTS:aom_common_app_util>
    559                                 $<TARGET_OBJECTS:aom_encoder_app_util>)
    560      add_executable(photon_noise_table
    561                     "${AOM_ROOT}/examples/photon_noise_table.c"
    562                     $<TARGET_OBJECTS:aom_common_app_util>
    563                     $<TARGET_OBJECTS:aom_encoder_app_util>)
    564    endif()
    565    add_executable(scalable_encoder "${AOM_ROOT}/examples/scalable_encoder.c"
    566                                    $<TARGET_OBJECTS:aom_common_app_util>
    567                                    $<TARGET_OBJECTS:aom_encoder_app_util>)
    568    add_executable(svc_encoder_rtc "${AOM_ROOT}/examples/svc_encoder_rtc.cc"
    569                                   $<TARGET_OBJECTS:aom_common_app_util>
    570                                   $<TARGET_OBJECTS:aom_encoder_app_util>)
    571    target_link_libraries(svc_encoder_rtc ${AOM_LIB_LINK_TYPE} aom_av1_rc)
    572 
    573    # Maintain a list of encoder example targets.
    574    list(APPEND AOM_ENCODER_EXAMPLE_TARGETS aomenc lossless_encoder set_maps
    575                simple_encoder scalable_encoder svc_encoder_rtc twopass_encoder)
    576    if(NOT BUILD_SHARED_LIBS AND NOT CONFIG_REALTIME_ONLY)
    577      list(APPEND AOM_ENCODER_EXAMPLE_TARGETS noise_model photon_noise_table)
    578    endif()
    579 
    580  endif()
    581 
    582  if(ENABLE_TOOLS)
    583    if(CONFIG_ENTROPY_STATS AND NOT BUILD_SHARED_LIBS)
    584 
    585      # TODO(tomfinegan): Sort out why a simple link command with
    586      # aom_entropy_optimizer.c won't work on macos, but dragging in all the
    587      # helper machinery allows the link to succeed.
    588      add_executable(aom_entropy_optimizer
    589                     "${AOM_ROOT}/tools/aom_entropy_optimizer.c"
    590                     $<TARGET_OBJECTS:aom_common_app_util>
    591                     $<TARGET_OBJECTS:aom_encoder_app_util>
    592                     $<TARGET_OBJECTS:aom_usage_exit>)
    593 
    594      # Maintain a list of encoder tool targets.
    595      list(APPEND AOM_ENCODER_TOOL_TARGETS aom_entropy_optimizer)
    596    endif()
    597  endif()
    598 
    599  # Add encoder examples and tools to the targets list.
    600  list(APPEND AOM_APP_TARGETS ${AOM_ENCODER_EXAMPLE_TARGETS}
    601              ${AOM_ENCODER_TOOL_TARGETS})
    602 
    603  if(CONFIG_TUNE_BUTTERAUGLI)
    604    find_package(PkgConfig)
    605    # Use find_library() with STATIC_LINK_JXL for static build since
    606    # pkg_check_modules() with LIBJXL_STATIC is not working.
    607    if(STATIC_LINK_JXL OR NOT PKG_CONFIG_FOUND)
    608      find_library(LIBJXL_LIBRARIES libjxl.a)
    609      find_library(LIBHWY_LIBRARIES libhwy.a)
    610      find_library(LIBSKCMS_LIBRARIES libskcms.a)
    611      find_library(LIBBROTLICOMMON_LIBRARIES libbrotlicommon-static.a)
    612      find_library(LIBBROTLIENC_LIBRARIES libbrotlienc-static.a)
    613      find_library(LIBBROTLIDEC_LIBRARIES libbrotlidec-static.a)
    614      find_path(LIBJXL_INCLUDE_DIRS butteraugli.h PATH_SUFFIXES jxl)
    615      if(LIBJXL_LIBRARIES
    616         AND LIBHWY_LIBRARIES
    617         AND LIBSKCMS_LIBRARIES
    618         AND LIBBROTLICOMMON_LIBRARIES
    619         AND LIBBROTLIENC_LIBRARIES
    620         AND LIBBROTLIDEC_LIBRARIES
    621         AND LIBJXL_INCLUDE_DIRS)
    622        message(STATUS "Found JXL library: ${LIBJXL_LIBRARIES} "
    623                       "${LIBHWY_LIBRARIES} ${LIBSKCMS_LIBRARIES} "
    624                       "${LIBBROTLICOMMON_LIBRARIES} ${LIBBROTLIENC_LIBRARIES}"
    625                       "${LIBBROTLIDEC_LIBRARIES}")
    626        message(STATUS "Found JXL include: ${LIBJXL_INCLUDE_DIRS}")
    627      else()
    628        message(FATAL_ERROR "JXL library not found.")
    629      endif()
    630      target_link_libraries(aom
    631                            PRIVATE ${LIBJXL_LIBRARIES} ${LIBHWY_LIBRARIES}
    632                                    ${LIBSKCMS_LIBRARIES}
    633                                    ${LIBBROTLIENC_LIBRARIES}
    634                                    ${LIBBROTLIDEC_LIBRARIES}
    635                                    ${LIBBROTLICOMMON_LIBRARIES})
    636      target_include_directories(aom_dsp_encoder PRIVATE ${LIBJXL_INCLUDE_DIRS})
    637    else()
    638      pkg_check_modules(LIBJXL REQUIRED libjxl)
    639      target_link_libraries(aom PRIVATE ${LIBJXL_LDFLAGS})
    640      target_include_directories(aom_dsp_encoder PRIVATE ${LIBJXL_INCLUDE_DIRS})
    641      if(LIBJXL_CFLAGS)
    642        append_compiler_flag("${LIBJXL_CFLAGS}")
    643      endif()
    644      pkg_check_modules(LIBHWY REQUIRED libhwy)
    645      target_link_libraries(aom PRIVATE ${LIBHWY_LDFLAGS})
    646      target_include_directories(aom_dsp_encoder
    647                                 PRIVATE ${LIBLIBHWY_INCLUDE_DIRS})
    648      if(LIBHWY_CFLAGS)
    649        append_compiler_flag("${LIBHWY_CFLAGS}")
    650      endif()
    651    endif()
    652 
    653    set_target_properties(aom PROPERTIES LINKER_LANGUAGE CXX)
    654    if(BUILD_SHARED_LIBS)
    655      set_target_properties(aom_static PROPERTIES LINKER_LANGUAGE CXX)
    656    endif()
    657 
    658    list(APPEND AOM_LIB_TARGETS yuv)
    659    target_sources(aom PRIVATE $<TARGET_OBJECTS:yuv>)
    660    if(BUILD_SHARED_LIBS)
    661      target_sources(aom_static PRIVATE $<TARGET_OBJECTS:yuv>)
    662    endif()
    663  endif()
    664 
    665  if(CONFIG_TFLITE)
    666    include(FetchContent)
    667 
    668    set(TFLITE_TAG "v2.6.1")
    669 
    670    message(STATUS "Fetching TFLite ${TFLITE_TAG}...")
    671 
    672    # static linking makes life with TFLite much easier
    673    set(TFLITE_C_BUILD_SHARED_LIBS OFF)
    674 
    675    # We don't care about comparing against these delegates (yet), and disabling
    676    # it reduces compile time meaningfully
    677    set(TFLITE_ENABLE_RUY OFF)
    678    set(TFLITE_ENABLE_XNNPACK OFF)
    679 
    680    fetchcontent_declare(tflite
    681                         GIT_REPOSITORY https://github.com/tensorflow/tensorflow
    682                         GIT_TAG ${TFLITE_TAG}
    683                         GIT_SHALLOW TRUE)
    684 
    685    fetchcontent_getproperties(tflite)
    686    if(NOT tflite_POPULATED)
    687      fetchcontent_populate(tflite)
    688      # Some of the subprojects (e.g. Eigen) are very noisy and emit status
    689      # messages all the time. Temporary ignore status messages while adding
    690      # this to silence it. Ugly but effective.
    691      set(OLD_CMAKE_MESSAGE_LOG_LEVEL ${CMAKE_MESSAGE_LOG_LEVEL})
    692      set(CMAKE_MESSAGE_LOG_LEVEL WARNING)
    693      add_subdirectory(${tflite_SOURCE_DIR}/tensorflow/lite/c
    694                       ${tflite_BINARY_DIR})
    695      set(CMAKE_MESSAGE_LOG_LEVEL ${OLD_CMAKE_MESSAGE_LOG_LEVEL})
    696    endif()
    697 
    698    # Disable some noisy warnings in tflite
    699    target_compile_options(tensorflow-lite PRIVATE -w)
    700 
    701    # tensorflowlite_c is implicitly declared by this FetchContent
    702    include_directories(${tflite_SOURCE_DIR})
    703    target_link_libraries(aom PRIVATE tensorflow-lite)
    704  endif()
    705 
    706  if(CONFIG_TUNE_VMAF)
    707    find_package(PkgConfig)
    708    if(PKG_CONFIG_FOUND)
    709      pkg_check_modules(VMAF REQUIRED libvmaf)
    710      if(BUILD_SHARED_LIBS)
    711        target_link_libraries(aom_static PRIVATE ${VMAF_LDFLAGS})
    712      endif()
    713      target_link_libraries(aom PRIVATE ${VMAF_LDFLAGS})
    714      target_include_directories(aom_dsp_encoder PRIVATE ${VMAF_INCLUDE_DIRS})
    715      if(VMAF_CFLAGS)
    716        foreach(flag "${VMAF_CFLAGS}")
    717          append_compiler_flag("${flag}")
    718        endforeach()
    719      endif()
    720    else()
    721      message(FATAL_ERROR "CONFIG_TUNE_VMAF error: pkg-config not found.")
    722    endif()
    723    set_target_properties(aom PROPERTIES LINKER_LANGUAGE CXX)
    724    if(BUILD_SHARED_LIBS)
    725      set_target_properties(aom_static PROPERTIES LINKER_LANGUAGE CXX)
    726    endif()
    727  endif()
    728 endif()
    729 
    730 if(ENABLE_EXAMPLES)
    731 
    732  # Maintain a separate variable listing only the examples to facilitate
    733  # installation of example programs into an examples sub directory of
    734  # $AOM_DIST_DIR/bin when building the dist target.
    735  list(APPEND AOM_EXAMPLE_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS}
    736              ${AOM_ENCODER_EXAMPLE_TARGETS})
    737 endif()
    738 
    739 if(ENABLE_TOOLS)
    740  if(CONFIG_AV1_DECODER)
    741    add_executable(dump_obu "${AOM_ROOT}/tools/dump_obu.cc"
    742                            "${AOM_ROOT}/tools/obu_parser.cc"
    743                            "${AOM_ROOT}/tools/obu_parser.h"
    744                            $<TARGET_OBJECTS:aom_common_app_util>
    745                            $<TARGET_OBJECTS:aom_decoder_app_util>
    746                            $<TARGET_OBJECTS:aom_usage_exit>)
    747 
    748    list(APPEND AOM_TOOL_TARGETS dump_obu)
    749    list(APPEND AOM_APP_TARGETS dump_obu)
    750 
    751    # Maintain a separate variable listing only the examples to facilitate
    752    # installation of example programs into an tools sub directory of
    753    # $AOM_DIST_DIR/bin when building the dist target.
    754    list(APPEND AOM_TOOL_TARGETS ${AOM_DECODER_TOOL_TARGETS}
    755                ${AOM_ENCODER_TOOL_TARGETS})
    756  endif()
    757 endif()
    758 
    759 if(ENABLE_EXAMPLES AND CONFIG_AV1_DECODER AND CONFIG_AV1_ENCODER)
    760  add_executable(aom_cx_set_ref "${AOM_ROOT}/examples/aom_cx_set_ref.c"
    761                                $<TARGET_OBJECTS:aom_common_app_util>
    762                                $<TARGET_OBJECTS:aom_encoder_app_util>)
    763  list(APPEND AOM_EXAMPLE_TARGETS aom_cx_set_ref)
    764  list(APPEND AOM_APP_TARGETS aom_cx_set_ref)
    765 endif()
    766 
    767 if(ENABLE_EXAMPLES AND CONFIG_AV1_ENCODER)
    768  add_executable(lightfield_encoder "${AOM_ROOT}/examples/lightfield_encoder.c"
    769                                    $<TARGET_OBJECTS:aom_common_app_util>
    770                                    $<TARGET_OBJECTS:aom_encoder_app_util>)
    771  list(APPEND AOM_EXAMPLE_TARGETS lightfield_encoder)
    772  list(APPEND AOM_APP_TARGETS lightfield_encoder)
    773 endif()
    774 
    775 if(ENABLE_EXAMPLES AND CONFIG_AV1_DECODER)
    776  add_executable(lightfield_tile_list_decoder
    777                 "${AOM_ROOT}/examples/lightfield_tile_list_decoder.c"
    778                 $<TARGET_OBJECTS:aom_common_app_util>
    779                 $<TARGET_OBJECTS:aom_decoder_app_util>)
    780  list(APPEND AOM_EXAMPLE_TARGETS lightfield_tile_list_decoder)
    781  list(APPEND AOM_APP_TARGETS lightfield_tile_list_decoder)
    782 endif()
    783 
    784 if(ENABLE_EXAMPLES AND CONFIG_AV1_DECODER)
    785  add_executable(lightfield_decoder "${AOM_ROOT}/examples/lightfield_decoder.c"
    786                                    $<TARGET_OBJECTS:aom_common_app_util>
    787                                    $<TARGET_OBJECTS:aom_decoder_app_util>)
    788  list(APPEND AOM_EXAMPLE_TARGETS lightfield_decoder)
    789  list(APPEND AOM_APP_TARGETS lightfield_decoder)
    790 endif()
    791 
    792 if(ENABLE_EXAMPLES AND CONFIG_AV1_ENCODER AND CONFIG_AV1_DECODER)
    793  add_executable(lightfield_bitstream_parsing
    794                 "${AOM_ROOT}/examples/lightfield_bitstream_parsing.c"
    795                 $<TARGET_OBJECTS:aom_common_app_util>
    796                 $<TARGET_OBJECTS:aom_encoder_app_util>
    797                 $<TARGET_OBJECTS:aom_decoder_app_util>)
    798  list(APPEND AOM_EXAMPLE_TARGETS lightfield_bitstream_parsing)
    799  list(APPEND AOM_APP_TARGETS lightfield_bitstream_parsing)
    800 endif()
    801 
    802 foreach(aom_app ${AOM_APP_TARGETS})
    803  target_link_libraries(${aom_app} ${AOM_LIB_LINK_TYPE} aom)
    804 endforeach()
    805 
    806 if(ENABLE_EXAMPLES OR ENABLE_TESTS OR ENABLE_TOOLS)
    807  if(CONFIG_LIBYUV)
    808    # Add to existing targets.
    809    foreach(aom_app ${AOM_APP_TARGETS})
    810      target_sources(${aom_app} PRIVATE $<TARGET_OBJECTS:yuv>)
    811      set_property(TARGET ${aom_app} PROPERTY LINKER_LANGUAGE CXX)
    812    endforeach()
    813  endif()
    814 
    815  if(CONFIG_WEBM_IO)
    816    add_library(webm OBJECT ${AOM_LIBWEBM_SOURCES})
    817    include_directories("${AOM_ROOT}/third_party/libwebm")
    818    target_compile_definitions(webm PRIVATE __STDC_CONSTANT_MACROS)
    819    target_compile_definitions(webm PRIVATE __STDC_LIMIT_MACROS)
    820 
    821    if(NOT MSVC)
    822      target_compile_options(webm PRIVATE -Wno-shadow)
    823    endif()
    824 
    825    # Add to existing targets.
    826    if(CONFIG_AV1_DECODER)
    827      target_sources(aom_decoder_app_util PRIVATE ${AOM_WEBM_DECODER_SOURCES})
    828    endif()
    829 
    830    if(CONFIG_AV1_ENCODER)
    831      target_sources(aom_encoder_app_util PRIVATE ${AOM_WEBM_ENCODER_SOURCES})
    832    endif()
    833 
    834    foreach(aom_app ${AOM_APP_TARGETS})
    835      target_sources(${aom_app} PRIVATE $<TARGET_OBJECTS:webm>)
    836      set_property(TARGET ${aom_app} PROPERTY LINKER_LANGUAGE CXX)
    837    endforeach()
    838  endif()
    839 endif()
    840 
    841 if(ENABLE_TESTS)
    842 
    843  # Create test_libaom target and the targets it depends on.
    844  setup_aom_test_targets()
    845 endif()
    846 
    847 if(HAVE_PTHREAD_H AND CONFIG_MULTITHREAD)
    848  find_package(Threads)
    849  target_link_libraries(aom ${AOM_LIB_LINK_TYPE} Threads::Threads)
    850  if(BUILD_SHARED_LIBS)
    851    target_link_libraries(aom_static ${AOM_LIB_LINK_TYPE} Threads::Threads)
    852  endif()
    853 endif()
    854 
    855 if(XCODE)
    856 
    857  # TODO(tomfinegan): Make sure target has no C++ files before doing this as
    858  # it's not necessary in that case.
    859  if(CONFIG_LIBYUV OR CONFIG_WEBM_IO)
    860 
    861    # The Xcode generator does not obey LINKER_LANGUAGE. Because of the issue
    862    # what looks like a C++ file needs to be in any target that Xcode will link
    863    # when the target contains a C++ dependency. Without this Xcode will try to
    864    # link with the C linker, which always ends badly when a dependency actually
    865    # includes C++.
    866 
    867    # Note: LINKER_LANGUAGE is explicitly set to C++ for all targets touched
    868    # here, it really is the Xcode generator's fault, or just a deficiency in
    869    # Xcode itself.
    870    foreach(aom_app ${AOM_APP_TARGETS})
    871      add_no_op_source_file_to_target("${aom_app}" "cc")
    872    endforeach()
    873  endif()
    874 endif()
    875 
    876 if(ENABLE_EXAMPLES AND "${CMAKE_GENERATOR}" MATCHES "Makefiles$")
    877 
    878  # For historical purposes place the example binaries in the example directory.
    879  file(MAKE_DIRECTORY "${AOM_CONFIG_DIR}/examples")
    880 
    881  foreach(target ${AOM_EXAMPLE_TARGETS})
    882    if(NOT "${target}" MATCHES "aomdec\|aomenc")
    883      set_target_properties(${target}
    884                            PROPERTIES RUNTIME_OUTPUT_DIRECTORY
    885                                       "${AOM_CONFIG_DIR}/examples")
    886    endif()
    887  endforeach()
    888 
    889  if(ENABLE_TOOLS AND AOM_TOOL_TARGETS)
    890 
    891    # The same expectation is true for tool targets.
    892    file(MAKE_DIRECTORY "${AOM_CONFIG_DIR}/tools")
    893    set_target_properties(${AOM_TOOL_TARGETS}
    894                          PROPERTIES RUNTIME_OUTPUT_DIRECTORY
    895                                     "${AOM_CONFIG_DIR}/tools")
    896  endif()
    897 endif()
    898 
    899 if(BUILD_SHARED_LIBS)
    900  # Don't use -Wl,-z,defs with Clang's sanitizers.
    901  #
    902  # Clang's AddressSanitizer documentation says "When linking shared libraries,
    903  # the AddressSanitizer run-time is not linked, so -Wl,-z,defs may cause link
    904  # errors (don't use it with AddressSanitizer)." See
    905  # https://clang.llvm.org/docs/AddressSanitizer.html#usage. Similarly, see
    906  # https://clang.llvm.org/docs/MemorySanitizer.html#usage.
    907  if(NOT
    908     (APPLE OR CYGWIN OR WIN32)
    909     AND NOT (CMAKE_C_COMPILER_ID MATCHES "Clang" AND SANITIZE))
    910    # The -z defs linker option reports unresolved symbol references from object
    911    # files when building a shared library.
    912    if("${CMAKE_VERSION}" VERSION_LESS "3.13")
    913      # target_link_options() is not available before CMake 3.13.
    914      target_link_libraries(aom PRIVATE -Wl,-z,defs)
    915    else()
    916      target_link_options(aom PRIVATE LINKER:-z,defs)
    917    endif()
    918  endif()
    919 
    920  include("${AOM_ROOT}/build/cmake/exports.cmake")
    921  setup_exports_target()
    922 endif()
    923 
    924 # Handle user supplied compile and link flags last to ensure they're obeyed.
    925 set_user_flags()
    926 
    927 # Aomedia documentation rule.
    928 set(DOXYGEN_VERSION_VALUE 0)
    929 if(ENABLE_DOCS)
    930  find_package(Doxygen)
    931  if(DOXYGEN_FOUND)
    932    # Check if Doxygen version is >= minimum required version(i.e. 1.8.10).
    933    set(MINIMUM_DOXYGEN_VERSION 1008010)
    934 
    935    if(DOXYGEN_VERSION)
    936      # Strip SHA1 from version string if present.
    937      string(REGEX
    938             REPLACE "^([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" DOXYGEN_VERSION
    939                     ${DOXYGEN_VERSION})
    940      # Replace dots with semicolons to create a list.
    941      string(REGEX REPLACE "\\." ";" DOXYGEN_VERSION_LIST ${DOXYGEN_VERSION})
    942      # Parse version components from the list.
    943      list(GET DOXYGEN_VERSION_LIST 0 DOXYGEN_MAJOR)
    944      list(GET DOXYGEN_VERSION_LIST 1 DOXYGEN_MINOR)
    945      list(GET DOXYGEN_VERSION_LIST 2 DOXYGEN_PATCH)
    946    endif()
    947 
    948    # Construct a version value for comparison.
    949    math(EXPR DOXYGEN_MAJOR "${DOXYGEN_MAJOR}*1000000")
    950    math(EXPR DOXYGEN_MINOR "${DOXYGEN_MINOR}*1000")
    951    math(EXPR DOXYGEN_VERSION_VALUE
    952         "${DOXYGEN_MAJOR} + ${DOXYGEN_MINOR} + ${DOXYGEN_PATCH}")
    953 
    954    if(${DOXYGEN_VERSION_VALUE} LESS ${MINIMUM_DOXYGEN_VERSION})
    955      set(DOXYGEN_FOUND NO)
    956    endif()
    957  endif()
    958 
    959  if(DOXYGEN_FOUND)
    960    include("${AOM_ROOT}/docs.cmake")
    961    setup_documentation_targets()
    962  else()
    963    message(
    964      "--- Cannot find doxygen(version 1.8.10 or newer), ENABLE_DOCS turned off."
    965      )
    966    set(ENABLE_DOCS OFF)
    967  endif()
    968 endif()
    969 
    970 # Aomedia dist rule.
    971 if(CONFIG_AV1_DECODER AND ENABLE_EXAMPLES)
    972  list(APPEND AOM_DIST_APPS $<TARGET_FILE:aomdec>)
    973 endif()
    974 if(CONFIG_AV1_ENCODER AND ENABLE_EXAMPLES)
    975  list(APPEND AOM_DIST_APPS $<TARGET_FILE:aomenc>)
    976 endif()
    977 
    978 if(ENABLE_EXAMPLES)
    979  foreach(example ${AOM_EXAMPLE_TARGETS})
    980    list(APPEND AOM_DIST_EXAMPLES $<TARGET_FILE:${example}>)
    981    set_property(TARGET ${example} PROPERTY FOLDER examples)
    982  endforeach()
    983 endif()
    984 
    985 if(ENABLE_TOOLS)
    986  foreach(tool ${AOM_TOOL_TARGETS})
    987    list(APPEND AOM_DIST_TOOLS $<TARGET_FILE:${tool}>)
    988    set_property(TARGET ${tool} PROPERTY FOLDER tools)
    989  endforeach()
    990 endif()
    991 
    992 if(NOT AOM_DIST_DIR)
    993  set(AOM_DIST_DIR "${AOM_CONFIG_DIR}/dist")
    994 endif()
    995 
    996 add_custom_target(dist
    997                  COMMAND ${CMAKE_COMMAND}
    998                          -DAOM_ROOT=${AOM_ROOT}
    999                          -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
   1000                          -DAOM_DIST_DIR=${AOM_DIST_DIR}
   1001                          -DAOM_DIST_APPS="${AOM_DIST_APPS}"
   1002                          -DAOM_DIST_EXAMPLES="${AOM_DIST_EXAMPLES}"
   1003                          -DAOM_DIST_TOOLS="${AOM_DIST_TOOLS}"
   1004                          -DAOM_DIST_INCLUDES="${AOM_INSTALL_INCS}"
   1005                          -DAOM_DIST_LIBS=$<TARGET_FILE:aom>
   1006                          -DENABLE_DOCS=${ENABLE_DOCS} -P
   1007                          "${AOM_ROOT}/build/cmake/dist.cmake"
   1008                  DEPENDS ${AOM_INSTALL_BINS} ${AOM_INSTALL_LIBS}
   1009                          ${AOM_INSTALL_INCS} ${AOM_EXAMPLE_TARGETS}
   1010                          ${AOM_TOOL_TARGETS})
   1011 
   1012 if(ENABLE_DOCS)
   1013  add_dependencies(dist docs)
   1014 endif()
   1015 
   1016 # Collect all variables containing libaom source files.
   1017 get_cmake_property(all_cmake_vars VARIABLES)
   1018 foreach(var ${all_cmake_vars})
   1019  if("${var}" MATCHES "SOURCES$\|_INTRIN_\|_ASM_"
   1020     AND NOT "${var}" MATCHES "DOXYGEN\|LIBYUV\|_PKG_\|TEST"
   1021     AND NOT "${var}" MATCHES "_ASM_NASM\|_ASM_COMPILER")
   1022    list(APPEND aom_source_vars ${var})
   1023  endif()
   1024 endforeach()
   1025 
   1026 if(NOT CONFIG_AV1_DECODER)
   1027  list(FILTER aom_source_vars EXCLUDE REGEX "_DECODER_")
   1028 endif()
   1029 
   1030 # Libaom_srcs.txt generation.
   1031 set(libaom_srcs_txt_file "${AOM_CONFIG_DIR}/libaom_srcs.txt")
   1032 file(WRITE "${libaom_srcs_txt_file}" "# This file is generated. DO NOT EDIT.\n")
   1033 
   1034 # Static source file list first.
   1035 foreach(aom_source_var ${aom_source_vars})
   1036  foreach(file ${${aom_source_var}})
   1037    string(FIND "${file}" "${AOM_CONFIG_DIR}" aom_find_substring_index)
   1038    if(aom_find_substring_index EQUAL -1)
   1039      string(REPLACE "${AOM_ROOT}/" "" file "${file}")
   1040      if(NOT CONFIG_AV1_DECODER AND "${file}" MATCHES "aom_decoder")
   1041        continue()
   1042      endif()
   1043      file(APPEND "${libaom_srcs_txt_file}" "${file}\n")
   1044    endif()
   1045  endforeach()
   1046 endforeach()
   1047 
   1048 file(APPEND "${libaom_srcs_txt_file}"
   1049     "# Files below this line are generated by the libaom build system.\n")
   1050 foreach(aom_source_var ${aom_source_vars})
   1051  foreach(file ${${aom_source_var}})
   1052    string(FIND "${file}" "${AOM_CONFIG_DIR}" aom_find_substring_index)
   1053    if(NOT aom_find_substring_index EQUAL -1)
   1054      string(REPLACE "${AOM_CONFIG_DIR}/" "" file "${file}")
   1055      file(APPEND "${libaom_srcs_txt_file}" "${file}\n")
   1056    endif()
   1057  endforeach()
   1058 endforeach()
   1059 
   1060 # Libaom_srcs.gni generation.
   1061 set(libaom_srcs_gni_file "${AOM_CONFIG_DIR}/libaom_srcs.gni")
   1062 file(WRITE "${libaom_srcs_gni_file}" "# This file is generated. DO NOT EDIT.\n")
   1063 
   1064 foreach(aom_source_var ${aom_source_vars})
   1065  string(FIND "${${aom_source_var}}" "${AOM_ROOT}" aom_find_substring_index)
   1066  if(NOT aom_find_substring_index EQUAL -1)
   1067    string(TOLOWER ${aom_source_var} aom_source_var_lowercase)
   1068    file(APPEND "${libaom_srcs_gni_file}" "\n${aom_source_var_lowercase} = [\n")
   1069  endif()
   1070 
   1071  foreach(file ${${aom_source_var}})
   1072    string(FIND "${file}" "${AOM_CONFIG_DIR}" aom_find_substring_index)
   1073    if(aom_find_substring_index EQUAL -1)
   1074      string(REPLACE "${AOM_ROOT}" "//third_party/libaom/source/libaom" file
   1075                     "${file}")
   1076      if(NOT CONFIG_AV1_DECODER AND "${file}" MATCHES "aom_decoder")
   1077        continue()
   1078      endif()
   1079      file(APPEND "${libaom_srcs_gni_file}" "  \"${file}\",\n")
   1080    endif()
   1081  endforeach()
   1082 
   1083  string(FIND "${${aom_source_var}}" "${AOM_ROOT}" aom_find_substring_index)
   1084  if(NOT aom_find_substring_index EQUAL -1)
   1085    file(APPEND "${libaom_srcs_gni_file}" "]\n")
   1086  endif()
   1087 endforeach()
   1088 
   1089 file(APPEND "${libaom_srcs_gni_file}"
   1090     "\n# Files below this line are generated by the libaom build system.\n")
   1091 
   1092 foreach(aom_source_var ${aom_source_vars})
   1093  string(FIND "${${aom_source_var}}" "${AOM_CONFIG_DIR}"
   1094              aom_find_substring_index)
   1095  if(NOT aom_find_substring_index EQUAL -1)
   1096    string(TOLOWER ${aom_source_var} aom_source_var_lowercase)
   1097    file(APPEND "${libaom_srcs_gni_file}"
   1098         "\n${aom_source_var_lowercase}_gen = [\n")
   1099  endif()
   1100  foreach(file ${${aom_source_var}})
   1101    string(FIND "${file}" "${AOM_ROOT}" aom_find_substring_index)
   1102    if(aom_find_substring_index EQUAL -1)
   1103      string(REPLACE "${AOM_CONFIG_DIR}" "//third_party/libaom/source/libaom"
   1104                     file "${file}")
   1105      file(APPEND "${libaom_srcs_gni_file}" "  \"${file}\",\n")
   1106    endif()
   1107  endforeach()
   1108 
   1109  string(FIND "${${aom_source_var}}" "${AOM_CONFIG_DIR}"
   1110              aom_find_substring_index)
   1111  if(NOT aom_find_substring_index EQUAL -1)
   1112    file(APPEND "${libaom_srcs_gni_file}" "]\n")
   1113  endif()
   1114 endforeach()
   1115 
   1116 # Generate aom.pc and setup install rule.
   1117 setup_aom_install_targets()