Add sse2/avx2 version of aom_v_predictor_wxh()
[aom.git] / CMakeLists.txt
bloba3b20464dcd3af2774c4ea704f9c53bc60f2b477
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
5 ## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 ## was not distributed with this source code in the LICENSE file, you can
7 ## obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 ## Media Patent License 1.0 was not distributed with this source code in the
9 ## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
11 cmake_minimum_required(VERSION 3.5)
13 if (NOT EMSCRIPTEN)
14   if (NOT CMAKE_BUILD_TYPE)
15     set(CMAKE_BUILD_TYPE "Release" CACHE
16       "Build type: Debug, Release, RelWithDebInfo or MinSizeRel" STRING FORCE)
17   endif ()
18 endif ()
20 option(ENABLE_CCACHE "Enable ccache support." OFF)
21 option(ENABLE_DISTCC "Enable distcc support." OFF)
22 option(ENABLE_DOCS "Enable documentation generation (doxygen required)." ON)
23 option(ENABLE_EXAMPLES "Enables build of example code." ON)
24 option(ENABLE_GOMA "Enable goma support." OFF)
25 option(ENABLE_IDE_TEST_HOSTING
26        "Enables running tests within IDEs like Visual Studio and Xcode." OFF)
27 option(ENABLE_NASM "Use nasm instead of yasm for x86 assembly." OFF)
28 option(ENABLE_TOOLS "Enable applications in tools sub directory." ON)
29 option(ENABLE_WERROR "Converts warnings to errors at compile time." OFF)
31 # ARM assembly/intrinsics flags.
32 option(ENABLE_NEON "Enables NEON optimizations on ARM targets." ON)
33 option(ENABLE_NEON_ASM "Enables NEON ASM optimizations on ARM targets." ON)
35 # MIPS assembly/intrinsics flags.
36 option(ENABLE_DSPR2 "Enables DSPR2 optimizations on MIPS targets." OFF)
37 option(ENABLE_MSA "Enables MSA optimizations on MIPS targets." OFF)
39 # x86/x86_64 assembly/intrinsics flags.
40 option(ENABLE_MMX "Enables MMX optimizations on x86/x86_64 targets." ON)
41 option(ENABLE_SSE "Enables SSE optimizations on x86/x86_64 targets." ON)
42 option(ENABLE_SSE2 "Enables SSE2 optimizations on x86/x86_64 targets." ON)
43 option(ENABLE_SSE3 "Enables SSE3 optimizations on x86/x86_64 targets." ON)
44 option(ENABLE_SSSE3 "Enables SSSE3 optimizations on x86/x86_64 targets." ON)
45 option(ENABLE_SSE4_1 "Enables SSE4_1 optimizations on x86/x86_64 targets." ON)
46 option(ENABLE_SSE4_2 "Enables SSE4_2 optimizations on x86/x86_64 targets." ON)
47 option(ENABLE_AVX "Enables AVX optimizations on x86/x86_64 targets." ON)
48 option(ENABLE_AVX2 "Enables AVX2 optimizations on x86/x86_64 targets." ON)
50 # $BUILD_SHARED_LIBS is a CMake built-in-- it's listed here for visibility.
51 option(BUILD_SHARED_LIBS "CMake should generate a shared library build." OFF)
53 project(AOM C CXX)
55 set(AOM_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
56 set(AOM_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
58 if ("${AOM_ROOT}" STREQUAL "${AOM_CONFIG_DIR}")
59   message(FATAL_ERROR
60           "Building from within the aom source tree is not supported.\n"
61           "Hint: Run these commands\n"
62           "$ rm -rf CMakeCache.txt CMakeFiles\n"
63           "$ mkdir -p ../aom_build\n"
64           "$ cd ../aom_build\n"
65           "And re-run CMake from the aom_build directory.")
66 endif ()
68 include("${AOM_ROOT}/build/cmake/aom_configure.cmake")
69 include("${AOM_ROOT}/aom_dsp/aom_dsp.cmake")
70 include("${AOM_ROOT}/aom_mem/aom_mem.cmake")
71 include("${AOM_ROOT}/aom_ports/aom_ports.cmake")
72 include("${AOM_ROOT}/aom_scale/aom_scale.cmake")
73 include("${AOM_ROOT}/aom_util/aom_util.cmake")
74 include("${AOM_ROOT}/av1/av1.cmake")
75 include("${AOM_ROOT}/test/test.cmake")
76 include("${AOM_ROOT}/build/cmake/sanitizers.cmake")
77 include("${AOM_ROOT}/build/cmake/util.cmake")
79 set(AOM_RTCD_SOURCES
80     "${AOM_CONFIG_DIR}/aom_dsp_rtcd.h"
81     "${AOM_CONFIG_DIR}/aom_scale_rtcd.h"
82     "${AOM_CONFIG_DIR}/av1_rtcd.h"
83     "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd_defs.pl"
84     "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd.c"
85     "${AOM_ROOT}/aom_scale/aom_scale_rtcd.pl"
86     "${AOM_ROOT}/aom_scale/aom_scale_rtcd.c"
87     "${AOM_ROOT}/av1/common/av1_rtcd_defs.pl"
88     "${AOM_ROOT}/av1/common/av1_rtcd.c"
89     "${AOM_ROOT}/build/make/rtcd.pl")
91 # TODO(tomfinegan): Use libwebm's cmake support directly.
92 set(AOM_LIBWEBM_SOURCES
93     "${AOM_ROOT}/third_party/libwebm/common/hdr_util.cc"
94     "${AOM_ROOT}/third_party/libwebm/common/hdr_util.h"
95     "${AOM_ROOT}/third_party/libwebm/common/webmids.h"
96     "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxer.cc"
97     "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxer.h"
98     "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxertypes.h"
99     "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxerutil.cc"
100     "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxerutil.h"
101     "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvwriter.cc"
102     "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvwriter.h"
103     "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvparser.cc"
104     "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvparser.h"
105     "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvreader.cc"
106     "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvreader.h")
108 set(AOM_LIBYUV_SOURCES
109     "${AOM_ROOT}/third_party/libyuv/include/libyuv/basic_types.h"
110     "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert.h"
111     "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert_argb.h"
112     "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert_from.h"
113     "${AOM_ROOT}/third_party/libyuv/include/libyuv/cpu_id.h"
114     "${AOM_ROOT}/third_party/libyuv/include/libyuv/planar_functions.h"
115     "${AOM_ROOT}/third_party/libyuv/include/libyuv/rotate.h"
116     "${AOM_ROOT}/third_party/libyuv/include/libyuv/row.h"
117     "${AOM_ROOT}/third_party/libyuv/include/libyuv/scale.h"
118     "${AOM_ROOT}/third_party/libyuv/include/libyuv/scale_row.h"
119     "${AOM_ROOT}/third_party/libyuv/source/cpu_id.cc"
120     "${AOM_ROOT}/third_party/libyuv/source/planar_functions.cc"
121     "${AOM_ROOT}/third_party/libyuv/source/row_any.cc"
122     "${AOM_ROOT}/third_party/libyuv/source/row_common.cc"
123     "${AOM_ROOT}/third_party/libyuv/source/row_gcc.cc"
124     "${AOM_ROOT}/third_party/libyuv/source/row_mips.cc"
125     "${AOM_ROOT}/third_party/libyuv/source/row_neon.cc"
126     "${AOM_ROOT}/third_party/libyuv/source/row_neon64.cc"
127     "${AOM_ROOT}/third_party/libyuv/source/row_win.cc"
128     "${AOM_ROOT}/third_party/libyuv/source/scale.cc"
129     "${AOM_ROOT}/third_party/libyuv/source/scale_any.cc"
130     "${AOM_ROOT}/third_party/libyuv/source/scale_common.cc"
131     "${AOM_ROOT}/third_party/libyuv/source/scale_gcc.cc"
132     "${AOM_ROOT}/third_party/libyuv/source/scale_mips.cc"
133     "${AOM_ROOT}/third_party/libyuv/source/scale_neon.cc"
134     "${AOM_ROOT}/third_party/libyuv/source/scale_neon64.cc"
135     "${AOM_ROOT}/third_party/libyuv/source/scale_win.cc")
137 set(AOM_SOURCES
138     "${AOM_CONFIG_DIR}/aom_config.c"
139     "${AOM_CONFIG_DIR}/aom_config.h"
140     "${AOM_ROOT}/aom/aom.h"
141     "${AOM_ROOT}/aom/aom_codec.h"
142     "${AOM_ROOT}/aom/aom_decoder.h"
143     "${AOM_ROOT}/aom/aom_encoder.h"
144     "${AOM_ROOT}/aom/aom_frame_buffer.h"
145     "${AOM_ROOT}/aom/aom_image.h"
146     "${AOM_ROOT}/aom/aom_integer.h"
147     "${AOM_ROOT}/aom/aomcx.h"
148     "${AOM_ROOT}/aom/aomdx.h"
149     "${AOM_ROOT}/aom/internal/aom_codec_internal.h"
150     "${AOM_ROOT}/aom/src/aom_codec.c"
151     "${AOM_ROOT}/aom/src/aom_decoder.c"
152     "${AOM_ROOT}/aom/src/aom_encoder.c"
153     "${AOM_ROOT}/aom/src/aom_image.c"
154     "${AOM_ROOT}/aom/src/aom_integer.c")
156 set(AOM_COMMON_APP_UTIL_SOURCES
157     "${AOM_ROOT}/args.c"
158     "${AOM_ROOT}/args.h"
159     "${AOM_ROOT}/md5_utils.c"
160     "${AOM_ROOT}/md5_utils.h"
161     "${AOM_ROOT}/tools_common.c"
162     "${AOM_ROOT}/tools_common.h"
163     "${AOM_ROOT}/video_common.h"
164     "${AOM_ROOT}/y4menc.c"
165     "${AOM_ROOT}/y4menc.h")
167 set(AOM_DECODER_APP_UTIL_SOURCES
168     "${AOM_ROOT}/ivfdec.c"
169     "${AOM_ROOT}/ivfdec.h"
170     "${AOM_ROOT}/video_reader.c"
171     "${AOM_ROOT}/video_reader.h")
173 if (CONFIG_OBU_NO_IVF)
174   list(APPEND AOM_DECODER_APP_UTIL_SOURCES "${AOM_ROOT}/obudec.c" "${AOM_ROOT}/obudec.h")
175 endif ()
177 set(AOM_ENCODER_APP_UTIL_SOURCES
178     "${AOM_ROOT}/ivfenc.c"
179     "${AOM_ROOT}/ivfenc.h"
180     "${AOM_ROOT}/video_writer.c"
181     "${AOM_ROOT}/video_writer.h"
182     "${AOM_ROOT}/warnings.c"
183     "${AOM_ROOT}/warnings.h"
184     "${AOM_ROOT}/y4minput.c"
185     "${AOM_ROOT}/y4minput.h"
186     "${AOM_ROOT}/examples/encoder_util.h"
187     "${AOM_ROOT}/examples/encoder_util.c")
189 set(AOM_ENCODER_STATS_SOURCES
190     "${AOM_ROOT}/aomstats.c"
191     "${AOM_ROOT}/aomstats.h"
192     "${AOM_ROOT}/rate_hist.c"
193     "${AOM_ROOT}/rate_hist.h")
195 set(AOM_PKG_CONFIG_SOURCES "${AOM_CONFIG_DIR}/aom.pc")
197 set(AOM_VERSION_SOURCES "${AOM_CONFIG_DIR}/aom_version.h")
199 set(AOM_WEBM_DECODER_SOURCES
200     "${AOM_ROOT}/webmdec.cc"
201     "${AOM_ROOT}/webmdec.h")
203 set(AOM_WEBM_ENCODER_SOURCES
204     "${AOM_ROOT}/webmenc.cc"
205     "${AOM_ROOT}/webmenc.h")
207 include_directories(${AOM_ROOT} ${AOM_CONFIG_DIR})
209 # Targets
210 add_library(aom_version ${AOM_VERSION_SOURCES})
211 add_dummy_source_file_to_target(aom_version c)
212 add_custom_command(
213   OUTPUT "${AOM_CONFIG_DIR}/aom_version.h"
214   COMMAND ${CMAKE_COMMAND}
215   ARGS -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
216     -DAOM_ROOT=${AOM_ROOT}
217     -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
218     -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
219     -P "${AOM_ROOT}/build/cmake/version.cmake"
220   COMMENT "Writing aom_version.h"
221   VERBATIM)
223 add_custom_target(aom_version_check
224   COMMAND ${CMAKE_COMMAND}
225     -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
226     -DAOM_ROOT=${AOM_ROOT}
227     -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
228     -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
229     -P "${AOM_ROOT}/build/cmake/version.cmake"
230   COMMENT "Updating version info if necessary."
231   VERBATIM)
232 add_dependencies(aom_version aom_version_check)
234 if (NOT MSVC)
235   add_library(aom_pc ${AOM_PKG_CONFIG_SOURCES})
236   add_dummy_source_file_to_target(aom_pc c)
237   add_custom_command(
238     OUTPUT "${AOM_CONFIG_DIR}/aom.pc"
239     COMMAND ${CMAKE_COMMAND}
240     ARGS -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
241       -DAOM_ROOT=${AOM_ROOT}
242       -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
243       -DCMAKE_PROJECT_NAME=${CMAKE_PROJECT_NAME}
244       -DCONFIG_MULTITHREAD=${CONFIG_MULTITHREAD}
245       -DHAVE_PTHREAD_H=${HAVE_PTHREAD_H}
246       -P "${AOM_ROOT}/build/cmake/pkg_config.cmake"
247       COMMENT "Writing aom.pc"
248       VERBATIM)
249   add_dependencies(aom_pc aom_version)
250 endif ()
252 # TODO(tomfinegan): Move rtcd target setup where it belongs for each rtcd
253 # source.
254 add_rtcd_build_step("${AOM_ROOT}/aom_dsp/aom_dsp_rtcd_defs.pl"
255                     "${AOM_CONFIG_DIR}/aom_dsp_rtcd.h"
256                     "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd.c"
257                     "aom_dsp_rtcd")
258 add_rtcd_build_step("${AOM_ROOT}/aom_scale/aom_scale_rtcd.pl"
259                     "${AOM_CONFIG_DIR}/aom_scale_rtcd.h"
260                     "${AOM_ROOT}/aom_scale/aom_scale_rtcd.c"
261                     "aom_scale_rtcd")
262 add_rtcd_build_step("${AOM_ROOT}/av1/common/av1_rtcd_defs.pl"
263                     "${AOM_CONFIG_DIR}/av1_rtcd.h"
264                     "${AOM_ROOT}/av1/common/av1_rtcd.c"
265                     "av1_rtcd")
267 add_library(aom_rtcd OBJECT ${AOM_RTCD_SOURCES})
268 add_dependencies(aom_rtcd aom_version)
270 add_library(aom_encoder_stats OBJECT ${AOM_ENCODER_STATS_SOURCES})
271 add_library(aom ${AOM_SOURCES} $<TARGET_OBJECTS:aom_rtcd>)
273 if (NOT MSVC AND NOT APPLE)
274   target_link_libraries(aom ${AOM_LIB_LINK_TYPE} m)
275 endif ()
277 # List of object and static library targets.
278 set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_rtcd aom_encoder_stats aom_mem
279     aom_scale aom)
281 # Setup dependencies.
282 setup_aom_dsp_targets()
283 setup_aom_mem_targets()
284 setup_aom_ports_targets()
285 setup_aom_util_targets()
286 setup_aom_scale_targets()
287 setup_av1_targets()
289 # Make all library targets depend on aom_rtcd to make sure it builds first.
290 foreach (aom_lib ${AOM_LIB_TARGETS})
291   if (NOT "${aom_lib}" STREQUAL "aom_rtcd")
292     add_dependencies(${aom_lib} aom_rtcd)
293   endif ()
294 endforeach ()
296 # Generate C/C++ stub files containing the function usage_exit(). Users of the
297 # aom_common_app_util library must define this function. This is a convenience
298 # to allow omission of the function from applications that might want to use
299 # other pieces of the util support without defining usage_exit().
300 file(WRITE "${AOM_CONFIG_DIR}/usage_exit.c" "void usage_exit(void) {}")
301 file(WRITE "${AOM_CONFIG_DIR}/usage_exit.cc"
302      "extern \"C\" void usage_exit(void) {}")
305 # Application and application support targets.
307 if (CONFIG_UNIT_TESTS OR ENABLE_EXAMPLES OR ENABLE_TOOLS)
308   add_library(aom_common_app_util OBJECT ${AOM_COMMON_APP_UTIL_SOURCES})
309   if (CONFIG_AV1_DECODER)
310     add_library(aom_decoder_app_util OBJECT ${AOM_DECODER_APP_UTIL_SOURCES})
311     # obudec depends on internal headers that require *rtcd.h
312     if (CONFIG_OBU_NO_IVF)
313       add_dependencies(aom_decoder_app_util aom_rtcd)
314     endif ()
315   endif ()
316   if (CONFIG_AV1_ENCODER)
317     add_library(aom_encoder_app_util OBJECT ${AOM_ENCODER_APP_UTIL_SOURCES})
318   endif ()
319 endif ()
321 if (CONFIG_AV1_DECODER AND ENABLE_EXAMPLES)
322   add_executable(aomdec
323                  "${AOM_ROOT}/aomdec.c"
324                  $<TARGET_OBJECTS:aom_common_app_util>
325                  $<TARGET_OBJECTS:aom_decoder_app_util>)
326   add_executable(decode_to_md5
327                  "${AOM_ROOT}/examples/decode_to_md5.c"
328                  $<TARGET_OBJECTS:aom_common_app_util>
329                  $<TARGET_OBJECTS:aom_decoder_app_util>)
330   add_executable(decode_with_drops
331                  "${AOM_ROOT}/examples/decode_with_drops.c"
332                  $<TARGET_OBJECTS:aom_common_app_util>
333                  $<TARGET_OBJECTS:aom_decoder_app_util>)
334   add_executable(simple_decoder
335                  "${AOM_ROOT}/examples/simple_decoder.c"
336                  $<TARGET_OBJECTS:aom_common_app_util>
337                  $<TARGET_OBJECTS:aom_decoder_app_util>)
338   if (CONFIG_SCALABILITY)
339     add_executable(scalable_decoder
340                    "${AOM_ROOT}/examples/scalable_decoder.c"
341                    $<TARGET_OBJECTS:aom_common_app_util>
342                    $<TARGET_OBJECTS:aom_decoder_app_util>)
343   endif ()
345   if (CONFIG_ANALYZER)
346     add_executable(analyzer
347                    "${AOM_ROOT}/examples/analyzer.cc"
348                    $<TARGET_OBJECTS:aom_common_app_util>
349                    $<TARGET_OBJECTS:aom_decoder_app_util>)
350     target_link_libraries(analyzer
351                           ${AOM_LIB_LINK_TYPE} ${wxWidgets_LIBRARIES})
352     set(AOM_APP_TARGETS ${AOM_APP_TARGETS} analyzer)
353     set(AOM_DECODER_EXAMPLE_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS} analyzer)
354   endif ()
356   if (CONFIG_INSPECTION)
357     add_executable(inspect
358                    "${AOM_ROOT}/examples/inspect.c"
359                    $<TARGET_OBJECTS:aom_common_app_util>
360                    $<TARGET_OBJECTS:aom_decoder_app_util>)
361     set(AOM_DECODER_EXAMPLE_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS} inspect)
363     if (EMSCRIPTEN)
364       add_preproc_definition(_POSIX_SOURCE)
365       append_link_flag_to_target("inspect" "-s TOTAL_MEMORY=402653184")
366       append_link_flag_to_target("inspect" "-s MODULARIZE=1")
367       append_link_flag_to_target("inspect"
368                                  "-s EXPORT_NAME=\"\'DecoderModule\'\"")
369       append_link_flag_to_target("inspect" "--memory-init-file 0")
371       if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
372         # Default to -O3 when no build type specified.
373         append_compiler_flag("-O3")
374       endif ()
376       em_link_post_js(inspect "${AOM_ROOT}/tools/inspect-post.js")
377     endif ()
378   endif ()
380   # Maintain a list of decoder example targets.
381   set(AOM_DECODER_EXAMPLE_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS}
382       aomdec decode_to_md5 decode_with_drops simple_decoder)
384   if (CONFIG_SCALABILITY)
385     set(AOM_DECODER_EXAMPLE_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS}
386         scalable_decoder)
387   endif ()
389   # Add decoder examples to the app targets list.
390   set(AOM_APP_TARGETS ${AOM_APP_TARGETS} ${AOM_DECODER_EXAMPLE_TARGETS})
391 endif ()
393 if (CONFIG_AV1_ENCODER)
394   if (ENABLE_EXAMPLES)
395     add_executable(aomenc
396                    "${AOM_ROOT}/aomenc.c"
397                    $<TARGET_OBJECTS:aom_common_app_util>
398                    $<TARGET_OBJECTS:aom_encoder_app_util>
399                    $<TARGET_OBJECTS:aom_encoder_stats>)
400     add_executable(lossless_encoder
401                    "${AOM_ROOT}/examples/lossless_encoder.c"
402                    $<TARGET_OBJECTS:aom_common_app_util>
403                    $<TARGET_OBJECTS:aom_encoder_app_util>)
404     add_executable(set_maps
405                    "${AOM_ROOT}/examples/set_maps.c"
406                    $<TARGET_OBJECTS:aom_common_app_util>
407                    $<TARGET_OBJECTS:aom_encoder_app_util>)
408     add_executable(simple_encoder
409                    "${AOM_ROOT}/examples/simple_encoder.c"
410                    $<TARGET_OBJECTS:aom_common_app_util>
411                    $<TARGET_OBJECTS:aom_encoder_app_util>)
412     add_executable(twopass_encoder
413                    "${AOM_ROOT}/examples/twopass_encoder.c"
414                    $<TARGET_OBJECTS:aom_common_app_util>
415                    $<TARGET_OBJECTS:aom_encoder_app_util>)
416     if (CONFIG_SCALABILITY)
417       add_executable(scalable_encoder
418                      "${AOM_ROOT}/examples/scalable_encoder.c"
419                      $<TARGET_OBJECTS:aom_common_app_util>
420                      $<TARGET_OBJECTS:aom_encoder_app_util>)
421     endif ()
423     # Maintain a list of encoder example targets.
424     set(AOM_ENCODER_EXAMPLE_TARGETS
425         aomenc lossless_encoder set_maps simple_encoder twopass_encoder)
427     if (CONFIG_SCALABILITY)
428       set(AOM_ENCODER_EXAMPLE_TARGETS ${AOM_ENCODER_EXAMPLE_TARGETS}
429           scalable_encoder)
430     endif ()
432   endif ()
434   if (ENABLE_TOOLS)
435     if (CONFIG_ENTROPY_STATS AND NOT BUILD_SHARED_LIBS)
436       # TODO(tomfinegan): Sort out why a simple link command with
437       # aom_entropy_optimizer.c won't work on macos, but dragging in all the
438       # helper machinery allows the link to succeed.
439       add_executable(aom_entropy_optimizer
440                      "${AOM_CONFIG_DIR}/usage_exit.c"
441                      "${AOM_ROOT}/tools/aom_entropy_optimizer.c"
442                      $<TARGET_OBJECTS:aom_common_app_util>
443                      $<TARGET_OBJECTS:aom_encoder_app_util>)
445       # Maintain a list of encoder tool targets.
446       set(AOM_ENCODER_TOOL_TARGETS
447           ${AOM_ENCODER_TOOL_TARGETS} aom_entropy_optimizer)
448     endif ()
449   endif ()
451   # Add encoder examples and tools to the targets list.
452   set(AOM_APP_TARGETS ${AOM_APP_TARGETS}
453       ${AOM_ENCODER_EXAMPLE_TARGETS} ${AOM_ENCODER_TOOL_TARGETS})
454 endif ()
456 if (ENABLE_EXAMPLES)
457   # Maintain a separate variable listing only the examples to facilitate
458   # installation of example programs into an examples sub directory of
459   # $AOM_DIST_DIR/bin when building the dist target.
460   set(AOM_EXAMPLE_TARGETS
461       ${AOM_DECODER_EXAMPLE_TARGETS} ${AOM_ENCODER_EXAMPLE_TARGETS})
462 endif ()
464 if (ENABLE_TOOLS)
465   if (CONFIG_AV1_DECODER)
466     require_cxx_flag_nomsvc("-std=c++11" NO)
467     add_executable(dump_obu
468                    "${AOM_CONFIG_DIR}/usage_exit.cc"
469                    "${AOM_ROOT}/tools/dump_obu.cc"
470                    "${AOM_ROOT}/tools/obu_parser.cc"
471                    "${AOM_ROOT}/tools/obu_parser.h"
472                    $<TARGET_OBJECTS:aom_common_app_util>
473                    $<TARGET_OBJECTS:aom_decoder_app_util>)
475     list(APPEND AOM_TOOL_TARGETS dump_obu)
476     list(APPEND AOM_APP_TARGETS dump_obu)
478     if (NOT MSVC)
479       target_compile_options(dump_obu PUBLIC -std=c++11)
480       # TODO(tomfinegan): This can go once the GCC pragma in libwebm is updated
481       # to silence the auto_ptr warnings for GCC >= v4.
482       target_compile_options(dump_obu PUBLIC -Wno-deprecated-declarations)
483     endif ()
485     # Maintain a separate variable listing only the examples to facilitate
486     # installation of example programs into an tools sub directory of
487     # $AOM_DIST_DIR/bin when building the dist target.
488     list(APPEND AOM_TOOL_TARGETS
489          ${AOM_DECODER_TOOL_TARGETS} ${AOM_ENCODER_TOOL_TARGETS})
490   endif ()
491 endif ()
493 if (ENABLE_EXAMPLES AND CONFIG_AV1_DECODER AND CONFIG_AV1_ENCODER)
494   add_executable(aom_cx_set_ref
495                  "${AOM_ROOT}/examples/aom_cx_set_ref.c"
496                  $<TARGET_OBJECTS:aom_common_app_util>
497                  $<TARGET_OBJECTS:aom_encoder_app_util>)
498   set(AOM_EXAMPLE_TARGETS ${AOM_EXAMPLE_TARGETS} aom_cx_set_ref)
499   set(AOM_APP_TARGETS ${AOM_APP_TARGETS} aom_cx_set_ref)
500 endif ()
502 foreach (aom_app ${AOM_APP_TARGETS})
503   target_link_libraries(${aom_app} ${AOM_LIB_LINK_TYPE} aom)
504 endforeach ()
506 if (CONFIG_UNIT_TESTS OR ENABLE_EXAMPLES OR ENABLE_TOOLS)
507   if (CONFIG_LIBYUV)
508     add_library(yuv OBJECT ${AOM_LIBYUV_SOURCES})
509     if (NOT MSVC)
510       target_compile_options(yuv PRIVATE -Wno-unused-parameter)
511     endif ()
512     include_directories("${AOM_ROOT}/third_party/libyuv/include")
514     # Add to existing targets.
515     foreach (aom_app ${AOM_APP_TARGETS})
516       target_sources(${aom_app} PRIVATE $<TARGET_OBJECTS:yuv>)
517       set_property(TARGET ${aom_app} PROPERTY LINKER_LANGUAGE CXX)
518     endforeach ()
519   endif ()
521   if (CONFIG_WEBM_IO)
522     add_library(webm OBJECT ${AOM_LIBWEBM_SOURCES})
523     include_directories("${AOM_ROOT}/third_party/libwebm")
524     target_compile_definitions(webm PRIVATE __STDC_CONSTANT_MACROS)
525     target_compile_definitions(webm PRIVATE __STDC_LIMIT_MACROS)
527     if (NOT MSVC)
528       target_compile_options(webm PRIVATE -Wno-shadow)
529     endif ()
531     # Add to existing targets.
532     if (CONFIG_AV1_DECODER)
533       target_sources(aom_decoder_app_util PRIVATE ${AOM_WEBM_DECODER_SOURCES})
534     endif ()
536     if (CONFIG_AV1_ENCODER)
537       target_sources(aom_encoder_app_util PRIVATE ${AOM_WEBM_ENCODER_SOURCES})
538     endif ()
540     foreach (aom_app ${AOM_APP_TARGETS})
541       target_sources(${aom_app} PRIVATE $<TARGET_OBJECTS:webm>)
542       set_property(TARGET ${aom_app} PROPERTY LINKER_LANGUAGE CXX)
543      endforeach ()
544   endif ()
545 endif ()
547 if (CONFIG_UNIT_TESTS)
548   # Create test_libaom target and the targets it depends on.
549   setup_aom_test_targets()
550 endif ()
552 if (HAVE_PTHREAD_H AND CONFIG_MULTITHREAD)
553   find_package(Threads)
554   foreach (app_target ${AOM_APP_TARGETS})
555     target_link_libraries(${app_target} ${AOM_LIB_LINK_TYPE} Threads::Threads)
556   endforeach ()
557 endif ()
559 if (XCODE)
560   # TODO(tomfinegan): Make sure target has no C++ files before doing this as
561   # it's not necessary in that case.
562   if (CONFIG_LIBYUV OR CONFIG_WEBM_IO)
563     # The Xcode generator does not obey LINKER_LANGUAGE. Because of the issue
564     # what looks like a C++ file needs to be in any target that Xcode will link
565     # when the target contains a C++ dependency.
566     # Without this Xcode will try to link with the C linker, which always ends
567     # badly when a dependency actually includes C++.
568     # Note: LINKER_LANGUAGE is explicitly set to C++ for all targets touched
569     # here, it really is the Xcode generator's fault, or just a deficiency in
570     # Xcode itself.
571     foreach (aom_app ${AOM_APP_TARGETS})
572       add_dummy_source_file_to_target("${aom_app}" "cc")
573     endforeach ()
574   endif ()
575 endif ()
577 if (ENABLE_EXAMPLES AND "${CMAKE_GENERATOR}" MATCHES "Makefiles$")
578   # For historical purposes place the example binaries in the example directory.
579   file(MAKE_DIRECTORY "${AOM_CONFIG_DIR}/examples")
581   foreach (target ${AOM_EXAMPLE_TARGETS})
582     if (NOT "${target}" MATCHES "aomdec\|aomenc")
583       set_target_properties(${target} PROPERTIES
584                             RUNTIME_OUTPUT_DIRECTORY
585                             "${AOM_CONFIG_DIR}/examples")
586     endif ()
587   endforeach ()
589   if (ENABLE_TOOLS AND AOM_TOOL_TARGETS)
590     # The same expectation is true for tool targets.
591     file(MAKE_DIRECTORY "${AOM_CONFIG_DIR}/tools")
592     set_target_properties(${AOM_TOOL_TARGETS} PROPERTIES
593                           RUNTIME_OUTPUT_DIRECTORY "${AOM_CONFIG_DIR}/tools")
594   endif ()
595 endif ()
597 if (BUILD_SHARED_LIBS)
598   include("${AOM_ROOT}/build/cmake/exports.cmake")
599   setup_exports_target()
600   set_target_properties(aom PROPERTIES SOVERSION 0)
601 endif ()
603 # Handle user supplied compile and link flags last to ensure they're obeyed.
604 set_user_flags()
606 # Aomedia documentation rule.
607 if (ENABLE_DOCS)
608   include(FindDoxygen)
609   if (DOXYGEN_FOUND)
610     include("${AOM_ROOT}/docs.cmake")
611     setup_documentation_targets()
612   else ()
613     message("--- Cannot find doxygen, ENABLE_DOCS turned off.")
614     set(ENABLE_DOCS OFF)
615   endif ()
616 endif ()
618 # Aomedia install rule.
619 set(AOM_INSTALL_INCS
620     "${AOM_ROOT}/aom/aom.h"
621     "${AOM_ROOT}/aom/aom_codec.h"
622     "${AOM_ROOT}/aom/aom_frame_buffer.h"
623     "${AOM_ROOT}/aom/aom_image.h"
624     "${AOM_ROOT}/aom/aom_integer.h"
625     "${AOM_ROOT}/aom/aom.h")
627 if (CONFIG_AV1_DECODER)
628   if (ENABLE_EXAMPLES)
629     set(AOM_INSTALL_BINS ${AOM_INSTALL_BINS} aomdec)
630   endif ()
632   set(AOM_INSTALL_INCS
633       ${AOM_INSTALL_INCS}
634       "${AOM_ROOT}/aom/aom_decoder.h"
635       "${AOM_ROOT}/aom/aomdx.h")
636 endif ()
638 if (CONFIG_AV1_ENCODER)
639   if (ENABLE_EXAMPLES)
640     set(AOM_INSTALL_BINS ${AOM_INSTALL_BINS} aomenc)
641   endif ()
643   set(AOM_INSTALL_INCS
644       ${AOM_INSTALL_INCS}
645       "${AOM_ROOT}/aom/aomcx.h"
646       "${AOM_ROOT}/aom/aom_encoder.h")
647 endif ()
649 set(AOM_INSTALL_LIBS aom)
651 install(FILES ${AOM_INSTALL_INCS}
652         DESTINATION "${CMAKE_INSTALL_PREFIX}/include/aom")
653 install(FILES "${AOM_CONFIG_DIR}/aom.pc"
654         DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
655 install(TARGETS ${AOM_INSTALL_LIBS} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
657 if (ENABLE_EXAMPLES)
658   install(TARGETS ${AOM_INSTALL_BINS} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
659 endif ()
661 # Aomedia dist rule.
662 if (CONFIG_AV1_DECODER AND ENABLE_EXAMPLES)
663   set(AOM_DIST_APPS ${AOM_DIST_APPS} $<TARGET_FILE:aomdec>)
664 endif ()
665 if (CONFIG_AV1_ENCODER AND ENABLE_EXAMPLES)
666   set(AOM_DIST_APPS ${AOM_DIST_APPS} $<TARGET_FILE:aomenc>)
667 endif ()
669 if (ENABLE_EXAMPLES)
670   foreach (example ${AOM_EXAMPLE_TARGETS})
671     list(APPEND AOM_DIST_EXAMPLES $<TARGET_FILE:${example}>)
672   endforeach ()
673 endif ()
675 if (ENABLE_TOOLS)
676   foreach (tool ${AOM_TOOL_TARGETS})
677     list(APPEND AOM_DIST_TOOLS $<TARGET_FILE:${tool}>)
678   endforeach ()
679 endif ()
681 if (NOT AOM_DIST_DIR)
682   set(AOM_DIST_DIR "${AOM_CONFIG_DIR}/dist")
683 endif ()
685 add_custom_target(dist
686                   COMMAND ${CMAKE_COMMAND}
687                   -DAOM_ROOT=${AOM_ROOT}
688                   -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
689                   -DAOM_DIST_DIR=${AOM_DIST_DIR}
690                   -DAOM_DIST_APPS="${AOM_DIST_APPS}"
691                   -DAOM_DIST_EXAMPLES="${AOM_DIST_EXAMPLES}"
692                   -DAOM_DIST_TOOLS="${AOM_DIST_TOOLS}"
693                   -DAOM_DIST_INCLUDES="${AOM_INSTALL_INCS}"
694                   -DAOM_DIST_LIBS=$<TARGET_FILE:aom>
695                   -DENABLE_DOCS=${ENABLE_DOCS}
696                   -P "${AOM_ROOT}/build/cmake/dist.cmake"
697                   DEPENDS ${AOM_INSTALL_BINS} ${AOM_INSTALL_LIBS}
698                   ${AOM_INSTALL_INCS} ${AOM_EXAMPLE_TARGETS}
699                   ${AOM_TOOL_TARGETS})
701 if (ENABLE_DOCS)
702   add_dependencies(dist docs)
703 endif ()
705 # Collect all variables containing libaom source files.
706 get_cmake_property(all_cmake_vars VARIABLES)
707 foreach (var ${all_cmake_vars})
708   if ("${var}" MATCHES "SOURCES$\|_INTRIN_\|_ASM_" AND NOT
709       "${var}" MATCHES "_APP_\|DOXYGEN\|LIBWEBM\|LIBYUV\|_PKG_\|TEST")
710     list(APPEND aom_source_vars ${var})
711   endif ()
712 endforeach ()
714 # Libaom_srcs.txt generation.
715 set(libaom_srcs_txt_file "${AOM_CONFIG_DIR}/libaom_srcs.txt")
716 file(WRITE "${libaom_srcs_txt_file}" "# This file is generated. DO NOT EDIT.\n")
718 # Static source file list first.
719 foreach (aom_source_var ${aom_source_vars})
720   foreach (file ${${aom_source_var}})
721     if (NOT "${file}" MATCHES "${AOM_CONFIG_DIR}")
722       string(REPLACE "${AOM_ROOT}/" "" file "${file}")
723       file(APPEND "${libaom_srcs_txt_file}" "${file}\n")
724     endif ()
725   endforeach ()
726 endforeach ()
728 file(APPEND "${libaom_srcs_txt_file}"
729      "# Files below this line are generated by the libaom build system.\n")
730 foreach (aom_source_var ${aom_source_vars})
731   foreach (file ${${aom_source_var}})
732     if ("${file}" MATCHES "${AOM_CONFIG_DIR}")
733       string(REPLACE "${AOM_CONFIG_DIR}/" "" file "${file}")
734       file(APPEND "${libaom_srcs_txt_file}" "${file}\n")
735     endif ()
736   endforeach ()
737 endforeach ()
739 # Libaom_srcs.gni generation.
740 set(libaom_srcs_gni_file "${AOM_CONFIG_DIR}/libaom_srcs.gni")
741 file(WRITE "${libaom_srcs_gni_file}" "# This file is generated. DO NOT EDIT.\n")
743 foreach (aom_source_var ${aom_source_vars})
744   if ("${${aom_source_var}}" MATCHES "${AOM_ROOT}")
745     string(TOLOWER ${aom_source_var} aom_source_var_lowercase)
746     file(APPEND "${libaom_srcs_gni_file}" "\n${aom_source_var_lowercase} = [\n")
747   endif ()
749   foreach (file ${${aom_source_var}})
750     if (NOT "${file}" MATCHES "${AOM_CONFIG_DIR}")
751       string(REPLACE "${AOM_ROOT}" "//third_party/aom/src" file "${file}")
752       file(APPEND "${libaom_srcs_gni_file}" "  \"${file}\",\n")
753     endif ()
754   endforeach ()
756   if ("${${aom_source_var}}" MATCHES "${AOM_ROOT}")
757     file(APPEND "${libaom_srcs_gni_file}" "]\n")
758   endif ()
759 endforeach ()
761 file(APPEND "${libaom_srcs_gni_file}"
762      "\n# Files below this line are generated by the libaom build system.\n")
764 foreach (aom_source_var ${aom_source_vars})
765   if ("${${aom_source_var}}" MATCHES "${AOM_CONFIG_DIR}")
766     string(TOLOWER ${aom_source_var} aom_source_var_lowercase)
767     file(APPEND "${libaom_srcs_gni_file}"
768          "\n${aom_source_var_lowercase}_gen = [\n")
769   endif ()
770   foreach (file ${${aom_source_var}})
771     if (NOT "${file}" MATCHES "${AOM_ROOT}")
772       string(REPLACE "${AOM_CONFIG_DIR}" "//third_party/aom/src" file "${file}")
773       file(APPEND "${libaom_srcs_gni_file}" "  \"${file}\",\n")
774     endif ()
775   endforeach ()
777   if ("${${aom_source_var}}" MATCHES "${AOM_CONFIG_DIR}")
778     file(APPEND "${libaom_srcs_gni_file}" "]\n")
779   endif ()
780 endforeach ()