summaryrefslogtreecommitdiff
path: root/chromium/third_party/openh264/BUILD.gn
blob: e33b5233b5bb07ff868434dd367d88d70ab969c5 (plain)
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
29
30
31
32
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/linux/pkg_config.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/shim_headers.gni")
import("//third_party/openh264/openh264_args.gni")
import("//third_party/openh264/openh264_sources.gni")
import("//third_party/yasm/yasm_assemble.gni")

# Config shared by all openh264 targets.
config("config") {
  cflags = []
  defines = []

  # GCC and clang flags. MSVS (is_win && !is_clang) does not use cflags.
  if (!is_win || is_clang) {
    cflags += [
      "-Wno-format",
      "-Wno-header-hygiene",
      "-Wno-unused-function",
      "-Wno-unused-value",
    ]
  }

  # Platform-specific defines.
  if (is_android) {
    # Android NDK is necessary for its cpufeatures and this define is what
    # OpenH264 code uses to check if it should be used.
    defines += [ "ANDROID_NDK" ]
  }
}

# YASM assembly is only checked to be working on Windows and Linux.
# Mac is known to fail certain tests when building, but actual assembly
# is believed to work.
# MSAN builds are flaky with assembler. crbug.com/685168

use_assembler = (is_win || is_linux) &&
                (target_cpu == "x86" || target_cpu == "x64") && !is_msan

# This IF statement will make the targets visible only on specific builds,
# which will lead to failures on other platforms if accidentally invoked.
if (use_assembler) {
  yasm_assemble("openh264_common_yasm") {
    include_dirs = openh264_common_include_dirs
    sources = openh264_common_sources_asm_x86
    if (target_cpu == "x86") {
      defines = [ "X86_32" ]
    } else {  # x64
      if (is_mac) {
        defines = [
          "PREFIX",
          "UNIX64",
        ]
      } else if (is_win) {
        defines = [ "WIN64" ]
      } else if (is_linux) {
        defines = [ "UNIX64" ]
      }
    }
  }

  yasm_assemble("openh264_processing_yasm") {
    include_dirs = openh264_processing_include_dirs
    include_dirs += [ "./src/codec/common/x86" ]
    sources = openh264_processing_sources_asm_x86
    if (target_cpu == "x86") {
      defines = [ "X86_32" ]
    } else {  # x64
      if (is_mac) {
        defines = [
          "PREFIX",
          "UNIX64",
        ]
      } else if (is_win) {
        defines = [ "WIN64" ]
      } else if (is_linux) {
        defines = [ "UNIX64" ]
      }
    }
  }

  yasm_assemble("openh264_encoder_yasm") {
    include_dirs = openh264_encoder_include_dirs
    include_dirs += [ "./src/codec/common/x86" ]
    sources = openh264_encoder_sources_asm_x86
    if (target_cpu == "x86") {
      defines = [ "X86_32" ]
    } else {  # x64
      if (is_mac) {
        defines = [
          "PREFIX",
          "UNIX64",
        ]
      } else if (is_win) {
        defines = [ "WIN64" ]
      } else if (is_linux) {
        defines = [ "UNIX64" ]
      }
    }
  }
}  # if (is_win || is_linux)

source_set("bundled_common") {
  sources = openh264_common_sources
  include_dirs = openh264_common_include_dirs

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [ "//build/config/compiler:no_chromium_code" ]
  configs += [ ":config" ]
  deps = []
  if (use_assembler) {
    defines = [ "X86_ASM" ]
    deps += [ ":openh264_common_yasm" ]
  }
  if (is_android) {
    deps += [
      # Defines "android_get/setCpu..." functions. The original OpenH264 build
      # files replaces these using macros for "wels_..." versions of the same
      # functions. We do not have access to these and use the <cpu-features.h>
      # ones instead.
      "//third_party/android_tools:cpu_features",
    ]
  }
}

source_set("bundled_processing") {
  sources = openh264_processing_sources
  include_dirs = openh264_processing_include_dirs

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [ "//build/config/compiler:no_chromium_code" ]
  configs += [ ":config" ]
  deps = [
    ":bundled_common",
  ]
  if (use_assembler) {
    defines = [ "X86_ASM" ]
    deps += [ ":openh264_processing_yasm" ]
  }
}

source_set("bundled_encoder") {
  sources = openh264_encoder_sources
  include_dirs = openh264_encoder_include_dirs

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [ "//build/config/compiler:no_chromium_code" ]
  configs += [ ":config" ]

  # TODO: Remove after fixing always-true condition
  # third_party/openh264/src/codec/encoder/core/src/encoder_ext.cpp:142.
  if (is_clang) {
    configs -= [ "//build/config/clang:extra_warnings" ]
  }
  deps = [
    ":bundled_common",
    ":bundled_processing",
  ]
  if (use_assembler) {
    defines = [ "X86_ASM" ]
    deps += [ ":openh264_encoder_yasm" ]
  }
}

if (use_system_openh264) {
  pkg_config("system_openh264") {
    packages = [ "openh264" ]
  }
}

shim_headers("openh264_shim") {
  prefix = "wels/"
  root_path = "src/codec/api/svc"
  headers = [
    "codec_api.h",
    "codec_app_def.h",
    "codec_def.h",
    "codec_ver.h",
  ]
}

group("common") {
  if (use_system_openh264) {
    deps = [ ":openh264_shim" ]
    public_configs = [ ":system_openh264" ]
  } else {
    public_deps = [ ":bundled_common" ]
  }
}

group("processing") {
  if (use_system_openh264) {
    deps = [ ":openh264_shim" ]
    public_configs = [ ":system_openh264" ]
  } else {
    public_deps = [ ":bundled_processing" ]
  }
}

group("encoder") {
  if (use_system_openh264) {
    deps = [ ":openh264_shim" ]
    public_configs = [ ":system_openh264" ]
  } else {
    public_deps = [ ":bundled_encoder" ]
  }
}