Bug 1874684 - Part 17: Fix uninitialised variable warnings from clang-tidy. r=allstarschh
[gecko.git] / third_party / aom / CMakeLists.txt
blob00a7e2bca9bcc5282c31b047e0609b5a953a1017
2 # Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
11 if(CONFIG_TFLITE)
12   cmake_minimum_required(VERSION 3.11)
13 else()
14   cmake_minimum_required(VERSION 3.9)
15 endif()
17 set(AOM_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
18 set(AOM_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
19 if("${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.")
26 endif()
28 project(AOM C CXX)
30 # GENERATED source property global visibility.
31 if(POLICY CMP0118)
32   cmake_policy(SET CMP0118 NEW)
33 endif()
35 if(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()
42 endif()
44 if(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!")
49 endif()
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
55 # c=<current>, r=<revision>, a=<age>
57 # libtool generates a .so file as .so.[c-a].a.r, while -version-info c:r:a is
58 # passed to libtool.
60 # We set SO_FILE_VERSION = [c-a].a.r
61 set(LT_CURRENT 11)
62 set(LT_REVISION 2)
63 set(LT_AGE 8)
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)
70 # Enable generators like Xcode and Visual Studio to place projects in folders.
71 set_property(GLOBAL PROPERTY USE_FOLDERS TRUE)
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")
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")
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")
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")
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")
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")
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")
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")
205 list(APPEND AOM_ENCODER_STATS_SOURCES "${AOM_ROOT}/stats/aomstats.c"
206             "${AOM_ROOT}/stats/aomstats.h" "${AOM_ROOT}/stats/rate_hist.c"
207             "${AOM_ROOT}/stats/rate_hist.h")
209 list(APPEND AOM_VERSION_SOURCES "${AOM_CONFIG_DIR}/config/aom_version.h")
211 list(APPEND AOM_WEBM_DECODER_SOURCES "${AOM_ROOT}/common/webmdec.cc"
212             "${AOM_ROOT}/common/webmdec.h")
214 list(APPEND AOM_WEBM_ENCODER_SOURCES "${AOM_ROOT}/common/webmenc.cc"
215             "${AOM_ROOT}/common/webmenc.h")
217 include_directories(${AOM_ROOT} ${AOM_CONFIG_DIR} ${AOM_ROOT}/apps
218                     ${AOM_ROOT}/common ${AOM_ROOT}/examples ${AOM_ROOT}/stats)
220 # Targets
221 add_library(aom_version ${AOM_VERSION_SOURCES})
222 add_no_op_source_file_to_target(aom_version c)
223 add_custom_command(OUTPUT "${AOM_CONFIG_DIR}/config/aom_version.h"
224                    COMMAND ${CMAKE_COMMAND} ARGS
225                            -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
226                            -DAOM_ROOT=${AOM_ROOT}
227                            -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
228                            -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
229                            "${AOM_ROOT}/build/cmake/version.cmake"
230                    COMMENT "Writing aom_version.h"
231                    VERBATIM)
233 add_custom_target(aom_version_check
234                   COMMAND ${CMAKE_COMMAND}
235                           -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
236                           -DAOM_ROOT=${AOM_ROOT}
237                           -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
238                           -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
239                           "${AOM_ROOT}/build/cmake/version.cmake"
240                   COMMENT "Updating version info if necessary."
241                   VERBATIM)
243 if(BUILD_SHARED_LIBS AND NOT MSVC)
244   # Generate version file immediately for non-MSVC shared builds: The version
245   # string is needed for the aom target.
246   execute_process(COMMAND ${CMAKE_COMMAND}
247                           -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
248                           -DAOM_ROOT=${AOM_ROOT}
249                           -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
250                           -DPERL_EXECUTABLE=${PERL_EXECUTABLE} -P
251                           "${AOM_ROOT}/build/cmake/version.cmake")
252 endif()
254 add_dependencies(aom_version aom_version_check)
256 # TODO(tomfinegan): Move rtcd target setup where it belongs for each rtcd
257 # source.
258 add_rtcd_build_step("${AOM_ROOT}/aom_dsp/aom_dsp_rtcd_defs.pl"
259                     "${AOM_CONFIG_DIR}/config/aom_dsp_rtcd.h"
260                     "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd.c" "aom_dsp_rtcd")
261 add_rtcd_build_step("${AOM_ROOT}/aom_scale/aom_scale_rtcd.pl"
262                     "${AOM_CONFIG_DIR}/config/aom_scale_rtcd.h"
263                     "${AOM_ROOT}/aom_scale/aom_scale_rtcd.c" "aom_scale_rtcd")
264 add_rtcd_build_step("${AOM_ROOT}/av1/common/av1_rtcd_defs.pl"
265                     "${AOM_CONFIG_DIR}/config/av1_rtcd.h"
266                     "${AOM_ROOT}/av1/common/av1_rtcd.c" "av1_rtcd")
268 add_library(aom_rtcd OBJECT ${AOM_RTCD_SOURCES})
269 add_dependencies(aom_rtcd aom_version)
271 if(ENABLE_EXAMPLES)
272   add_library(aom_encoder_stats OBJECT ${AOM_ENCODER_STATS_SOURCES})
273   set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_encoder_stats)
274 endif()
276 # Xcode generator cannot take a library composed solely of objects. See
277 # https://gitlab.kitware.com/cmake/cmake/-/issues/17500
278 if(XCODE)
279   set(target_objs_aom ${AOM_SOURCES})
280 else()
281   add_library(aom_obj OBJECT ${AOM_SOURCES})
282   set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_obj)
283   set(target_objs_aom $<TARGET_OBJECTS:aom_obj>)
284 endif()
285 add_library(aom ${target_objs_aom} $<TARGET_OBJECTS:aom_rtcd>)
287 if(BUILD_SHARED_LIBS)
288   add_library(aom_static STATIC ${target_objs_aom} $<TARGET_OBJECTS:aom_rtcd>)
289   set_target_properties(aom_static PROPERTIES OUTPUT_NAME aom)
290   if(MSVC OR (WIN32 AND NOT MINGW))
291     # Fix race condition between the import library and the static library.
292     # Affects MSVC in all three flavors (stock, clang-cl, LLVM -- the latter
293     # sets MSVC and MINGW both to FALSE).
294     set_target_properties(aom PROPERTIES ARCHIVE_OUTPUT_NAME "aom_dll")
295   endif()
297   if(NOT MSVC)
298     # Extract version string and set VERSION/SOVERSION for the aom target.
299     extract_version_string("${AOM_CONFIG_DIR}/config/aom_version.h"
300                            aom_version_triple)
302     # Strip any trailing version information, if present.
303     string(FIND "${aom_version_triple}" "-" dash_pos)
304     if(NOT dash_pos EQUAL -1)
305       string(SUBSTRING "${aom_version_triple}" 0 ${dash_pos} aom_version_triple)
306     endif()
308     # cmake-format: off
309     # VERSION is embedded in the .so file name.
310     # libaom.so -> libaom.so.SOVERSION
311     # libaom.so.SOVERSION -> libaom.so.VERSION
312     # libaom.so.VERSION
313     # cmake-format: on
314     set_target_properties(aom PROPERTIES SOVERSION ${SO_VERSION})
315     set_target_properties(aom PROPERTIES VERSION ${SO_FILE_VERSION})
316   endif()
317 endif()
319 if(NOT WIN32 AND NOT APPLE)
320   target_link_libraries(aom ${AOM_LIB_LINK_TYPE} m)
321   if(BUILD_SHARED_LIBS)
322     target_link_libraries(aom_static ${AOM_LIB_LINK_TYPE} m)
323   endif()
324 endif()
326 if(CONFIG_AV1_ENCODER AND NOT BUILD_SHARED_LIBS)
327   list(APPEND AOM_AV1_RC_SOURCES "${AOM_ROOT}/av1/ratectrl_rtc.h"
328               "${AOM_ROOT}/av1/ratectrl_rtc.cc")
329   add_library(aom_av1_rc ${AOM_AV1_RC_SOURCES})
330   target_link_libraries(aom_av1_rc ${AOM_LIB_LINK_TYPE} aom)
331   if(NOT WIN32 AND NOT APPLE)
332     target_link_libraries(aom_av1_rc ${AOM_LIB_LINK_TYPE} m)
333   endif()
334   set_target_properties(aom_av1_rc PROPERTIES LINKER_LANGUAGE CXX)
335 endif()
337 # List of object and static library targets.
338 set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_rtcd aom_mem aom_scale aom)
339 if(CONFIG_AV1_ENCODER AND NOT BUILD_SHARED_LIBS)
340   set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_av1_rc)
341 endif()
342 if(BUILD_SHARED_LIBS)
343   set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_static)
344 endif()
346 # Setup dependencies.
347 if(CONFIG_THREE_PASS)
348   setup_ivf_dec_targets()
349 endif()
350 setup_aom_dsp_targets()
351 setup_aom_mem_targets()
352 setup_aom_ports_targets()
353 setup_aom_util_targets()
354 setup_aom_scale_targets()
355 setup_av1_targets()
357 # Make all library targets depend on aom_rtcd to make sure it builds first.
358 foreach(aom_lib ${AOM_LIB_TARGETS})
359   if(NOT "${aom_lib}" STREQUAL "aom_rtcd")
360     add_dependencies(${aom_lib} aom_rtcd)
361   endif()
362 endforeach()
364 # Generate a C file containing the function usage_exit(). Users of the
365 # aom_common_app_util library must define this function. This is a convenience
366 # to allow omission of the function from applications that might want to use
367 # other pieces of the util support without defining usage_exit().
368 file(WRITE "${AOM_GEN_SRC_DIR}/usage_exit.c"
369      "#include <stdlib.h>\n\n#include \"common/tools_common.h\"\n\n"
370      "void usage_exit(void) { exit(EXIT_FAILURE); }\n")
373 # Application and application support targets.
375 if(ENABLE_EXAMPLES OR ENABLE_TESTS OR ENABLE_TOOLS)
376   add_library(aom_common_app_util OBJECT ${AOM_COMMON_APP_UTIL_SOURCES})
377   add_library(aom_usage_exit OBJECT "${AOM_GEN_SRC_DIR}/usage_exit.c")
378   set_property(TARGET ${example} PROPERTY FOLDER examples)
379   if(CONFIG_AV1_DECODER)
380     add_library(aom_decoder_app_util OBJECT ${AOM_DECODER_APP_UTIL_SOURCES})
381     set_property(TARGET ${example} PROPERTY FOLDER examples)
382     # obudec depends on internal headers that require *rtcd.h
383     add_dependencies(aom_decoder_app_util aom_rtcd)
384   endif()
385   if(CONFIG_AV1_ENCODER)
386     add_library(aom_encoder_app_util OBJECT ${AOM_ENCODER_APP_UTIL_SOURCES})
387     set_property(TARGET ${example} PROPERTY FOLDER examples)
388   endif()
389 endif()
391 if(CONFIG_AV1_DECODER AND ENABLE_EXAMPLES)
392   add_executable(aomdec "${AOM_ROOT}/apps/aomdec.c"
393                         $<TARGET_OBJECTS:aom_common_app_util>
394                         $<TARGET_OBJECTS:aom_decoder_app_util>)
395   add_executable(decode_to_md5 "${AOM_ROOT}/examples/decode_to_md5.c"
396                                $<TARGET_OBJECTS:aom_common_app_util>
397                                $<TARGET_OBJECTS:aom_decoder_app_util>)
398   add_executable(decode_with_drops "${AOM_ROOT}/examples/decode_with_drops.c"
399                                    $<TARGET_OBJECTS:aom_common_app_util>
400                                    $<TARGET_OBJECTS:aom_decoder_app_util>)
401   add_executable(simple_decoder "${AOM_ROOT}/examples/simple_decoder.c"
402                                 $<TARGET_OBJECTS:aom_common_app_util>
403                                 $<TARGET_OBJECTS:aom_decoder_app_util>)
404   add_executable(scalable_decoder "${AOM_ROOT}/examples/scalable_decoder.c"
405                                   $<TARGET_OBJECTS:aom_common_app_util>
406                                   $<TARGET_OBJECTS:aom_decoder_app_util>)
408   if(CONFIG_ANALYZER)
409     add_executable(analyzer "${AOM_ROOT}/examples/analyzer.cc"
410                             $<TARGET_OBJECTS:aom_common_app_util>
411                             $<TARGET_OBJECTS:aom_decoder_app_util>)
412     target_link_libraries(analyzer ${AOM_LIB_LINK_TYPE} ${wxWidgets_LIBRARIES})
413     list(APPEND AOM_APP_TARGETS analyzer)
414     list(APPEND AOM_DECODER_EXAMPLE_TARGETS analyzer)
415   endif()
417   if(CONFIG_INSPECTION)
418     add_executable(inspect "${AOM_ROOT}/examples/inspect.c"
419                            $<TARGET_OBJECTS:aom_common_app_util>
420                            $<TARGET_OBJECTS:aom_decoder_app_util>)
421     list(APPEND AOM_DECODER_EXAMPLE_TARGETS inspect)
423     if(EMSCRIPTEN)
424       add_preproc_definition(_POSIX_SOURCE)
425       append_link_flag_to_target("inspect" "--emrun")
426       append_link_flag_to_target("inspect" "-s USE_PTHREADS=0")
427       append_link_flag_to_target("inspect" "-s WASM=1")
428       append_link_flag_to_target("inspect" "-s MODULARIZE=1")
429       append_link_flag_to_target("inspect" "-s ALLOW_MEMORY_GROWTH=1")
430       append_link_flag_to_target(
431         "inspect" "-s \'EXTRA_EXPORTED_RUNTIME_METHODS=[\"UTF8ToString\"]\'")
432       append_link_flag_to_target("inspect"
433                                  "-s EXPORT_NAME=\"\'DecoderModule\'\"")
434       append_link_flag_to_target("inspect" "--memory-init-file 0")
436       if("${CMAKE_BUILD_TYPE}" STREQUAL "")
438         # Default to -O3 when no build type is specified.
439         append_compiler_flag("-O3")
440       endif()
442       em_link_post_js(inspect "${AOM_ROOT}/tools/inspect-post.js")
443     endif()
444   endif()
446   # Maintain a list of decoder example targets.
447   list(APPEND AOM_DECODER_EXAMPLE_TARGETS aomdec decode_to_md5 decode_with_drops
448               scalable_decoder simple_decoder)
450   # Add decoder examples to the app targets list.
451   list(APPEND AOM_APP_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS})
452 endif()
454 if(CONFIG_LIBYUV OR CONFIG_TUNE_BUTTERAUGLI)
455   add_library(yuv OBJECT ${AOM_LIBYUV_SOURCES})
456   if(NOT MSVC)
457     target_compile_options(yuv PRIVATE -Wno-shadow)
458   endif()
459   include_directories("${AOM_ROOT}/third_party/libyuv/include")
460 endif()
462 if(CONFIG_AV1_ENCODER)
463   if(ENABLE_EXAMPLES)
464     add_executable(aomenc "${AOM_ROOT}/apps/aomenc.c"
465                           $<TARGET_OBJECTS:aom_common_app_util>
466                           $<TARGET_OBJECTS:aom_encoder_app_util>
467                           $<TARGET_OBJECTS:aom_encoder_stats>)
468     add_executable(lossless_encoder "${AOM_ROOT}/examples/lossless_encoder.c"
469                                     $<TARGET_OBJECTS:aom_common_app_util>
470                                     $<TARGET_OBJECTS:aom_encoder_app_util>)
471     add_executable(set_maps "${AOM_ROOT}/examples/set_maps.c"
472                             $<TARGET_OBJECTS:aom_common_app_util>
473                             $<TARGET_OBJECTS:aom_encoder_app_util>)
474     add_executable(simple_encoder "${AOM_ROOT}/examples/simple_encoder.c"
475                                   $<TARGET_OBJECTS:aom_common_app_util>
476                                   $<TARGET_OBJECTS:aom_encoder_app_util>)
477     add_executable(twopass_encoder "${AOM_ROOT}/examples/twopass_encoder.c"
478                                    $<TARGET_OBJECTS:aom_common_app_util>
479                                    $<TARGET_OBJECTS:aom_encoder_app_util>)
480     add_executable(noise_model "${AOM_ROOT}/examples/noise_model.c"
481                                $<TARGET_OBJECTS:aom_common_app_util>
482                                $<TARGET_OBJECTS:aom_encoder_app_util>)
483     add_executable(photon_noise_table
484                    "${AOM_ROOT}/examples/photon_noise_table.c"
485                    $<TARGET_OBJECTS:aom_common_app_util>
486                    $<TARGET_OBJECTS:aom_encoder_app_util>)
487     add_executable(scalable_encoder "${AOM_ROOT}/examples/scalable_encoder.c"
488                                     $<TARGET_OBJECTS:aom_common_app_util>
489                                     $<TARGET_OBJECTS:aom_encoder_app_util>)
491     # Maintain a list of encoder example targets.
492     list(APPEND AOM_ENCODER_EXAMPLE_TARGETS aomenc lossless_encoder noise_model
493                 photon_noise_table set_maps simple_encoder scalable_encoder
494                 twopass_encoder)
496     if(NOT BUILD_SHARED_LIBS)
497       add_executable(svc_encoder_rtc "${AOM_ROOT}/examples/svc_encoder_rtc.cc"
498                                      $<TARGET_OBJECTS:aom_common_app_util>
499                                      $<TARGET_OBJECTS:aom_encoder_app_util>)
500       target_link_libraries(svc_encoder_rtc ${AOM_LIB_LINK_TYPE} aom_av1_rc)
501       list(APPEND AOM_ENCODER_EXAMPLE_TARGETS svc_encoder_rtc)
502     endif()
503   endif()
505   if(ENABLE_TOOLS)
506     if(CONFIG_ENTROPY_STATS AND NOT BUILD_SHARED_LIBS)
508       # TODO(tomfinegan): Sort out why a simple link command with
509       # aom_entropy_optimizer.c won't work on macos, but dragging in all the
510       # helper machinery allows the link to succeed.
511       add_executable(aom_entropy_optimizer
512                      "${AOM_ROOT}/tools/aom_entropy_optimizer.c"
513                      $<TARGET_OBJECTS:aom_common_app_util>
514                      $<TARGET_OBJECTS:aom_encoder_app_util>
515                      $<TARGET_OBJECTS:aom_usage_exit>)
517       # Maintain a list of encoder tool targets.
518       list(APPEND AOM_ENCODER_TOOL_TARGETS aom_entropy_optimizer)
519     endif()
520   endif()
522   # Add encoder examples and tools to the targets list.
523   list(APPEND AOM_APP_TARGETS ${AOM_ENCODER_EXAMPLE_TARGETS}
524               ${AOM_ENCODER_TOOL_TARGETS})
526   if(CONFIG_TUNE_BUTTERAUGLI)
527     find_package(PkgConfig)
528     # Use find_library() with STATIC_LINK_JXL for static build since
529     # pkg_check_modules() with LIBJXL_STATIC is not working.
530     if(STATIC_LINK_JXL OR NOT PKG_CONFIG_FOUND)
531       find_library(LIBJXL_LIBRARIES libjxl.a)
532       find_library(LIBHWY_LIBRARIES libhwy.a)
533       find_library(LIBSKCMS_LIBRARIES libskcms.a)
534       find_library(LIBBROTLICOMMON_LIBRARIES libbrotlicommon-static.a)
535       find_library(LIBBROTLIENC_LIBRARIES libbrotlienc-static.a)
536       find_library(LIBBROTLIDEC_LIBRARIES libbrotlidec-static.a)
537       find_path(LIBJXL_INCLUDE_DIRS butteraugli.h PATH_SUFFIXES jxl)
538       if(LIBJXL_LIBRARIES
539          AND LIBHWY_LIBRARIES
540          AND LIBSKCMS_LIBRARIES
541          AND LIBBROTLICOMMON_LIBRARIES
542          AND LIBBROTLIENC_LIBRARIES
543          AND LIBBROTLIDEC_LIBRARIES
544          AND LIBJXL_INCLUDE_DIRS)
545         message(STATUS "Found JXL library: ${LIBJXL_LIBRARIES} "
546                        "${LIBHWY_LIBRARIES} ${LIBSKCMS_LIBRARIES} "
547                        "${LIBBROTLICOMMON_LIBRARIES} ${LIBBROTLIENC_LIBRARIES}"
548                        "${LIBBROTLIDEC_LIBRARIES}")
549         message(STATUS "Found JXL include: ${LIBJXL_INCLUDE_DIRS}")
550       else()
551         message(FATAL_ERROR "JXL library not found.")
552       endif()
553       target_link_libraries(aom
554                             PRIVATE ${LIBJXL_LIBRARIES} ${LIBHWY_LIBRARIES}
555                                     ${LIBSKCMS_LIBRARIES}
556                                     ${LIBBROTLIENC_LIBRARIES}
557                                     ${LIBBROTLIDEC_LIBRARIES}
558                                     ${LIBBROTLICOMMON_LIBRARIES})
559       target_include_directories(aom_dsp_encoder PRIVATE ${LIBJXL_INCLUDE_DIRS})
560     else()
561       pkg_check_modules(LIBJXL REQUIRED libjxl)
562       target_link_libraries(aom PRIVATE ${LIBJXL_LDFLAGS} ${LIBJXL_LIBRARIES})
563       target_include_directories(aom_dsp_encoder PRIVATE ${LIBJXL_INCLUDE_DIRS})
564       if(LIBJXL_CFLAGS)
565         append_compiler_flag("${LIBJXL_CFLAGS}")
566       endif()
567       pkg_check_modules(LIBHWY REQUIRED libhwy)
568       target_link_libraries(aom PRIVATE ${LIBHWY_LDFLAGS} ${LIBHWY_LIBRARIES})
569       target_include_directories(aom_dsp_encoder
570                                  PRIVATE ${LIBLIBHWY_INCLUDE_DIRS})
571       if(LIBHWY_CFLAGS)
572         append_compiler_flag("${LIBHWY_CFLAGS}")
573       endif()
574     endif()
576     set_target_properties(aom PROPERTIES LINKER_LANGUAGE CXX)
577     if(BUILD_SHARED_LIBS)
578       set_target_properties(aom_static PROPERTIES LINKER_LANGUAGE CXX)
579     endif()
581     list(APPEND AOM_LIB_TARGETS yuv)
582     target_sources(aom PRIVATE $<TARGET_OBJECTS:yuv>)
583     if(BUILD_SHARED_LIBS)
584       target_sources(aom_static PRIVATE $<TARGET_OBJECTS:yuv>)
585     endif()
586   endif()
588   if(CONFIG_TFLITE)
589     include(FetchContent)
591     set(TFLITE_TAG "v2.6.1")
593     message(STATUS "Fetching TFLite ${TFLITE_TAG}...")
595     # static linking makes life with TFLite much easier
596     set(TFLITE_C_BUILD_SHARED_LIBS OFF)
598     # We don't care about comparing against these delegates (yet), and disabling
599     # it reduces compile time meaningfully
600     set(TFLITE_ENABLE_RUY OFF)
601     set(TFLITE_ENABLE_XNNPACK OFF)
603     fetchcontent_declare(tflite
604                          GIT_REPOSITORY https://github.com/tensorflow/tensorflow
605                          GIT_TAG ${TFLITE_TAG}
606                          GIT_SHALLOW TRUE)
608     fetchcontent_getproperties(tflite)
609     if(NOT tflite_POPULATED)
610       fetchcontent_populate(tflite)
611       # Some of the subprojects (e.g. Eigen) are very noisy and emit status
612       # messages all the time. Temporary ignore status messages while adding
613       # this to silence it. Ugly but effective.
614       set(OLD_CMAKE_MESSAGE_LOG_LEVEL ${CMAKE_MESSAGE_LOG_LEVEL})
615       set(CMAKE_MESSAGE_LOG_LEVEL WARNING)
616       add_subdirectory(${tflite_SOURCE_DIR}/tensorflow/lite/c
617                        ${tflite_BINARY_DIR})
618       set(CMAKE_MESSAGE_LOG_LEVEL ${OLD_CMAKE_MESSAGE_LOG_LEVEL})
619     endif()
621     # Disable some noisy warnings in tflite
622     target_compile_options(tensorflow-lite PRIVATE -w)
624     # tensorflowlite_c is implicitly declared by this FetchContent
625     include_directories(${tflite_SOURCE_DIR})
626     target_link_libraries(aom PRIVATE tensorflow-lite)
627   endif()
629   if(CONFIG_TUNE_VMAF)
630     find_package(PkgConfig)
631     if(PKG_CONFIG_FOUND)
632       pkg_check_modules(VMAF REQUIRED libvmaf)
633       if(BUILD_SHARED_LIBS)
634         target_link_libraries(aom_static
635                               PRIVATE ${VMAF_LDFLAGS} ${VMAF_LIBRARIES})
636       endif()
637       target_link_libraries(aom PRIVATE ${VMAF_LDFLAGS} ${VMAF_LIBRARIES})
638       target_include_directories(aom_dsp_encoder PRIVATE ${VMAF_INCLUDE_DIRS})
639       if(VMAF_CFLAGS)
640         foreach(flag "${VMAF_CFLAGS}")
641           append_compiler_flag("${flag}")
642         endforeach()
643       endif()
644     else()
645       message(FATAL_ERROR "CONFIG_TUNE_VMAF error: pkg-config not found.")
646     endif()
647     set_target_properties(aom PROPERTIES LINKER_LANGUAGE CXX)
648     if(BUILD_SHARED_LIBS)
649       set_target_properties(aom_static PROPERTIES LINKER_LANGUAGE CXX)
650     endif()
651   endif()
652 endif()
654 if(ENABLE_EXAMPLES)
656   # Maintain a separate variable listing only the examples to facilitate
657   # installation of example programs into an examples sub directory of
658   # $AOM_DIST_DIR/bin when building the dist target.
659   list(APPEND AOM_EXAMPLE_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS}
660               ${AOM_ENCODER_EXAMPLE_TARGETS})
661 endif()
663 if(ENABLE_TOOLS)
664   if(CONFIG_AV1_DECODER)
665     add_executable(dump_obu "${AOM_ROOT}/tools/dump_obu.cc"
666                             "${AOM_ROOT}/tools/obu_parser.cc"
667                             "${AOM_ROOT}/tools/obu_parser.h"
668                             $<TARGET_OBJECTS:aom_common_app_util>
669                             $<TARGET_OBJECTS:aom_decoder_app_util>
670                             $<TARGET_OBJECTS:aom_usage_exit>)
672     list(APPEND AOM_TOOL_TARGETS dump_obu)
673     list(APPEND AOM_APP_TARGETS dump_obu)
675     # Maintain a separate variable listing only the examples to facilitate
676     # installation of example programs into an tools sub directory of
677     # $AOM_DIST_DIR/bin when building the dist target.
678     list(APPEND AOM_TOOL_TARGETS ${AOM_DECODER_TOOL_TARGETS}
679                 ${AOM_ENCODER_TOOL_TARGETS})
680   endif()
681 endif()
683 if(ENABLE_EXAMPLES AND CONFIG_AV1_DECODER AND CONFIG_AV1_ENCODER)
684   add_executable(aom_cx_set_ref "${AOM_ROOT}/examples/aom_cx_set_ref.c"
685                                 $<TARGET_OBJECTS:aom_common_app_util>
686                                 $<TARGET_OBJECTS:aom_encoder_app_util>)
687   list(APPEND AOM_EXAMPLE_TARGETS aom_cx_set_ref)
688   list(APPEND AOM_APP_TARGETS aom_cx_set_ref)
689 endif()
691 if(ENABLE_EXAMPLES AND CONFIG_AV1_ENCODER)
692   add_executable(lightfield_encoder "${AOM_ROOT}/examples/lightfield_encoder.c"
693                                     $<TARGET_OBJECTS:aom_common_app_util>
694                                     $<TARGET_OBJECTS:aom_encoder_app_util>)
695   list(APPEND AOM_EXAMPLE_TARGETS lightfield_encoder)
696   list(APPEND AOM_APP_TARGETS lightfield_encoder)
697 endif()
699 if(ENABLE_EXAMPLES AND CONFIG_AV1_DECODER)
700   add_executable(lightfield_tile_list_decoder
701                  "${AOM_ROOT}/examples/lightfield_tile_list_decoder.c"
702                  $<TARGET_OBJECTS:aom_common_app_util>
703                  $<TARGET_OBJECTS:aom_decoder_app_util>)
704   list(APPEND AOM_EXAMPLE_TARGETS lightfield_tile_list_decoder)
705   list(APPEND AOM_APP_TARGETS lightfield_tile_list_decoder)
706 endif()
708 if(ENABLE_EXAMPLES AND CONFIG_AV1_DECODER)
709   add_executable(lightfield_decoder "${AOM_ROOT}/examples/lightfield_decoder.c"
710                                     $<TARGET_OBJECTS:aom_common_app_util>
711                                     $<TARGET_OBJECTS:aom_decoder_app_util>)
712   list(APPEND AOM_EXAMPLE_TARGETS lightfield_decoder)
713   list(APPEND AOM_APP_TARGETS lightfield_decoder)
714 endif()
716 if(ENABLE_EXAMPLES AND CONFIG_AV1_ENCODER AND CONFIG_AV1_DECODER)
717   add_executable(lightfield_bitstream_parsing
718                  "${AOM_ROOT}/examples/lightfield_bitstream_parsing.c"
719                  $<TARGET_OBJECTS:aom_common_app_util>
720                  $<TARGET_OBJECTS:aom_encoder_app_util>
721                  $<TARGET_OBJECTS:aom_decoder_app_util>)
722   list(APPEND AOM_EXAMPLE_TARGETS lightfield_bitstream_parsing)
723   list(APPEND AOM_APP_TARGETS lightfield_bitstream_parsing)
724 endif()
726 foreach(aom_app ${AOM_APP_TARGETS})
727   target_link_libraries(${aom_app} ${AOM_LIB_LINK_TYPE} aom)
728 endforeach()
730 if(ENABLE_EXAMPLES OR ENABLE_TESTS OR ENABLE_TOOLS)
731   if(CONFIG_LIBYUV)
732     # Add to existing targets.
733     foreach(aom_app ${AOM_APP_TARGETS})
734       target_sources(${aom_app} PRIVATE $<TARGET_OBJECTS:yuv>)
735       set_property(TARGET ${aom_app} PROPERTY LINKER_LANGUAGE CXX)
736     endforeach()
737   endif()
739   if(CONFIG_WEBM_IO)
740     add_library(webm OBJECT ${AOM_LIBWEBM_SOURCES})
741     include_directories("${AOM_ROOT}/third_party/libwebm")
742     target_compile_definitions(webm PRIVATE __STDC_CONSTANT_MACROS)
743     target_compile_definitions(webm PRIVATE __STDC_LIMIT_MACROS)
745     if(NOT MSVC)
746       target_compile_options(webm PRIVATE -Wno-shadow)
747     endif()
749     # Add to existing targets.
750     if(CONFIG_AV1_DECODER)
751       target_sources(aom_decoder_app_util PRIVATE ${AOM_WEBM_DECODER_SOURCES})
752     endif()
754     if(CONFIG_AV1_ENCODER)
755       target_sources(aom_encoder_app_util PRIVATE ${AOM_WEBM_ENCODER_SOURCES})
756     endif()
758     foreach(aom_app ${AOM_APP_TARGETS})
759       target_sources(${aom_app} PRIVATE $<TARGET_OBJECTS:webm>)
760       set_property(TARGET ${aom_app} PROPERTY LINKER_LANGUAGE CXX)
761     endforeach()
762   endif()
763 endif()
765 if(ENABLE_TESTS)
767   # Create test_libaom target and the targets it depends on.
768   setup_aom_test_targets()
769 endif()
771 if(HAVE_PTHREAD_H AND CONFIG_MULTITHREAD)
772   find_package(Threads)
773   target_link_libraries(aom ${AOM_LIB_LINK_TYPE} Threads::Threads)
774   if(BUILD_SHARED_LIBS)
775     target_link_libraries(aom_static ${AOM_LIB_LINK_TYPE} Threads::Threads)
776   endif()
777 endif()
779 if(XCODE)
781   # TODO(tomfinegan): Make sure target has no C++ files before doing this as
782   # it's not necessary in that case.
783   if(CONFIG_LIBYUV OR CONFIG_WEBM_IO)
785     # The Xcode generator does not obey LINKER_LANGUAGE. Because of the issue
786     # what looks like a C++ file needs to be in any target that Xcode will link
787     # when the target contains a C++ dependency. Without this Xcode will try to
788     # link with the C linker, which always ends badly when a dependency actually
789     # includes C++.
791     # Note: LINKER_LANGUAGE is explicitly set to C++ for all targets touched
792     # here, it really is the Xcode generator's fault, or just a deficiency in
793     # Xcode itself.
794     foreach(aom_app ${AOM_APP_TARGETS})
795       add_no_op_source_file_to_target("${aom_app}" "cc")
796     endforeach()
797   endif()
798 endif()
800 if(ENABLE_EXAMPLES AND "${CMAKE_GENERATOR}" MATCHES "Makefiles$")
802   # For historical purposes place the example binaries in the example directory.
803   file(MAKE_DIRECTORY "${AOM_CONFIG_DIR}/examples")
805   foreach(target ${AOM_EXAMPLE_TARGETS})
806     if(NOT "${target}" MATCHES "aomdec\|aomenc")
807       set_target_properties(${target}
808                             PROPERTIES RUNTIME_OUTPUT_DIRECTORY
809                                        "${AOM_CONFIG_DIR}/examples")
810     endif()
811   endforeach()
813   if(ENABLE_TOOLS AND AOM_TOOL_TARGETS)
815     # The same expectation is true for tool targets.
816     file(MAKE_DIRECTORY "${AOM_CONFIG_DIR}/tools")
817     set_target_properties(${AOM_TOOL_TARGETS}
818                           PROPERTIES RUNTIME_OUTPUT_DIRECTORY
819                                      "${AOM_CONFIG_DIR}/tools")
820   endif()
821 endif()
823 if(BUILD_SHARED_LIBS)
824   # Don't use -Wl,-z,defs with Clang's sanitizers.
825   #
826   # Clang's AddressSanitizer documentation says "When linking shared libraries,
827   # the AddressSanitizer run-time is not linked, so -Wl,-z,defs may cause link
828   # errors (don't use it with AddressSanitizer)." See
829   # https://clang.llvm.org/docs/AddressSanitizer.html#usage. Similarly, see
830   # https://clang.llvm.org/docs/MemorySanitizer.html#usage.
831   if(NOT WIN32
832      AND NOT APPLE
833      AND NOT (CMAKE_C_COMPILER_ID MATCHES "Clang" AND SANITIZE))
834     # The -z defs linker option reports unresolved symbol references from object
835     # files when building a shared library.
836     if("${CMAKE_VERSION}" VERSION_LESS "3.13")
837       # target_link_options() is not available before CMake 3.13.
838       target_link_libraries(aom PRIVATE -Wl,-z,defs)
839     else()
840       target_link_options(aom PRIVATE LINKER:-z,defs)
841     endif()
842   endif()
844   include("${AOM_ROOT}/build/cmake/exports.cmake")
845   setup_exports_target()
846 endif()
848 # Handle user supplied compile and link flags last to ensure they're obeyed.
849 set_user_flags()
851 # Aomedia documentation rule.
852 set(DOXYGEN_VERSION_VALUE 0)
853 if(ENABLE_DOCS)
854   find_package(Doxygen)
855   if(DOXYGEN_FOUND)
856     # Check if Doxygen version is >= minimum required version(i.e. 1.8.10).
857     set(MINIMUM_DOXYGEN_VERSION 1008010)
859     if(DOXYGEN_VERSION)
860       # Strip SHA1 from version string if present.
861       string(REGEX
862              REPLACE "^([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" DOXYGEN_VERSION
863                      ${DOXYGEN_VERSION})
864       # Replace dots with semicolons to create a list.
865       string(REGEX REPLACE "\\." ";" DOXYGEN_VERSION_LIST ${DOXYGEN_VERSION})
866       # Parse version components from the list.
867       list(GET DOXYGEN_VERSION_LIST 0 DOXYGEN_MAJOR)
868       list(GET DOXYGEN_VERSION_LIST 1 DOXYGEN_MINOR)
869       list(GET DOXYGEN_VERSION_LIST 2 DOXYGEN_PATCH)
870     endif()
872     # Construct a version value for comparison.
873     math(EXPR DOXYGEN_MAJOR "${DOXYGEN_MAJOR}*1000000")
874     math(EXPR DOXYGEN_MINOR "${DOXYGEN_MINOR}*1000")
875     math(EXPR DOXYGEN_VERSION_VALUE
876          "${DOXYGEN_MAJOR} + ${DOXYGEN_MINOR} + ${DOXYGEN_PATCH}")
878     if(${DOXYGEN_VERSION_VALUE} LESS ${MINIMUM_DOXYGEN_VERSION})
879       set(DOXYGEN_FOUND NO)
880     endif()
881   endif()
883   if(DOXYGEN_FOUND)
884     include("${AOM_ROOT}/docs.cmake")
885     setup_documentation_targets()
886   else()
887     message(
888       "--- Cannot find doxygen(version 1.8.10 or newer), ENABLE_DOCS turned off."
889       )
890     set(ENABLE_DOCS OFF)
891   endif()
892 endif()
894 # Aomedia dist rule.
895 if(CONFIG_AV1_DECODER AND ENABLE_EXAMPLES)
896   list(APPEND AOM_DIST_APPS $<TARGET_FILE:aomdec>)
897 endif()
898 if(CONFIG_AV1_ENCODER AND ENABLE_EXAMPLES)
899   list(APPEND AOM_DIST_APPS $<TARGET_FILE:aomenc>)
900 endif()
902 if(ENABLE_EXAMPLES)
903   foreach(example ${AOM_EXAMPLE_TARGETS})
904     list(APPEND AOM_DIST_EXAMPLES $<TARGET_FILE:${example}>)
905     set_property(TARGET ${example} PROPERTY FOLDER examples)
906   endforeach()
907 endif()
909 if(ENABLE_TOOLS)
910   foreach(tool ${AOM_TOOL_TARGETS})
911     list(APPEND AOM_DIST_TOOLS $<TARGET_FILE:${tool}>)
912     set_property(TARGET ${tool} PROPERTY FOLDER tools)
913   endforeach()
914 endif()
916 if(NOT AOM_DIST_DIR)
917   set(AOM_DIST_DIR "${AOM_CONFIG_DIR}/dist")
918 endif()
920 add_custom_target(dist
921                   COMMAND ${CMAKE_COMMAND}
922                           -DAOM_ROOT=${AOM_ROOT}
923                           -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
924                           -DAOM_DIST_DIR=${AOM_DIST_DIR}
925                           -DAOM_DIST_APPS="${AOM_DIST_APPS}"
926                           -DAOM_DIST_EXAMPLES="${AOM_DIST_EXAMPLES}"
927                           -DAOM_DIST_TOOLS="${AOM_DIST_TOOLS}"
928                           -DAOM_DIST_INCLUDES="${AOM_INSTALL_INCS}"
929                           -DAOM_DIST_LIBS=$<TARGET_FILE:aom>
930                           -DENABLE_DOCS=${ENABLE_DOCS} -P
931                           "${AOM_ROOT}/build/cmake/dist.cmake"
932                   DEPENDS ${AOM_INSTALL_BINS} ${AOM_INSTALL_LIBS}
933                           ${AOM_INSTALL_INCS} ${AOM_EXAMPLE_TARGETS}
934                           ${AOM_TOOL_TARGETS})
936 if(ENABLE_DOCS)
937   add_dependencies(dist docs)
938 endif()
940 # Collect all variables containing libaom source files.
941 get_cmake_property(all_cmake_vars VARIABLES)
942 foreach(var ${all_cmake_vars})
943   if("${var}" MATCHES "SOURCES$\|_INTRIN_\|_ASM_"
944      AND NOT "${var}" MATCHES "DOXYGEN\|LIBYUV\|_PKG_\|TEST"
945      AND NOT "${var}" MATCHES "_ASM_NASM\|_ASM_COMPILER")
946     list(APPEND aom_source_vars ${var})
947   endif()
948 endforeach()
950 if(NOT CONFIG_AV1_DECODER)
951   list(FILTER aom_source_vars EXCLUDE REGEX "_DECODER_")
952 endif()
954 # Libaom_srcs.txt generation.
955 set(libaom_srcs_txt_file "${AOM_CONFIG_DIR}/libaom_srcs.txt")
956 file(WRITE "${libaom_srcs_txt_file}" "# This file is generated. DO NOT EDIT.\n")
958 # Static source file list first.
959 foreach(aom_source_var ${aom_source_vars})
960   foreach(file ${${aom_source_var}})
961     if(NOT "${file}" MATCHES "${AOM_CONFIG_DIR}")
962       string(REPLACE "${AOM_ROOT}/" "" file "${file}")
963       if(NOT CONFIG_AV1_DECODER AND "${file}" MATCHES "aom_decoder")
964         continue()
965       endif()
966       file(APPEND "${libaom_srcs_txt_file}" "${file}\n")
967     endif()
968   endforeach()
969 endforeach()
971 file(APPEND "${libaom_srcs_txt_file}"
972      "# Files below this line are generated by the libaom build system.\n")
973 foreach(aom_source_var ${aom_source_vars})
974   foreach(file ${${aom_source_var}})
975     if("${file}" MATCHES "${AOM_CONFIG_DIR}")
976       string(REPLACE "${AOM_CONFIG_DIR}/" "" file "${file}")
977       file(APPEND "${libaom_srcs_txt_file}" "${file}\n")
978     endif()
979   endforeach()
980 endforeach()
982 # Libaom_srcs.gni generation.
983 set(libaom_srcs_gni_file "${AOM_CONFIG_DIR}/libaom_srcs.gni")
984 file(WRITE "${libaom_srcs_gni_file}" "# This file is generated. DO NOT EDIT.\n")
986 foreach(aom_source_var ${aom_source_vars})
987   if("${${aom_source_var}}" MATCHES "${AOM_ROOT}")
988     string(TOLOWER ${aom_source_var} aom_source_var_lowercase)
989     file(APPEND "${libaom_srcs_gni_file}" "\n${aom_source_var_lowercase} = [\n")
990   endif()
992   foreach(file ${${aom_source_var}})
993     if(NOT "${file}" MATCHES "${AOM_CONFIG_DIR}")
994       string(REPLACE "${AOM_ROOT}" "//third_party/libaom/source/libaom" file
995                      "${file}")
996       if(NOT CONFIG_AV1_DECODER AND "${file}" MATCHES "aom_decoder")
997         continue()
998       endif()
999       file(APPEND "${libaom_srcs_gni_file}" "  \"${file}\",\n")
1000     endif()
1001   endforeach()
1003   if("${${aom_source_var}}" MATCHES "${AOM_ROOT}")
1004     file(APPEND "${libaom_srcs_gni_file}" "]\n")
1005   endif()
1006 endforeach()
1008 file(APPEND "${libaom_srcs_gni_file}"
1009      "\n# Files below this line are generated by the libaom build system.\n")
1011 foreach(aom_source_var ${aom_source_vars})
1012   if("${${aom_source_var}}" MATCHES "${AOM_CONFIG_DIR}")
1013     string(TOLOWER ${aom_source_var} aom_source_var_lowercase)
1014     file(APPEND "${libaom_srcs_gni_file}"
1015          "\n${aom_source_var_lowercase}_gen = [\n")
1016   endif()
1017   foreach(file ${${aom_source_var}})
1018     if(NOT "${file}" MATCHES "${AOM_ROOT}")
1019       string(REPLACE "${AOM_CONFIG_DIR}" "//third_party/libaom/source/libaom"
1020                      file "${file}")
1021       file(APPEND "${libaom_srcs_gni_file}" "  \"${file}\",\n")
1022     endif()
1023   endforeach()
1025   if("${${aom_source_var}}" MATCHES "${AOM_CONFIG_DIR}")
1026     file(APPEND "${libaom_srcs_gni_file}" "]\n")
1027   endif()
1028 endforeach()
1030 # Generate aom.pc and setup install rule.
1031 setup_aom_install_targets()