aom_optimization.cmake 3.45 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
##
## Copyright (c) 2017, Alliance for Open Media. All rights reserved
##
## This source code is subject to the terms of the BSD 2 Clause License and
## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
## was not distributed with this source code in the LICENSE file, you can
## obtain it at www.aomedia.org/license/software. If the Alliance for Open
## Media Patent License 1.0 was not distributed with this source code in the
## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
##

# Adds an object library target. Terminates generation if $flag is not supported
# by the current compiler. $flag is the intrinsics flag required by the current
# compiler, and is added to the compile flags for all sources in $sources.
# $opt_name is used to name the target. $target_to_update is made
# dependent upon the created target.
#
# Note: the libaom target is always updated because OBJECT libraries have rules
# that disallow the direct addition of .o files to them as dependencies. Static
# libraries do not have this limitation.
function (add_intrinsics_object_library flag opt_name target_to_update sources)
  if (MSVC)
    message(FATAL_ERROR "MSVC instrinics support not implemented.")
  endif ()
  set(target_name ${target_to_update}_${opt_name}_intrinsics)
  add_library(${target_name} OBJECT ${${sources}})
  target_compile_options(${target_name} PUBLIC ${flag})
  target_sources(aom PUBLIC $<TARGET_OBJECTS:${target_name}>)
29
30
31
32

  # Add the new lib target to the global list of aom library targets.
  list(APPEND AOM_LIB_TARGETS ${target_name})
  set(AOM_LIB_TARGETS ${AOM_LIB_TARGETS} PARENT_SCOPE)
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
endfunction ()

# Adds build commands for ASM files in $sources and uses $asm_build_name to
# build an output directory path. Adds ASM objects to libaom directly. $sources
# must be the name of a variable containing a list of sources.
#
# Note: the libaom target is always updated because OBJECT libraries have rules
# that disallow the direct addition of .o files to them as dependencies. Static
# libraries do not have this limitation.
function (add_asm_build asm_build_name sources)
  set(AOM_ASM_OBJECTS_DIR "${AOM_CONFIG_DIR}/asm_objects/${asm_build_name}")
  if (NOT EXISTS "${AOM_ASM_OBJECTS_DIR}")
    file(MAKE_DIRECTORY "${AOM_ASM_OBJECTS_DIR}")
  endif ()

  # TODO(tomfinegan): This might get rather lengthy; probably best to move it
  # out into its own function or macro.
  if ("${AOM_TARGET_CPU}" STREQUAL "x86_64" AND
      "${AOM_TARGET_SYSTEM}" STREQUAL "Darwin")
    set(objformat "macho64")
  elseif ("${AOM_TARGET_CPU}" STREQUAL "x86_64" AND
      "${AOM_TARGET_SYSTEM}" STREQUAL "Linux")
    set(objformat "elf64")
  else ()
    message(FATAL_ERROR
            "Unknown obj format: ${AOM_TARGET_CPU}-${AOM_TARGET_SYSTEM}")
  endif ()

  foreach (asm_source ${${sources}})
    get_filename_component(asm_source_name "${asm_source}" NAME)
    set(asm_object "${AOM_ASM_OBJECTS_DIR}/${asm_source_name}.o")
    add_custom_command(OUTPUT "${asm_object}"
                       COMMAND ${YASM_EXECUTABLE}
                       ARGS -f ${objformat}
                            -I${AOM_ROOT} -I${AOM_CONFIG_DIR}
                            -o "${asm_object}" "${asm_source}"
                       DEPENDS "${asm_source}"
                       COMMENT "Building ASM object ${asm_object}"
                       WORKING_DIRECTORY "${AOM_CONFIG_DIR}"
                       VERBATIM)
    target_sources(aom PUBLIC "${asm_source}" "${asm_object}")
  endforeach ()
endfunction ()