blob: 8904fd6c69913235520ae97fac7cd10d9217dc07 [file] [log] [blame]
Hangyu Kuangf047e7c2016-07-06 14:21:45 -07001# Copyright 2014 The LibYuv Project Authors. All rights reserved.
2#
3# Use of this source code is governed by a BSD-style license
4# that can be found in the LICENSE file in the root of the source
5# tree. An additional intellectual property rights grant can be found
6# in the file PATENTS. All contributing project authors may
7# be found in the AUTHORS file in the root of the source tree.
8
Frank Barchardb83bb382017-02-22 18:01:07 -08009import("libyuv.gni")
10import("//testing/test.gni")
Hangyu Kuangf047e7c2016-07-06 14:21:45 -070011
Frank Barchardb33a82f2017-04-18 11:28:09 -070012declare_args() {
13 # Set to false to disable building with gflags.
14 libyuv_use_gflags = true
Chong Zhangab123ac2019-06-27 14:28:37 -070015
16 # When building a shared library using a target in WebRTC or
17 # Chromium projects that depends on libyuv, setting this flag
18 # to true makes libyuv symbols visible inside that library.
19 libyuv_symbols_visible = false
Frank Barchardb33a82f2017-04-18 11:28:09 -070020}
21
Hangyu Kuangf047e7c2016-07-06 14:21:45 -070022config("libyuv_config") {
Frank Barchardb83bb382017-02-22 18:01:07 -080023 include_dirs = [ "include" ]
Frank Barchardcead1e02017-03-10 12:03:05 -080024 if (is_android && current_cpu == "arm64") {
Frank Barchardb83bb382017-02-22 18:01:07 -080025 ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker64" ]
26 }
27 if (is_android && current_cpu != "arm64") {
28 ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker" ]
29 }
Hangyu Kuangf047e7c2016-07-06 14:21:45 -070030}
31
Frank Barchardb83bb382017-02-22 18:01:07 -080032# This target is built when no specific target is specified on the command line.
33group("default") {
34 testonly = true
35 deps = [
36 ":libyuv",
37 ]
38 if (libyuv_include_tests) {
39 deps += [
40 ":compare",
Frank Barchardb83bb382017-02-22 18:01:07 -080041 ":cpuid",
42 ":libyuv_unittest",
43 ":psnr",
Chong Zhangab123ac2019-06-27 14:28:37 -070044 ":yuvconvert",
Frank Barchardb83bb382017-02-22 18:01:07 -080045 ]
46 }
47}
Hangyu Kuangf047e7c2016-07-06 14:21:45 -070048
Frank Barchardcead1e02017-03-10 12:03:05 -080049group("libyuv") {
Chong Zhangab123ac2019-06-27 14:28:37 -070050 all_dependent_configs = [ ":libyuv_config" ]
51 deps = []
Frank Barchardcead1e02017-03-10 12:03:05 -080052
53 if (is_win && target_cpu == "x64") {
Chong Zhangab123ac2019-06-27 14:28:37 -070054 # Compile with clang in order to get inline assembly
Frank Barchardcead1e02017-03-10 12:03:05 -080055 public_deps = [
Chong Zhangab123ac2019-06-27 14:28:37 -070056 ":libyuv_internal(//build/toolchain/win:win_clang_x64)",
Frank Barchardcead1e02017-03-10 12:03:05 -080057 ]
58 } else {
59 public_deps = [
60 ":libyuv_internal",
61 ]
62 }
Chong Zhangab123ac2019-06-27 14:28:37 -070063
64 if (libyuv_use_neon) {
65 deps += [ ":libyuv_neon" ]
66 }
67
68 if (libyuv_use_msa) {
69 deps += [ ":libyuv_msa" ]
70 }
71
72 if (libyuv_use_mmi) {
73 deps += [ ":libyuv_mmi" ]
74 }
75
76 if (!is_ios) {
77 # Make sure that clients of libyuv link with libjpeg. This can't go in
78 # libyuv_internal because in Windows x64 builds that will generate a clang
79 # build of libjpeg, and we don't want two copies.
80 deps += [ "//third_party:jpeg" ]
81 }
Frank Barchardcead1e02017-03-10 12:03:05 -080082}
83
84static_library("libyuv_internal") {
Chong Zhangab123ac2019-06-27 14:28:37 -070085 visibility = [ ":*" ]
86
Hangyu Kuangf047e7c2016-07-06 14:21:45 -070087 sources = [
88 # Headers
89 "include/libyuv.h",
90 "include/libyuv/basic_types.h",
91 "include/libyuv/compare.h",
92 "include/libyuv/convert.h",
93 "include/libyuv/convert_argb.h",
94 "include/libyuv/convert_from.h",
95 "include/libyuv/convert_from_argb.h",
96 "include/libyuv/cpu_id.h",
97 "include/libyuv/mjpeg_decoder.h",
98 "include/libyuv/planar_functions.h",
99 "include/libyuv/rotate.h",
100 "include/libyuv/rotate_argb.h",
101 "include/libyuv/rotate_row.h",
102 "include/libyuv/row.h",
103 "include/libyuv/scale.h",
104 "include/libyuv/scale_argb.h",
105 "include/libyuv/scale_row.h",
106 "include/libyuv/version.h",
107 "include/libyuv/video_common.h",
108
109 # Source Files
110 "source/compare.cc",
111 "source/compare_common.cc",
112 "source/compare_gcc.cc",
113 "source/compare_win.cc",
114 "source/convert.cc",
115 "source/convert_argb.cc",
116 "source/convert_from.cc",
117 "source/convert_from_argb.cc",
118 "source/convert_jpeg.cc",
119 "source/convert_to_argb.cc",
120 "source/convert_to_i420.cc",
121 "source/cpu_id.cc",
122 "source/mjpeg_decoder.cc",
123 "source/mjpeg_validate.cc",
124 "source/planar_functions.cc",
125 "source/rotate.cc",
126 "source/rotate_any.cc",
127 "source/rotate_argb.cc",
128 "source/rotate_common.cc",
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700129 "source/rotate_gcc.cc",
130 "source/rotate_win.cc",
131 "source/row_any.cc",
132 "source/row_common.cc",
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700133 "source/row_gcc.cc",
134 "source/row_win.cc",
135 "source/scale.cc",
136 "source/scale_any.cc",
137 "source/scale_argb.cc",
138 "source/scale_common.cc",
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700139 "source/scale_gcc.cc",
140 "source/scale_win.cc",
141 "source/video_common.cc",
142 ]
143
Frank Barchardcead1e02017-03-10 12:03:05 -0800144 configs += [ ":libyuv_config" ]
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700145 defines = []
Frank Barchardb83bb382017-02-22 18:01:07 -0800146 deps = []
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700147
Chong Zhangab123ac2019-06-27 14:28:37 -0700148 if (libyuv_symbols_visible) {
149 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
150 configs += [ "//build/config/gcc:symbol_visibility_default" ]
151 }
152
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700153 if (!is_ios) {
154 defines += [ "HAVE_JPEG" ]
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700155
Chong Zhangab123ac2019-06-27 14:28:37 -0700156 # Needed to pull in libjpeg headers. Can't add //third_party:jpeg to deps
157 # because in Windows x64 build it will get compiled with clang.
158 deps += [ "//third_party:jpeg_includes" ]
Frank Barchardb83bb382017-02-22 18:01:07 -0800159 }
160
161 # Always enable optimization for Release and NaCl builds (to workaround
162 # crbug.com/538243).
163 if (!is_debug || is_nacl) {
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700164 configs -= [ "//build/config/compiler:default_optimization" ]
Frank Barchardcead1e02017-03-10 12:03:05 -0800165
Frank Barchardb83bb382017-02-22 18:01:07 -0800166 # Enable optimize for speed (-O2) over size (-Os).
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700167 configs += [ "//build/config/compiler:optimize_max" ]
168 }
Frank Barchardb83bb382017-02-22 18:01:07 -0800169
170 # To enable AVX2 or other cpu optimization, pass flag here
Chong Zhangab123ac2019-06-27 14:28:37 -0700171 if (!is_win) {
172 cflags = [
173 # "-mpopcnt",
174 # "-mavx2",
175 # "-mfma",
176 "-ffp-contract=fast", # Enable fma vectorization for NEON.
177 ]
178 }
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700179}
180
Frank Barchardb83bb382017-02-22 18:01:07 -0800181if (libyuv_use_neon) {
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700182 static_library("libyuv_neon") {
183 sources = [
184 # ARM Source Files
185 "source/compare_neon.cc",
186 "source/compare_neon64.cc",
187 "source/rotate_neon.cc",
188 "source/rotate_neon64.cc",
189 "source/row_neon.cc",
190 "source/row_neon64.cc",
191 "source/scale_neon.cc",
192 "source/scale_neon64.cc",
193 ]
194
Chong Zhangab123ac2019-06-27 14:28:37 -0700195 deps = [
196 ":libyuv_internal",
197 ]
198
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700199 public_configs = [ ":libyuv_config" ]
200
Frank Barchardb83bb382017-02-22 18:01:07 -0800201 # Always enable optimization for Release and NaCl builds (to workaround
202 # crbug.com/538243).
203 if (!is_debug) {
204 configs -= [ "//build/config/compiler:default_optimization" ]
Frank Barchardcead1e02017-03-10 12:03:05 -0800205
Frank Barchardb83bb382017-02-22 18:01:07 -0800206 # Enable optimize for speed (-O2) over size (-Os).
Chong Zhangab123ac2019-06-27 14:28:37 -0700207 # TODO(fbarchard): Consider optimize_speed which is O3.
Frank Barchardb83bb382017-02-22 18:01:07 -0800208 configs += [ "//build/config/compiler:optimize_max" ]
209 }
210
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700211 if (current_cpu != "arm64") {
212 configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
213 cflags = [ "-mfpu=neon" ]
214 }
215 }
216}
Frank Barchardb83bb382017-02-22 18:01:07 -0800217
218if (libyuv_use_msa) {
219 static_library("libyuv_msa") {
220 sources = [
221 # MSA Source Files
Chong Zhangab123ac2019-06-27 14:28:37 -0700222 "source/compare_msa.cc",
Frank Barchardcead1e02017-03-10 12:03:05 -0800223 "source/rotate_msa.cc",
Frank Barchardb83bb382017-02-22 18:01:07 -0800224 "source/row_msa.cc",
225 "source/scale_msa.cc",
Frank Barchardb83bb382017-02-22 18:01:07 -0800226 ]
227
Chong Zhangab123ac2019-06-27 14:28:37 -0700228 deps = [
229 ":libyuv_internal",
230 ]
231
232 public_configs = [ ":libyuv_config" ]
233 }
234}
235
236if (libyuv_use_mmi) {
237 static_library("libyuv_mmi") {
238 sources = [
239 # MMI Source Files
240 "source/compare_mmi.cc",
241 "source/rotate_mmi.cc",
242 "source/row_mmi.cc",
243 "source/scale_mmi.cc",
244 ]
245
246 deps = [
247 ":libyuv_internal",
248 ]
249
Frank Barchardb83bb382017-02-22 18:01:07 -0800250 public_configs = [ ":libyuv_config" ]
251 }
252}
253
254if (libyuv_include_tests) {
255 config("libyuv_unittest_warnings_config") {
256 if (!is_win) {
257 cflags = [
258 # TODO(fbarchard): Fix sign and unused variable warnings.
259 "-Wno-sign-compare",
Frank Barchardcead1e02017-03-10 12:03:05 -0800260 "-Wno-unused-variable",
Frank Barchardb83bb382017-02-22 18:01:07 -0800261 ]
262 }
263 if (is_win) {
264 cflags = [
Frank Barchardcead1e02017-03-10 12:03:05 -0800265 "/wd4245", # signed/unsigned mismatch
266 "/wd4189", # local variable is initialized but not referenced
Frank Barchardb83bb382017-02-22 18:01:07 -0800267 ]
268 }
269 }
270 config("libyuv_unittest_config") {
271 defines = [ "GTEST_RELATIVE_PATH" ]
272 }
273
274 test("libyuv_unittest") {
275 testonly = true
276
277 sources = [
Frank Barchardb83bb382017-02-22 18:01:07 -0800278 # sources
Frank Barchardcead1e02017-03-10 12:03:05 -0800279 # headers
Frank Barchardb83bb382017-02-22 18:01:07 -0800280 "unit_test/basictypes_test.cc",
Frank Barchardb83bb382017-02-22 18:01:07 -0800281 "unit_test/color_test.cc",
Frank Barchardcead1e02017-03-10 12:03:05 -0800282 "unit_test/compare_test.cc",
Frank Barchardb83bb382017-02-22 18:01:07 -0800283 "unit_test/convert_test.cc",
284 "unit_test/cpu_test.cc",
Chong Zhangab123ac2019-06-27 14:28:37 -0700285 "unit_test/cpu_thread_test.cc",
Frank Barchardb83bb382017-02-22 18:01:07 -0800286 "unit_test/math_test.cc",
287 "unit_test/planar_test.cc",
288 "unit_test/rotate_argb_test.cc",
289 "unit_test/rotate_test.cc",
290 "unit_test/scale_argb_test.cc",
291 "unit_test/scale_test.cc",
292 "unit_test/unit_test.cc",
Frank Barchardcead1e02017-03-10 12:03:05 -0800293 "unit_test/unit_test.h",
Frank Barchardb83bb382017-02-22 18:01:07 -0800294 "unit_test/video_common_test.cc",
295 ]
296
297 deps = [
298 ":libyuv",
299 "//testing/gtest",
Frank Barchardb83bb382017-02-22 18:01:07 -0800300 ]
301
Frank Barchardb33a82f2017-04-18 11:28:09 -0700302 defines = []
303 if (libyuv_use_gflags) {
304 defines += [ "LIBYUV_USE_GFLAGS" ]
305 deps += [ "//third_party/gflags" ]
306 }
307
Frank Barchardb83bb382017-02-22 18:01:07 -0800308 configs += [ ":libyuv_unittest_warnings_config" ]
309
Frank Barchardcead1e02017-03-10 12:03:05 -0800310 public_deps = [
311 "//testing/gtest",
312 ]
Frank Barchardb83bb382017-02-22 18:01:07 -0800313 public_configs = [ ":libyuv_unittest_config" ]
314
Frank Barchardb83bb382017-02-22 18:01:07 -0800315 if (is_linux) {
316 cflags = [ "-fexceptions" ]
317 }
318 if (is_ios) {
319 configs -= [ "//build/config/compiler:default_symbols" ]
320 configs += [ "//build/config/compiler:symbols" ]
321 cflags = [ "-Wno-sometimes-uninitialized" ]
322 }
323 if (!is_ios && !libyuv_disable_jpeg) {
324 defines += [ "HAVE_JPEG" ]
325 }
326 if (is_android) {
327 deps += [ "//testing/android/native_test:native_test_native_code" ]
328 }
329
330 # TODO(YangZhang): These lines can be removed when high accuracy
331 # YUV to RGB to Neon is ported.
Frank Barchardcead1e02017-03-10 12:03:05 -0800332 if ((target_cpu == "armv7" || target_cpu == "armv7s" ||
333 (target_cpu == "arm" && arm_version >= 7) || target_cpu == "arm64") &&
Frank Barchardb83bb382017-02-22 18:01:07 -0800334 (arm_use_neon || arm_optionally_use_neon)) {
335 defines += [ "LIBYUV_NEON" ]
336 }
337
338 defines += [
339 # Enable the following 3 macros to turn off assembly for specified CPU.
340 # "LIBYUV_DISABLE_X86",
341 # "LIBYUV_DISABLE_NEON",
Frank Barchardb83bb382017-02-22 18:01:07 -0800342 # Enable the following macro to build libyuv as a shared library (dll).
343 # "LIBYUV_USING_SHARED_LIBRARY"
344 ]
345 }
346
347 executable("compare") {
348 sources = [
349 # sources
Frank Barchardcead1e02017-03-10 12:03:05 -0800350 "util/compare.cc",
Frank Barchardb83bb382017-02-22 18:01:07 -0800351 ]
Frank Barchardcead1e02017-03-10 12:03:05 -0800352 deps = [
353 ":libyuv",
354 ]
Frank Barchardb83bb382017-02-22 18:01:07 -0800355 if (is_linux) {
356 cflags = [ "-fexceptions" ]
357 }
358 }
359
Frank Barchardb33a82f2017-04-18 11:28:09 -0700360 executable("yuvconvert") {
Frank Barchardb83bb382017-02-22 18:01:07 -0800361 sources = [
362 # sources
Frank Barchardb33a82f2017-04-18 11:28:09 -0700363 "util/yuvconvert.cc",
Frank Barchardb83bb382017-02-22 18:01:07 -0800364 ]
Frank Barchardcead1e02017-03-10 12:03:05 -0800365 deps = [
366 ":libyuv",
367 ]
Frank Barchardb83bb382017-02-22 18:01:07 -0800368 if (is_linux) {
369 cflags = [ "-fexceptions" ]
370 }
371 }
372
373 executable("psnr") {
374 sources = [
375 # sources
Frank Barchardb83bb382017-02-22 18:01:07 -0800376 "util/psnr.cc",
Frank Barchardcead1e02017-03-10 12:03:05 -0800377 "util/psnr_main.cc",
378 "util/ssim.cc",
Frank Barchardb83bb382017-02-22 18:01:07 -0800379 ]
Frank Barchardcead1e02017-03-10 12:03:05 -0800380 deps = [
381 ":libyuv",
382 ]
Frank Barchardb83bb382017-02-22 18:01:07 -0800383
384 if (!is_ios && !libyuv_disable_jpeg) {
385 defines = [ "HAVE_JPEG" ]
386 }
387 }
388
389 executable("cpuid") {
390 sources = [
391 # sources
Frank Barchardcead1e02017-03-10 12:03:05 -0800392 "util/cpuid.c",
Frank Barchardb83bb382017-02-22 18:01:07 -0800393 ]
Frank Barchardcead1e02017-03-10 12:03:05 -0800394 deps = [
395 ":libyuv",
396 ]
Frank Barchardb83bb382017-02-22 18:01:07 -0800397 }
398}