1# Copyright 2015 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/sanitizers/sanitizers.gni")
6import("//third_party/openh264/openh264_args.gni")
7import("//third_party/openh264/openh264_sources.gni")
8import("//third_party/yasm/yasm_assemble.gni")
9
10# Config shared by all openh264 targets.
11config("config") {
12  cflags = []
13  defines = []
14
15  if (is_chromeos && current_cpu == "arm") {
16    # HAVE_NEON and __chromeos__ are needed for enabling NEON on ChromeOS
17    # devices.
18    defines += [
19      "HAVE_NEON",
20      "__chromeos__",
21    ]
22  }
23
24  # GCC and clang flags. MSVS (is_win && !is_clang) does not use cflags.
25  if (!is_win || is_clang) {
26    cflags += [
27      "-Wno-format",
28      "-Wno-format-security",
29      "-Wno-header-hygiene",
30      "-Wno-unused-function",
31      "-Wno-unused-value",
32    ]
33  }
34
35  # Platform-specific defines.
36  if (is_android) {
37    # Android NDK is necessary for its cpufeatures and this define is what
38    # OpenH264 code uses to check if it should be used.
39    defines += [ "ANDROID_NDK" ]
40  }
41}
42
43# YASM assembly is only checked to be working on Windows and Linux.
44# Mac is known to fail certain tests when building, but actual assembly
45# is believed to work.
46# MSAN builds are flaky with assembler. crbug.com/685168
47
48use_assembler = (is_win || is_linux) &&
49                (current_cpu == "x86" || current_cpu == "x64") && !is_msan
50
51# This IF statement will make the targets visible only on specific builds,
52# which will lead to failures on other platforms if accidentally invoked.
53if (use_assembler) {
54  yasm_defines = []
55  if (!is_component_build) {
56    if (is_mac || is_ios) {
57      yasm_defines += [ "WELS_PRIVATE_EXTERN=:private_extern" ]
58    } else if (is_linux || is_android || is_fuchsia) {
59      yasm_defines += [ "WELS_PRIVATE_EXTERN=:hidden" ]
60    }
61  }
62
63  yasm_assemble("openh264_common_yasm") {
64    include_dirs = openh264_common_include_dirs
65    sources = openh264_common_sources_asm_x86
66    defines = yasm_defines
67    if (current_cpu == "x86") {
68      defines += [ "X86_32" ]
69    } else {  # x64
70      if (is_mac) {
71        defines += [
72          "PREFIX",
73          "UNIX64",
74        ]
75      } else if (is_win) {
76        defines += [ "WIN64" ]
77      } else if (is_linux) {
78        defines += [ "UNIX64" ]
79      }
80    }
81  }
82
83  yasm_assemble("openh264_processing_yasm") {
84    include_dirs = openh264_processing_include_dirs
85    include_dirs += [ "./src/codec/common/x86" ]
86    sources = openh264_processing_sources_asm_x86
87    defines = yasm_defines
88    if (current_cpu == "x86") {
89      defines += [ "X86_32" ]
90    } else {  # x64
91      if (is_mac) {
92        defines += [
93          "PREFIX",
94          "UNIX64",
95        ]
96      } else if (is_win) {
97        defines += [ "WIN64" ]
98      } else if (is_linux) {
99        defines += [ "UNIX64" ]
100      }
101    }
102  }
103
104  yasm_assemble("openh264_encoder_yasm") {
105    include_dirs = openh264_encoder_include_dirs
106    include_dirs += [ "./src/codec/common/x86" ]
107    sources = openh264_encoder_sources_asm_x86
108    defines = yasm_defines
109    if (current_cpu == "x86") {
110      defines += [ "X86_32" ]
111    } else {  # x64
112      if (is_mac) {
113        defines += [
114          "PREFIX",
115          "UNIX64",
116        ]
117      } else if (is_win) {
118        defines += [ "WIN64" ]
119      } else if (is_linux) {
120        defines += [ "UNIX64" ]
121      }
122    }
123  }
124}  # if (is_win || is_linux)
125
126source_set("common") {
127  sources = openh264_common_sources
128  if (is_chromeos && current_cpu == "arm") {
129    sources += openh264_common_sources_asm_arm
130  }
131  include_dirs = openh264_common_include_dirs
132
133  configs -= [ "//build/config/compiler:chromium_code" ]
134  configs += [ "//build/config/compiler:no_chromium_code" ]
135  configs += [ ":config" ]
136  deps = []
137  if (use_assembler) {
138    defines = [ "X86_ASM" ]
139    deps += [ ":openh264_common_yasm" ]
140  }
141  if (is_android) {
142    deps += [
143      # Defines "android_get/setCpu..." functions. The original OpenH264 build
144      # files replaces these using macros for "wels_..." versions of the same
145      # functions. We do not have access to these and use the <cpu-features.h>
146      # ones instead.
147      "//third_party/android_ndk:cpu_features",
148    ]
149  }
150}
151
152source_set("processing") {
153  sources = openh264_processing_sources
154  if (is_chromeos && current_cpu == "arm") {
155    sources += openh264_processing_sources_asm_arm
156  }
157  include_dirs = openh264_processing_include_dirs
158
159  configs -= [ "//build/config/compiler:chromium_code" ]
160  configs += [ "//build/config/compiler:no_chromium_code" ]
161  configs += [ ":config" ]
162  deps = [ ":common" ]
163  if (use_assembler) {
164    defines = [ "X86_ASM" ]
165    deps += [ ":openh264_processing_yasm" ]
166  }
167}
168
169source_set("encoder") {
170  sources = openh264_encoder_sources
171  if (is_chromeos && current_cpu == "arm") {
172    sources += openh264_encoder_sources_asm_arm
173  }
174  include_dirs = openh264_encoder_include_dirs
175
176  configs -= [ "//build/config/compiler:chromium_code" ]
177  configs += [ "//build/config/compiler:no_chromium_code" ]
178  configs += [ ":config" ]
179
180  # TODO: Remove after fixing always-true condition
181  # third_party/openh264/src/codec/encoder/core/src/encoder_ext.cpp:142.
182  if (is_clang) {
183    configs -= [ "//build/config/clang:extra_warnings" ]
184  }
185  deps = [
186    ":common",
187    ":processing",
188  ]
189  if (use_assembler) {
190    defines = [ "X86_ASM" ]
191    deps += [ ":openh264_encoder_yasm" ]
192  }
193}
194