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