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