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