1 # Copyright 2014 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.
5 import("//build/config/arm.gni")
6 import("//build/config/android/config.gni")
7 import("//third_party/libvpx/libvpx_srcs.gni")
8 import("//third_party/yasm/yasm_assemble.gni")
10 if (is_posix && !is_mac) {
16 # Sets the architecture name for building libvpx.
17 if (cpu_arch == "x86") {
18 cpu_arch_full = "ia32"
19 } else if (cpu_arch == "x64") {
21 cpu_arch_full = "generic"
25 } else if (cpu_arch == "arm") {
27 cpu_arch_full = "arm-neon"
28 } else if (is_android) {
29 cpu_arch_full = "arm-neon-cpu-detect"
34 cpu_arch_full = cpu_arch
37 config("libvpx_config") {
39 "//third_party/libvpx/source/config",
40 "//third_party/libvpx/source/config/$os_category/$cpu_arch_full",
41 "//third_party/libvpx/source/libvpx",
42 "$root_gen_dir/third_party/libvpx", # Provides vpx_rtcd.h.
44 cflags = [ "-Wno-unused-function", "-Wno-sign-compare" ]
47 # This config is applied to targets that depend on libvpx.
48 config("libvpx_external_config") {
50 "//third_party/libvpx/source/libvpx",
54 executable("libvpx_obj_int_extract") {
56 "//third_party/libvpx/source/libvpx/build/make/obj_int_extract.c"
58 configs += [ ":libvpx_config" ]
59 if (is_android_webview_build) {
60 defines += [ "FORCE_PARSE_ELF" ]
61 include_dirs += [ "//third_party/libvpx/include" ]
65 # A library whose object files contain integers to be extracted.
66 static_library("libvpx_asm_offsets") {
68 "//third_party/libvpx/source/libvpx/vp8/encoder/vp8_asm_enc_offsets.c",
69 "//third_party/libvpx/source/libvpx/vpx_scale/vpx_scale_asm_offsets.c"
71 configs += [ ":libvpx_config" ]
73 cflags = [ "-Wno-unused-function" ]
77 # This works only on POSIX to extract integer values from an object file.
78 template("obj_int_extract") {
80 script = "//third_party/libvpx/obj_int_extract.py"
81 bin_label = "//third_party/libvpx($host_toolchain)"
85 "./" + rebase_path(get_label_info(bin_label, "root_out_dir") +
86 "/libvpx_obj_int_extract",
90 if (cpu_arch == "arm") {
91 args += [ "-f", "gas" ]
93 args += [ "-f", "rvds" ]
98 rebase_path(get_label_info(":libvpx_asm_offsets", "target_out_dir")) +
99 "/" + invoker.src_dir + "/libvpx_asm_offsets." +
100 invoker.obj_file_root + ".o"
102 out_file = "$target_gen_dir/" + invoker.obj_file_root + ".asm"
103 args += [ "-o", rebase_path(out_file) ]
104 outputs = [ out_file ]
106 ":libvpx_asm_offsets",
107 ":libvpx_obj_int_extract($host_toolchain)"
112 obj_int_extract("gen_asm_offsets_vp8") {
113 src_dir = "source/libvpx/vp8/encoder"
114 obj_file_root = "vp8_asm_enc_offsets"
117 obj_int_extract("gen_asm_offsets_scale") {
118 src_dir = "source/libvpx/vpx_scale"
119 obj_file_root = "vpx_scale_asm_offsets"
122 if (cpu_arch == "x86" || cpu_arch == "x64") {
123 yasm_assemble("libvpx_yasm") {
124 if (cpu_arch == "x86") {
125 sources = libvpx_srcs_x86_assembly
126 } else if (cpu_arch == "x64") {
127 sources = libvpx_srcs_x86_64_assembly
130 defines = [ "CHROMIUM" ]
132 "//third_party/libvpx/source/config/$os_category/$cpu_arch_full",
133 "//third_party/libvpx/source/config",
134 "//third_party/libvpx/source/libvpx",
138 ":gen_asm_offsets_vp8",
139 ":gen_asm_offsets_scale",
144 static_library("libvpx_intrinsics_mmx") {
145 configs += [ ":libvpx_config" ]
147 if (cpu_arch == "x86") {
148 sources = libvpx_srcs_x86_mmx
149 } else if (cpu_arch == "x64") {
150 sources = libvpx_srcs_x86_64_mmx
154 static_library("libvpx_intrinsics_sse2") {
155 configs += [ ":libvpx_config" ]
156 cflags = [ "-msse2" ]
157 if (cpu_arch == "x86") {
158 sources = libvpx_srcs_x86_sse2
159 } else if (cpu_arch == "x64") {
160 sources = libvpx_srcs_x86_64_sse2
164 static_library("libvpx_intrinsics_ssse3") {
165 configs += [ ":libvpx_config" ]
166 cflags = [ "-mssse3" ]
167 if (cpu_arch == "x86") {
168 sources = libvpx_srcs_x86_ssse3
169 } else if (cpu_arch == "x64") {
170 sources = libvpx_srcs_x86_64_ssse3
174 static_library("libvpx_intrinsics_sse4_1") {
175 configs += [ ":libvpx_config" ]
176 cflags = [ "-msse4.1" ]
177 if (cpu_arch == "x86") {
178 sources = libvpx_srcs_x86_sse4_1
179 } else if (cpu_arch == "x64") {
180 sources = libvpx_srcs_x86_64_sse4_1
184 if (cpu_arch_full == "arm-neon-cpu-detect") {
185 static_library("libvpx_intrinsics_neon") {
186 configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
187 configs += [ ":libvpx_config" ]
188 cflags = [ "-mfpu=neon" ]
189 sources = libvpx_srcs_arm_neon_cpu_detect_neon
193 # Converts ARM assembly files to GAS style.
194 if (cpu_arch == "arm") {
195 action_foreach("convert_arm_assembly") {
196 script = "//third_party/libvpx/run_perl.py"
197 if (cpu_arch_full == "arm-neon") {
198 sources = libvpx_srcs_arm_neon_assembly
199 } else if (cpu_arch_full == "arm-neon-cpu-detect") {
200 sources = libvpx_srcs_arm_neon_cpu_detect_assembly
202 sources = libvpx_srcs_arm_assembly
204 outputs = [ "$target_gen_dir/{{source_name_part}}.S" ]
207 rebase_path("//third_party/libvpx/source/libvpx/build/make/ads2gas.pl",
210 "-o", rebase_path("$target_gen_dir/{{source_name_part}}.S")
214 static_library("libvpx_assembly_arm") {
215 sources = get_target_outputs(":convert_arm_assembly")
216 configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
217 configs += [ ":libvpx_config" ]
218 if (cpu_arch_full == "arm-neon" ||
219 cpu_arch_full == "arm-neon-cpu-detect") {
220 cflags = [ "-mfpu=neon" ]
223 ":convert_arm_assembly",
224 ":gen_asm_offsets_vp8",
225 ":gen_asm_offsets_scale",
230 static_library("libvpx") {
231 if (!is_debug && is_win && is_official_build) {
232 configs -= [ "//build/config/compiler:optimize" ]
233 configs += [ "//build/config/compiler:optimize_max" ]
236 if (cpu_arch == "x86") {
237 sources = libvpx_srcs_x86
238 } else if (cpu_arch == "x64") {
240 sources = libvpx_srcs_generic
242 sources = libvpx_srcs_x86_64
244 } else if (cpu_arch == "mipsel") {
245 sources = libvpx_srcs_generic
246 } else if (cpu_arch == "arm") {
248 sources = libvpx_srcs_arm_neon
249 } else if (is_android) {
250 sources = libvpx_srcs_arm_neon_cpu_detect
252 sources = libvpx_srcs_arm
254 } else if (cpu_arch == "arm64") {
255 sources = libvpx_srcs_arm64
257 configs += [ ":libvpx_config" ]
259 if (cpu_arch == "x86" || (cpu_arch == "x64" && !is_msan)) {
262 ":libvpx_intrinsics_mmx",
263 ":libvpx_intrinsics_sse2",
264 ":libvpx_intrinsics_ssse3",
265 ":libvpx_intrinsics_sse4_1",
268 if (cpu_arch_full == "arm-neon-cpu-detect") {
269 deps += [ ":libvpx_intrinsics_neon" ]
272 deps += [ "//third_party/android_tools:cpu_features" ]
274 if (cpu_arch == "arm") {
275 deps += [ ":libvpx_assembly_arm" ]
278 public_configs = [ ":libvpx_external_config" ]