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