av1_convolve_ x,y _avx2() -- use 256 bit load/store
[aom.git] / CMakeLists.txt
blobc10e33c38a3459871fc17e33686de794c382bd71
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_ADOPTED_EXPERIMENTS "Enable adopted experiments." ON)
21 option(ENABLE_CCACHE "Enable ccache support." OFF)
22 option(ENABLE_DISTCC "Enable distcc support." OFF)
23 option(ENABLE_DOCS "Enable documentation generation (doxygen required)." ON)
24 option(ENABLE_EXAMPLES "Enables build of example code." ON)
25 option(ENABLE_GOMA "Enable goma support." OFF)
26 option(ENABLE_IDE_TEST_HOSTING
27        "Enables running tests within IDEs like Visual Studio and Xcode." OFF)
28 option(ENABLE_NASM "Use nasm instead of yasm for x86 assembly." OFF)
29 option(ENABLE_TOOLS "Enable applications in tools sub directory." ON)
30 option(ENABLE_WERROR "Converts warnings to errors at compile time." OFF)
32 # ARM assembly/intrinsics flags.
33 option(ENABLE_NEON "Enables NEON optimizations on ARM targets." ON)
34 option(ENABLE_NEON_ASM "Enables NEON ASM optimizations on ARM targets." ON)
36 # MIPS assembly/intrinsics flags.
37 option(ENABLE_DSPR2 "Enables DSPR2 optimizations on MIPS targets." OFF)
38 option(ENABLE_MSA "Enables MSA optimizations on MIPS targets." OFF)
40 # x86/x86_64 assembly/intrinsics flags.
41 option(ENABLE_MMX "Enables MMX optimizations on x86/x86_64 targets." ON)
42 option(ENABLE_SSE "Enables SSE optimizations on x86/x86_64 targets." ON)
43 option(ENABLE_SSE2 "Enables SSE2 optimizations on x86/x86_64 targets." ON)
44 option(ENABLE_SSE3 "Enables SSE3 optimizations on x86/x86_64 targets." ON)
45 option(ENABLE_SSSE3 "Enables SSSE3 optimizations on x86/x86_64 targets." ON)
46 option(ENABLE_SSE4_1 "Enables SSE4_1 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: mkdir -p ../aom_build && cd ../aom_build\n"
62           "Run cmake from there.")
63 endif ()
65 include("${AOM_ROOT}/build/cmake/aom_configure.cmake")
66 include("${AOM_ROOT}/aom_dsp/aom_dsp.cmake")
67 include("${AOM_ROOT}/aom_mem/aom_mem.cmake")
68 include("${AOM_ROOT}/aom_ports/aom_ports.cmake")
69 include("${AOM_ROOT}/aom_scale/aom_scale.cmake")
70 include("${AOM_ROOT}/aom_util/aom_util.cmake")
71 include("${AOM_ROOT}/av1/av1.cmake")
72 include("${AOM_ROOT}/test/test.cmake")
73 include("${AOM_ROOT}/build/cmake/sanitizers.cmake")
74 include("${AOM_ROOT}/build/cmake/util.cmake")
76 set(AOM_RTCD_SOURCES
77     "${AOM_CONFIG_DIR}/aom_dsp_rtcd.h"
78     "${AOM_CONFIG_DIR}/aom_scale_rtcd.h"
79     "${AOM_CONFIG_DIR}/av1_rtcd.h"
80     "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd_defs.pl"
81     "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd.c"
82     "${AOM_ROOT}/aom_scale/aom_scale_rtcd.pl"
83     "${AOM_ROOT}/aom_scale/aom_scale_rtcd.c"
84     "${AOM_ROOT}/av1/common/av1_rtcd_defs.pl"
85     "${AOM_ROOT}/av1/common/av1_rtcd.c"
86     "${AOM_ROOT}/build/make/rtcd.pl")
88 # TODO(tomfinegan): Use libwebm's cmake support directly.
89 set(AOM_LIBWEBM_SOURCES
90     "${AOM_ROOT}/third_party/libwebm/common/hdr_util.cc"
91     "${AOM_ROOT}/third_party/libwebm/common/hdr_util.h"
92     "${AOM_ROOT}/third_party/libwebm/common/webmids.h"
93     "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxer.cc"
94     "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxer.h"
95     "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxertypes.h"
96     "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxerutil.cc"
97     "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvmuxerutil.h"
98     "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvwriter.cc"
99     "${AOM_ROOT}/third_party/libwebm/mkvmuxer/mkvwriter.h"
100     "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvparser.cc"
101     "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvparser.h"
102     "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvreader.cc"
103     "${AOM_ROOT}/third_party/libwebm/mkvparser/mkvreader.h")
105 set(AOM_LIBYUV_SOURCES
106     "${AOM_ROOT}/third_party/libyuv/include/libyuv/basic_types.h"
107     "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert.h"
108     "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert_argb.h"
109     "${AOM_ROOT}/third_party/libyuv/include/libyuv/convert_from.h"
110     "${AOM_ROOT}/third_party/libyuv/include/libyuv/cpu_id.h"
111     "${AOM_ROOT}/third_party/libyuv/include/libyuv/planar_functions.h"
112     "${AOM_ROOT}/third_party/libyuv/include/libyuv/rotate.h"
113     "${AOM_ROOT}/third_party/libyuv/include/libyuv/row.h"
114     "${AOM_ROOT}/third_party/libyuv/include/libyuv/scale.h"
115     "${AOM_ROOT}/third_party/libyuv/include/libyuv/scale_row.h"
116     "${AOM_ROOT}/third_party/libyuv/source/cpu_id.cc"
117     "${AOM_ROOT}/third_party/libyuv/source/planar_functions.cc"
118     "${AOM_ROOT}/third_party/libyuv/source/row_any.cc"
119     "${AOM_ROOT}/third_party/libyuv/source/row_common.cc"
120     "${AOM_ROOT}/third_party/libyuv/source/row_gcc.cc"
121     "${AOM_ROOT}/third_party/libyuv/source/row_mips.cc"
122     "${AOM_ROOT}/third_party/libyuv/source/row_neon.cc"
123     "${AOM_ROOT}/third_party/libyuv/source/row_neon64.cc"
124     "${AOM_ROOT}/third_party/libyuv/source/row_win.cc"
125     "${AOM_ROOT}/third_party/libyuv/source/scale.cc"
126     "${AOM_ROOT}/third_party/libyuv/source/scale_any.cc"
127     "${AOM_ROOT}/third_party/libyuv/source/scale_common.cc"
128     "${AOM_ROOT}/third_party/libyuv/source/scale_gcc.cc"
129     "${AOM_ROOT}/third_party/libyuv/source/scale_mips.cc"
130     "${AOM_ROOT}/third_party/libyuv/source/scale_neon.cc"
131     "${AOM_ROOT}/third_party/libyuv/source/scale_neon64.cc"
132     "${AOM_ROOT}/third_party/libyuv/source/scale_win.cc")
134 set(AOM_SOURCES
135     "${AOM_CONFIG_DIR}/aom_config.c"
136     "${AOM_CONFIG_DIR}/aom_config.h"
137     "${AOM_ROOT}/aom/aom.h"
138     "${AOM_ROOT}/aom/aom_codec.h"
139     "${AOM_ROOT}/aom/aom_decoder.h"
140     "${AOM_ROOT}/aom/aom_encoder.h"
141     "${AOM_ROOT}/aom/aom_frame_buffer.h"
142     "${AOM_ROOT}/aom/aom_image.h"
143     "${AOM_ROOT}/aom/aom_integer.h"
144     "${AOM_ROOT}/aom/aomcx.h"
145     "${AOM_ROOT}/aom/aomdx.h"
146     "${AOM_ROOT}/aom/internal/aom_codec_internal.h"
147     "${AOM_ROOT}/aom/src/aom_codec.c"
148     "${AOM_ROOT}/aom/src/aom_decoder.c"
149     "${AOM_ROOT}/aom/src/aom_encoder.c"
150     "${AOM_ROOT}/aom/src/aom_image.c")
152 set(AOM_COMMON_APP_UTIL_SOURCES
153     "${AOM_ROOT}/args.c"
154     "${AOM_ROOT}/args.h"
155     "${AOM_ROOT}/md5_utils.c"
156     "${AOM_ROOT}/md5_utils.h"
157     "${AOM_ROOT}/tools_common.c"
158     "${AOM_ROOT}/tools_common.h"
159     "${AOM_ROOT}/video_common.h"
160     "${AOM_ROOT}/y4menc.c"
161     "${AOM_ROOT}/y4menc.h")
163 set(AOM_DECODER_APP_UTIL_SOURCES
164     "${AOM_ROOT}/ivfdec.c"
165     "${AOM_ROOT}/ivfdec.h"
166     "${AOM_ROOT}/video_reader.c"
167     "${AOM_ROOT}/video_reader.h")
169 if (CONFIG_OBU_NO_IVF)
170   list(APPEND AOM_DECODER_APP_UTIL_SOURCES "${AOM_ROOT}/obudec.c" "${AOM_ROOT}/obudec.h")
171 endif ()
173 set(AOM_ENCODER_APP_UTIL_SOURCES
174     "${AOM_ROOT}/ivfenc.c"
175     "${AOM_ROOT}/ivfenc.h"
176     "${AOM_ROOT}/video_writer.c"
177     "${AOM_ROOT}/video_writer.h"
178     "${AOM_ROOT}/warnings.c"
179     "${AOM_ROOT}/warnings.h"
180     "${AOM_ROOT}/y4minput.c"
181     "${AOM_ROOT}/y4minput.h"
182     "${AOM_ROOT}/examples/encoder_util.h"
183     "${AOM_ROOT}/examples/encoder_util.c")
185 set(AOM_ENCODER_STATS_SOURCES
186     "${AOM_ROOT}/aomstats.c"
187     "${AOM_ROOT}/aomstats.h"
188     "${AOM_ROOT}/rate_hist.c"
189     "${AOM_ROOT}/rate_hist.h")
191 set(AOM_PKG_CONFIG_SOURCES "${AOM_CONFIG_DIR}/aom.pc")
193 set(AOM_VERSION_SOURCES "${AOM_CONFIG_DIR}/aom_version.h")
195 set(AOM_WEBM_DECODER_SOURCES
196     "${AOM_ROOT}/webmdec.cc"
197     "${AOM_ROOT}/webmdec.h")
199 set(AOM_WEBM_ENCODER_SOURCES
200     "${AOM_ROOT}/webmenc.cc"
201     "${AOM_ROOT}/webmenc.h")
203 include_directories(${AOM_ROOT} ${AOM_CONFIG_DIR})
205 # Targets
206 add_library(aom_version ${AOM_VERSION_SOURCES})
207 add_dummy_source_file_to_target(aom_version c)
208 add_custom_command(
209   OUTPUT "${AOM_CONFIG_DIR}/aom_version.h"
210   COMMAND ${CMAKE_COMMAND}
211   ARGS -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
212     -DAOM_ROOT=${AOM_ROOT}
213     -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
214     -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
215     -P "${AOM_ROOT}/build/cmake/version.cmake"
216   COMMENT "Writing aom_version.h"
217   VERBATIM)
219 add_custom_target(aom_version_check
220   COMMAND ${CMAKE_COMMAND}
221     -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
222     -DAOM_ROOT=${AOM_ROOT}
223     -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
224     -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
225     -P "${AOM_ROOT}/build/cmake/version.cmake"
226   COMMENT "Updating version info if necessary."
227   VERBATIM)
228 add_dependencies(aom_version aom_version_check)
230 if (NOT MSVC)
231   add_library(aom_pc ${AOM_PKG_CONFIG_SOURCES})
232   add_dummy_source_file_to_target(aom_pc c)
233   add_custom_command(
234     OUTPUT "${AOM_CONFIG_DIR}/aom.pc"
235     COMMAND ${CMAKE_COMMAND}
236     ARGS -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
237       -DAOM_ROOT=${AOM_ROOT}
238       -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
239       -DCMAKE_PROJECT_NAME=${CMAKE_PROJECT_NAME}
240       -DCONFIG_MULTITHREAD=${CONFIG_MULTITHREAD}
241       -DHAVE_PTHREAD_H=${HAVE_PTHREAD_H}
242       -P "${AOM_ROOT}/build/cmake/pkg_config.cmake"
243       COMMENT "Writing aom.pc"
244       VERBATIM)
245   add_dependencies(aom_pc aom_version)
246 endif ()
248 # TODO(tomfinegan): Move rtcd target setup where it belongs for each rtcd
249 # source.
250 add_rtcd_build_step("${AOM_ROOT}/aom_dsp/aom_dsp_rtcd_defs.pl"
251                     "${AOM_CONFIG_DIR}/aom_dsp_rtcd.h"
252                     "${AOM_ROOT}/aom_dsp/aom_dsp_rtcd.c"
253                     "aom_dsp_rtcd")
254 add_rtcd_build_step("${AOM_ROOT}/aom_scale/aom_scale_rtcd.pl"
255                     "${AOM_CONFIG_DIR}/aom_scale_rtcd.h"
256                     "${AOM_ROOT}/aom_scale/aom_scale_rtcd.c"
257                     "aom_scale_rtcd")
258 add_rtcd_build_step("${AOM_ROOT}/av1/common/av1_rtcd_defs.pl"
259                     "${AOM_CONFIG_DIR}/av1_rtcd.h"
260                     "${AOM_ROOT}/av1/common/av1_rtcd.c"
261                     "av1_rtcd")
263 add_library(aom_rtcd OBJECT ${AOM_RTCD_SOURCES})
264 add_dependencies(aom_rtcd aom_version)
266 add_library(aom_encoder_stats OBJECT ${AOM_ENCODER_STATS_SOURCES})
267 add_library(aom ${AOM_SOURCES} $<TARGET_OBJECTS:aom_rtcd>)
269 if (NOT MSVC AND NOT APPLE)
270   target_link_libraries(aom ${AOM_LIB_LINK_TYPE} m)
271 endif ()
273 # List of object and static library targets.
274 set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} aom_rtcd aom_encoder_stats aom_mem
275     aom_scale aom)
277 # Setup dependencies.
278 setup_aom_dsp_targets()
279 setup_aom_mem_targets()
280 setup_aom_ports_targets()
281 setup_aom_util_targets()
282 setup_aom_scale_targets()
283 setup_av1_targets()
285 # Make all library targets depend on aom_rtcd to make sure it builds first.
286 foreach (aom_lib ${AOM_LIB_TARGETS})
287   if (NOT "${aom_lib}" STREQUAL "aom_rtcd")
288     add_dependencies(${aom_lib} aom_rtcd)
289   endif ()
290 endforeach ()
292 # Generate C/C++ stub files containing the function usage_exit(). Users of the
293 # aom_common_app_util library must define this function. This is a convenience
294 # to allow omission of the function from applications that might want to use
295 # other pieces of the util support without defining usage_exit().
296 file(WRITE "${AOM_CONFIG_DIR}/usage_exit.c" "void usage_exit(void) {}")
297 file(WRITE "${AOM_CONFIG_DIR}/usage_exit.cc"
298      "extern \"C\" void usage_exit(void) {}")
301 # Application and application support targets.
303 if (CONFIG_UNIT_TESTS OR ENABLE_EXAMPLES OR ENABLE_TOOLS)
304   add_library(aom_common_app_util OBJECT ${AOM_COMMON_APP_UTIL_SOURCES})
305   if (CONFIG_AV1_DECODER)
306     add_library(aom_decoder_app_util OBJECT ${AOM_DECODER_APP_UTIL_SOURCES})
307   endif ()
308   if (CONFIG_AV1_ENCODER)
309     add_library(aom_encoder_app_util OBJECT ${AOM_ENCODER_APP_UTIL_SOURCES})
310   endif ()
311 endif ()
313 if (CONFIG_AV1_DECODER AND ENABLE_EXAMPLES)
314   add_executable(aomdec
315                  "${AOM_ROOT}/aomdec.c"
316                  $<TARGET_OBJECTS:aom_common_app_util>
317                  $<TARGET_OBJECTS:aom_decoder_app_util>)
318   add_executable(decode_to_md5
319                  "${AOM_ROOT}/examples/decode_to_md5.c"
320                  $<TARGET_OBJECTS:aom_common_app_util>
321                  $<TARGET_OBJECTS:aom_decoder_app_util>)
322   add_executable(decode_with_drops
323                  "${AOM_ROOT}/examples/decode_with_drops.c"
324                  $<TARGET_OBJECTS:aom_common_app_util>
325                  $<TARGET_OBJECTS:aom_decoder_app_util>)
326   add_executable(simple_decoder
327                  "${AOM_ROOT}/examples/simple_decoder.c"
328                  $<TARGET_OBJECTS:aom_common_app_util>
329                  $<TARGET_OBJECTS:aom_decoder_app_util>)
331   if (CONFIG_ANALYZER)
332     add_executable(analyzer
333                    "${AOM_ROOT}/examples/analyzer.cc"
334                    $<TARGET_OBJECTS:aom_common_app_util>
335                    $<TARGET_OBJECTS:aom_decoder_app_util>)
336     target_link_libraries(analyzer
337                           ${AOM_LIB_LINK_TYPE} ${wxWidgets_LIBRARIES})
338     set(AOM_APP_TARGETS ${AOM_APP_TARGETS} analyzer)
339     set(AOM_DECODER_EXAMPLE_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS} analyzer)
340   endif ()
342   if (CONFIG_INSPECTION)
343     add_executable(inspect
344                    "${AOM_ROOT}/examples/inspect.c"
345                    $<TARGET_OBJECTS:aom_common_app_util>
346                    $<TARGET_OBJECTS:aom_decoder_app_util>)
347     set(AOM_DECODER_EXAMPLE_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS} inspect)
349     if (EMSCRIPTEN)
350       add_preproc_definition(_POSIX_SOURCE)
351       append_link_flag_to_target("inspect" "-s TOTAL_MEMORY=134217728")
352       append_link_flag_to_target("inspect" "-s MODULARIZE=1")
353       append_link_flag_to_target("inspect"
354                                  "-s EXPORT_NAME=\"\'DecoderModule\'\"")
355       append_link_flag_to_target("inspect" "--memory-init-file 0")
357       if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
358         # Default to -O3 when no build type specified.
359         append_compiler_flag("-O3")
360       endif ()
362       em_link_post_js(inspect "${AOM_ROOT}/tools/inspect-post.js")
363     endif ()
364   endif ()
366   # Maintain a list of decoder example targets.
367   set(AOM_DECODER_EXAMPLE_TARGETS ${AOM_DECODER_EXAMPLE_TARGETS}
368       aomdec decode_to_md5 decode_with_drops simple_decoder)
370   # Add decoder examples to the app targets list.
371   set(AOM_APP_TARGETS ${AOM_APP_TARGETS} ${AOM_DECODER_EXAMPLE_TARGETS})
372 endif ()
374 if (CONFIG_AV1_ENCODER)
375   if (ENABLE_EXAMPLES)
376     add_executable(aomenc
377                    "${AOM_ROOT}/aomenc.c"
378                    $<TARGET_OBJECTS:aom_common_app_util>
379                    $<TARGET_OBJECTS:aom_encoder_app_util>
380                    $<TARGET_OBJECTS:aom_encoder_stats>)
381     add_executable(lossless_encoder
382                    "${AOM_ROOT}/examples/lossless_encoder.c"
383                    $<TARGET_OBJECTS:aom_common_app_util>
384                    $<TARGET_OBJECTS:aom_encoder_app_util>)
385     add_executable(set_maps
386                    "${AOM_ROOT}/examples/set_maps.c"
387                    $<TARGET_OBJECTS:aom_common_app_util>
388                    $<TARGET_OBJECTS:aom_encoder_app_util>)
389     add_executable(simple_encoder
390                    "${AOM_ROOT}/examples/simple_encoder.c"
391                    $<TARGET_OBJECTS:aom_common_app_util>
392                    $<TARGET_OBJECTS:aom_encoder_app_util>)
393     add_executable(twopass_encoder
394                    "${AOM_ROOT}/examples/twopass_encoder.c"
395                    $<TARGET_OBJECTS:aom_common_app_util>
396                    $<TARGET_OBJECTS:aom_encoder_app_util>)
398     # Maintain a list of encoder example targets.
399     set(AOM_ENCODER_EXAMPLE_TARGETS
400         aomenc lossless_encoder set_maps simple_encoder twopass_encoder)
401   endif ()
403   if (ENABLE_TOOLS)
404     if (CONFIG_ENTROPY_STATS AND NOT BUILD_SHARED_LIBS)
405       # TODO(tomfinegan): Sort out why a simple link command with
406       # aom_entropy_optimizer.c won't work on macos, but dragging in all the
407       # helper machinery allows the link to succeed.
408       add_executable(aom_entropy_optimizer
409                      "${AOM_CONFIG_DIR}/usage_exit.c"
410                      "${AOM_ROOT}/tools/aom_entropy_optimizer.c"
411                      $<TARGET_OBJECTS:aom_common_app_util>
412                      $<TARGET_OBJECTS:aom_encoder_app_util>)
414       # Maintain a list of encoder tool targets.
415       set(AOM_ENCODER_TOOL_TARGETS
416           ${AOM_ENCODER_TOOL_TARGETS} aom_entropy_optimizer)
417     endif ()
418   endif ()
420   # Add encoder examples and tools to the targets list.
421   set(AOM_APP_TARGETS ${AOM_APP_TARGETS}
422       ${AOM_ENCODER_EXAMPLE_TARGETS} ${AOM_ENCODER_TOOL_TARGETS})
423 endif ()
425 if (ENABLE_EXAMPLES)
426   # Maintain a separate variable listing only the examples to facilitate
427   # installation of example programs into an examples sub directory of
428   # $AOM_DIST_DIR/bin when building the dist target.
429   set(AOM_EXAMPLE_TARGETS
430       ${AOM_DECODER_EXAMPLE_TARGETS} ${AOM_ENCODER_EXAMPLE_TARGETS})
431 endif ()
433 if (ENABLE_TOOLS)
434   if (CONFIG_AV1_DECODER AND CONFIG_OBU)
435     require_cxx_flag_nomsvc("-std=c++11" NO)
436     add_executable(dump_obu
437                    "${AOM_CONFIG_DIR}/usage_exit.cc"
438                    "${AOM_ROOT}/tools/dump_obu.cc"
439                    "${AOM_ROOT}/tools/obu_parser.cc"
440                    "${AOM_ROOT}/tools/obu_parser.h"
441                    $<TARGET_OBJECTS:aom_common_app_util>
442                    $<TARGET_OBJECTS:aom_decoder_app_util>)
444     list(APPEND AOM_TOOL_TARGETS dump_obu)
445     list(APPEND AOM_APP_TARGETS dump_obu)
447     if (NOT MSVC)
448       target_compile_options(dump_obu PUBLIC -std=c++11)
449       # TODO(tomfinegan): This can go once the GCC pragma in libwebm is updated
450       # to silence the auto_ptr warnings for GCC >= v4.
451       target_compile_options(dump_obu PUBLIC -Wno-deprecated-declarations)
452     endif ()
454     # Maintain a separate variable listing only the examples to facilitate
455     # installation of example programs into an tools sub directory of
456     # $AOM_DIST_DIR/bin when building the dist target.
457     list(APPEND AOM_TOOL_TARGETS
458          ${AOM_DECODER_TOOL_TARGETS} ${AOM_ENCODER_TOOL_TARGETS})
459   endif ()
460 endif ()
462 if (ENABLE_EXAMPLES AND CONFIG_AV1_DECODER AND CONFIG_AV1_ENCODER)
463   add_executable(aom_cx_set_ref
464                  "${AOM_ROOT}/examples/aom_cx_set_ref.c"
465                  $<TARGET_OBJECTS:aom_common_app_util>
466                  $<TARGET_OBJECTS:aom_encoder_app_util>)
467   set(AOM_EXAMPLE_TARGETS ${AOM_EXAMPLE_TARGETS} aom_cx_set_ref)
468   set(AOM_APP_TARGETS ${AOM_APP_TARGETS} aom_cx_set_ref)
469 endif ()
471 foreach (aom_app ${AOM_APP_TARGETS})
472   target_link_libraries(${aom_app} ${AOM_LIB_LINK_TYPE} aom)
473 endforeach ()
475 if (CONFIG_UNIT_TESTS OR ENABLE_EXAMPLES OR ENABLE_TOOLS)
476   if (CONFIG_LIBYUV)
477     add_library(yuv OBJECT ${AOM_LIBYUV_SOURCES})
478     if (NOT MSVC)
479       target_compile_options(yuv PRIVATE -Wno-unused-parameter)
480     endif ()
481     include_directories("${AOM_ROOT}/third_party/libyuv/include")
483     # Add to existing targets.
484     foreach (aom_app ${AOM_APP_TARGETS})
485       target_sources(${aom_app} PRIVATE $<TARGET_OBJECTS:yuv>)
486       set_property(TARGET ${aom_app} PROPERTY LINKER_LANGUAGE CXX)
487     endforeach ()
488   endif ()
490   if (CONFIG_WEBM_IO)
491     add_library(webm OBJECT ${AOM_LIBWEBM_SOURCES})
492     include_directories("${AOM_ROOT}/third_party/libwebm")
493     target_compile_definitions(webm PRIVATE __STDC_CONSTANT_MACROS)
494     target_compile_definitions(webm PRIVATE __STDC_LIMIT_MACROS)
496     if (NOT MSVC)
497       target_compile_options(webm PRIVATE -Wno-shadow)
498     endif ()
500     # Add to existing targets.
501     if (CONFIG_AV1_DECODER)
502       target_sources(aom_decoder_app_util PRIVATE ${AOM_WEBM_DECODER_SOURCES})
503     endif ()
505     if (CONFIG_AV1_ENCODER)
506       target_sources(aom_encoder_app_util PRIVATE ${AOM_WEBM_ENCODER_SOURCES})
507     endif ()
509     foreach (aom_app ${AOM_APP_TARGETS})
510       target_sources(${aom_app} PRIVATE $<TARGET_OBJECTS:webm>)
511       set_property(TARGET ${aom_app} PROPERTY LINKER_LANGUAGE CXX)
512      endforeach ()
513   endif ()
514 endif ()
516 if (CONFIG_UNIT_TESTS)
517   # Create test_libaom target and the targets it depends on.
518   setup_aom_test_targets()
519 endif ()
521 if (HAVE_PTHREAD_H AND CONFIG_MULTITHREAD)
522   find_package(Threads)
523   foreach (app_target ${AOM_APP_TARGETS})
524     target_link_libraries(${app_target} ${AOM_LIB_LINK_TYPE} Threads::Threads)
525   endforeach ()
526 endif ()
528 if (XCODE)
529   # TODO(tomfinegan): Make sure target has no C++ files before doing this as
530   # it's not necessary in that case.
531   if (CONFIG_LIBYUV OR CONFIG_WEBM_IO)
532     # The Xcode generator does not obey LINKER_LANGUAGE. Because of the issue
533     # what looks like a C++ file needs to be in any target that Xcode will link
534     # when the target contains a C++ dependency.
535     # Without this Xcode will try to link with the C linker, which always ends
536     # badly when a dependency actually includes C++.
537     # Note: LINKER_LANGUAGE is explicitly set to C++ for all targets touched
538     # here, it really is the Xcode generator's fault, or just a deficiency in
539     # Xcode itself.
540     foreach (aom_app ${AOM_APP_TARGETS})
541       add_dummy_source_file_to_target("${aom_app}" "cc")
542     endforeach ()
543   endif ()
544 endif ()
546 if (ENABLE_EXAMPLES AND "${CMAKE_GENERATOR}" MATCHES "Makefiles$")
547   # Users of the configure build expect the example targets to be built in the
548   # examples sub directory of the configured build directory after running make.
549   file(MAKE_DIRECTORY "${AOM_CONFIG_DIR}/examples")
551   foreach (target ${AOM_EXAMPLE_TARGETS})
552     if (NOT "${target}" MATCHES "aomdec\|aomenc")
553       set_target_properties(${target} PROPERTIES
554                             RUNTIME_OUTPUT_DIRECTORY
555                             "${AOM_CONFIG_DIR}/examples")
556     endif ()
557   endforeach ()
559   if (ENABLE_TOOLS AND AOM_TOOL_TARGETS)
560     # The same expectation is true for tool targets.
561     file(MAKE_DIRECTORY "${AOM_CONFIG_DIR}/tools")
562     set_target_properties(${AOM_TOOL_TARGETS} PROPERTIES
563                           RUNTIME_OUTPUT_DIRECTORY "${AOM_CONFIG_DIR}/tools")
564   endif ()
565 endif ()
567 if (BUILD_SHARED_LIBS)
568   include("${AOM_ROOT}/build/cmake/exports.cmake")
569   setup_exports_target()
570   set_target_properties(aom PROPERTIES SOVERSION 0)
571 endif ()
573 # Handle user supplied compile and link flags last to ensure they're obeyed.
574 set_user_flags()
576 # Aomedia documentation rule.
577 if (ENABLE_DOCS)
578   include(FindDoxygen)
579   if (DOXYGEN_FOUND)
580     include("${AOM_ROOT}/docs.cmake")
581     setup_documentation_targets()
582   else ()
583     message("--- Cannot find doxygen, ENABLE_DOCS turned off.")
584     set(ENABLE_DOCS OFF)
585   endif ()
586 endif ()
588 # Aomedia install rule.
589 set(AOM_INSTALL_INCS
590     "${AOM_ROOT}/aom/aom.h"
591     "${AOM_ROOT}/aom/aom_codec.h"
592     "${AOM_ROOT}/aom/aom_frame_buffer.h"
593     "${AOM_ROOT}/aom/aom_image.h"
594     "${AOM_ROOT}/aom/aom_integer.h"
595     "${AOM_ROOT}/aom/aom.h")
597 if (CONFIG_AV1_DECODER)
598   if (ENABLE_EXAMPLES)
599     set(AOM_INSTALL_BINS ${AOM_INSTALL_BINS} aomdec)
600   endif ()
602   set(AOM_INSTALL_INCS
603       ${AOM_INSTALL_INCS}
604       "${AOM_ROOT}/aom/aom_decoder.h"
605       "${AOM_ROOT}/aom/aomdx.h")
606 endif ()
608 if (CONFIG_AV1_ENCODER)
609   if (ENABLE_EXAMPLES)
610     set(AOM_INSTALL_BINS ${AOM_INSTALL_BINS} aomenc)
611   endif ()
613   set(AOM_INSTALL_INCS
614       ${AOM_INSTALL_INCS}
615       "${AOM_ROOT}/aom/aomcx.h"
616       "${AOM_ROOT}/aom/aom_encoder.h")
617 endif ()
619 set(AOM_INSTALL_LIBS aom)
621 install(FILES ${AOM_INSTALL_INCS}
622         DESTINATION "${CMAKE_INSTALL_PREFIX}/include/aom")
623 install(FILES "${AOM_CONFIG_DIR}/aom.pc"
624         DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
625 install(TARGETS ${AOM_INSTALL_LIBS} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
627 if (ENABLE_EXAMPLES)
628   install(TARGETS ${AOM_INSTALL_BINS} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
629 endif ()
631 # Aomedia dist rule.
632 if (CONFIG_AV1_DECODER AND ENABLE_EXAMPLES)
633   set(AOM_DIST_APPS ${AOM_DIST_APPS} $<TARGET_FILE:aomdec>)
634 endif ()
635 if (CONFIG_AV1_ENCODER AND ENABLE_EXAMPLES)
636   set(AOM_DIST_APPS ${AOM_DIST_APPS} $<TARGET_FILE:aomenc>)
637 endif ()
639 if (ENABLE_EXAMPLES)
640   foreach (example ${AOM_EXAMPLE_TARGETS})
641     list(APPEND AOM_DIST_EXAMPLES $<TARGET_FILE:${example}>)
642   endforeach ()
643 endif ()
645 if (ENABLE_TOOLS)
646   foreach (tool ${AOM_TOOL_TARGETS})
647     list(APPEND AOM_DIST_TOOLS $<TARGET_FILE:${tool}>)
648   endforeach ()
649 endif ()
651 if (NOT AOM_DIST_DIR)
652   set(AOM_DIST_DIR "${AOM_CONFIG_DIR}/dist")
653 endif ()
655 add_custom_target(dist
656                   COMMAND ${CMAKE_COMMAND}
657                   -DAOM_ROOT=${AOM_ROOT}
658                   -DAOM_CONFIG_DIR=${AOM_CONFIG_DIR}
659                   -DAOM_DIST_DIR=${AOM_DIST_DIR}
660                   -DAOM_DIST_APPS="${AOM_DIST_APPS}"
661                   -DAOM_DIST_EXAMPLES="${AOM_DIST_EXAMPLES}"
662                   -DAOM_DIST_TOOLS="${AOM_DIST_TOOLS}"
663                   -DAOM_DIST_INCLUDES="${AOM_INSTALL_INCS}"
664                   -DAOM_DIST_LIBS=$<TARGET_FILE:aom>
665                   -DENABLE_DOCS=${ENABLE_DOCS}
666                   -P "${AOM_ROOT}/build/cmake/dist.cmake"
667                   DEPENDS ${AOM_INSTALL_BINS} ${AOM_INSTALL_LIBS}
668                   ${AOM_INSTALL_INCS} ${AOM_EXAMPLE_TARGETS}
669                   ${AOM_TOOL_TARGETS})
671 if (ENABLE_DOCS)
672   add_dependencies(dist docs)
673 endif ()
675 # Collect all variables containing libaom source files.
676 get_cmake_property(all_cmake_vars VARIABLES)
677 foreach (var ${all_cmake_vars})
678   if ("${var}" MATCHES "SOURCES$\|_INTRIN_\|_ASM_" AND NOT
679       "${var}" MATCHES "_APP_\|DOXYGEN\|LIBWEBM\|LIBYUV\|_PKG_\|TEST")
680     list(APPEND aom_source_vars ${var})
681   endif ()
682 endforeach ()
684 # Libaom_srcs.txt generation.
685 set(libaom_srcs_txt_file "${AOM_CONFIG_DIR}/libaom_srcs.txt")
686 file(WRITE "${libaom_srcs_txt_file}" "# This file is generated. DO NOT EDIT.\n")
688 # Static source file list first.
689 foreach (aom_source_var ${aom_source_vars})
690   foreach (file ${${aom_source_var}})
691     if (NOT "${file}" MATCHES "${AOM_CONFIG_DIR}")
692       string(REPLACE "${AOM_ROOT}/" "" file "${file}")
693       file(APPEND "${libaom_srcs_txt_file}" "${file}\n")
694     endif ()
695   endforeach ()
696 endforeach ()
698 file(APPEND "${libaom_srcs_txt_file}"
699      "# Files below this line are generated by the libaom build system.\n")
700 foreach (aom_source_var ${aom_source_vars})
701   foreach (file ${${aom_source_var}})
702     if ("${file}" MATCHES "${AOM_CONFIG_DIR}")
703       string(REPLACE "${AOM_CONFIG_DIR}/" "" file "${file}")
704       file(APPEND "${libaom_srcs_txt_file}" "${file}\n")
705     endif ()
706   endforeach ()
707 endforeach ()
709 # Libaom_srcs.gni generation.
710 set(libaom_srcs_gni_file "${AOM_CONFIG_DIR}/libaom_srcs.gni")
711 file(WRITE "${libaom_srcs_gni_file}" "# This file is generated. DO NOT EDIT.\n")
713 foreach (aom_source_var ${aom_source_vars})
714   if ("${${aom_source_var}}" MATCHES "${AOM_ROOT}")
715     string(TOLOWER ${aom_source_var} aom_source_var_lowercase)
716     file(APPEND "${libaom_srcs_gni_file}" "\n${aom_source_var_lowercase} = [\n")
717   endif ()
719   foreach (file ${${aom_source_var}})
720     if (NOT "${file}" MATCHES "${AOM_CONFIG_DIR}")
721       string(REPLACE "${AOM_ROOT}" "//third_party/aom/src" file "${file}")
722       file(APPEND "${libaom_srcs_gni_file}" "  \"${file}\",\n")
723     endif ()
724   endforeach ()
726   if ("${${aom_source_var}}" MATCHES "${AOM_ROOT}")
727     file(APPEND "${libaom_srcs_gni_file}" "]\n")
728   endif ()
729 endforeach ()
731 file(APPEND "${libaom_srcs_gni_file}"
732      "\n# Files below this line are generated by the libaom build system.\n")
734 foreach (aom_source_var ${aom_source_vars})
735   if ("${${aom_source_var}}" MATCHES "${AOM_CONFIG_DIR}")
736     string(TOLOWER ${aom_source_var} aom_source_var_lowercase)
737     file(APPEND "${libaom_srcs_gni_file}"
738          "\n${aom_source_var_lowercase}_gen = [\n")
739   endif ()
740   foreach (file ${${aom_source_var}})
741     if (NOT "${file}" MATCHES "${AOM_ROOT}")
742       string(REPLACE "${AOM_CONFIG_DIR}" "//third_party/aom/src" file "${file}")
743       file(APPEND "${libaom_srcs_gni_file}" "  \"${file}\",\n")
744     endif ()
745   endforeach ()
747   if ("${${aom_source_var}}" MATCHES "${AOM_CONFIG_DIR}")
748     file(APPEND "${libaom_srcs_gni_file}" "]\n")
749   endif ()
750 endforeach ()