xref: /aosp_15_r20/external/libyuv/BUILD.gn (revision 4e366538070a3a6c5c163c31b791eab742e1657a)
1# 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
9import("//build/config/features.gni")
10import("//testing/test.gni")
11import("libyuv.gni")
12
13declare_args() {
14  # Set to false to disable building with absl flags.
15  libyuv_use_absl_flags = true
16
17  # When building a shared library using a target in WebRTC or
18  # Chromium projects that depends on libyuv, setting this flag
19  # to true makes libyuv symbols visible inside that library.
20  libyuv_symbols_visible = false
21}
22
23config("libyuv_config") {
24  include_dirs = [ "include" ]
25  if (is_android) {
26    if (target_cpu == "arm" || target_cpu == "x86" || target_cpu == "mipsel") {
27      ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker" ]
28    } else {
29      ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker64" ]
30    }
31  }
32  defines = []
33  if (!libyuv_use_neon) {
34    defines += [ "LIBYUV_DISABLE_NEON" ]
35  }
36  if (libyuv_disable_rvv) {
37    defines += [ "LIBYUV_DISABLE_RVV" ]
38  }
39  if (!libyuv_use_lsx) {
40    defines += [ "LIBYUV_DISABLE_LSX" ]
41  }
42  if (!libyuv_use_lasx) {
43    defines += [ "LIBYUV_DISABLE_LASX" ]
44  }
45}
46
47# This target is built when no specific target is specified on the command line.
48group("default") {
49  testonly = true
50  deps = [ ":libyuv" ]
51  if (libyuv_include_tests) {
52    deps += [
53      ":compare",
54      ":cpuid",
55      ":i444tonv12_eg",
56      ":libyuv_unittest",
57      ":psnr",
58      ":yuvconstants",
59      ":yuvconvert",
60    ]
61  }
62}
63
64group("libyuv") {
65  all_dependent_configs = [ ":libyuv_config" ]
66  deps = []
67
68  if (is_win && target_cpu == "x64") {
69    # Compile with clang in order to get inline assembly
70    public_deps = [ ":libyuv_internal(//build/toolchain/win:win_clang_x64)" ]
71  } else {
72    public_deps = [ ":libyuv_internal" ]
73  }
74
75  if (libyuv_use_neon) {
76    deps += [ ":libyuv_neon" ]
77  }
78
79  if (libyuv_use_msa) {
80    deps += [ ":libyuv_msa" ]
81  }
82
83  if (libyuv_use_lsx) {
84    deps += [ ":libyuv_lsx" ]
85  }
86
87  if (libyuv_use_lasx) {
88    deps += [ ":libyuv_lasx" ]
89  }
90
91  if (!is_ios && !libyuv_disable_jpeg) {
92    # Make sure that clients of libyuv link with libjpeg. This can't go in
93    # libyuv_internal because in Windows x64 builds that will generate a clang
94    # build of libjpeg, and we don't want two copies.
95    deps += [ "//third_party:jpeg" ]
96  }
97}
98
99static_library("libyuv_internal") {
100  visibility = [ ":*" ]
101
102  sources = [
103    # Headers
104    "include/libyuv.h",
105    "include/libyuv/basic_types.h",
106    "include/libyuv/compare.h",
107    "include/libyuv/convert.h",
108    "include/libyuv/convert_argb.h",
109    "include/libyuv/convert_from.h",
110    "include/libyuv/convert_from_argb.h",
111    "include/libyuv/cpu_id.h",
112    "include/libyuv/mjpeg_decoder.h",
113    "include/libyuv/planar_functions.h",
114    "include/libyuv/rotate.h",
115    "include/libyuv/rotate_argb.h",
116    "include/libyuv/rotate_row.h",
117    "include/libyuv/row.h",
118    "include/libyuv/scale.h",
119    "include/libyuv/scale_argb.h",
120    "include/libyuv/scale_rgb.h",
121    "include/libyuv/scale_row.h",
122    "include/libyuv/scale_uv.h",
123    "include/libyuv/version.h",
124    "include/libyuv/video_common.h",
125
126    # Source Files
127    "source/compare.cc",
128    "source/compare_common.cc",
129    "source/compare_gcc.cc",
130    "source/compare_win.cc",
131    "source/convert.cc",
132    "source/convert_argb.cc",
133    "source/convert_from.cc",
134    "source/convert_from_argb.cc",
135    "source/convert_jpeg.cc",
136    "source/convert_to_argb.cc",
137    "source/convert_to_i420.cc",
138    "source/cpu_id.cc",
139    "source/mjpeg_decoder.cc",
140    "source/mjpeg_validate.cc",
141    "source/planar_functions.cc",
142    "source/rotate.cc",
143    "source/rotate_any.cc",
144    "source/rotate_argb.cc",
145    "source/rotate_common.cc",
146    "source/rotate_gcc.cc",
147    "source/rotate_win.cc",
148    "source/row_any.cc",
149    "source/row_common.cc",
150    "source/row_gcc.cc",
151    "source/row_rvv.cc",
152    "source/row_win.cc",
153    "source/scale.cc",
154    "source/scale_any.cc",
155    "source/scale_argb.cc",
156    "source/scale_common.cc",
157    "source/scale_gcc.cc",
158    "source/scale_rgb.cc",
159    "source/scale_rvv.cc",
160    "source/scale_uv.cc",
161    "source/scale_win.cc",
162    "source/video_common.cc",
163  ]
164
165  configs += [ ":libyuv_config" ]
166  defines = []
167  deps = []
168
169  if (libyuv_symbols_visible) {
170    configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
171    configs += [ "//build/config/gcc:symbol_visibility_default" ]
172  }
173
174  if ((!is_ios || use_blink) && !libyuv_disable_jpeg) {
175    defines += [ "HAVE_JPEG" ]
176
177    # Needed to pull in libjpeg headers. Can't add //third_party:jpeg to deps
178    # because in Windows x64 build it will get compiled with clang.
179    deps += [ "//third_party:jpeg_includes" ]
180  }
181
182  # Always enable optimization for Release and NaCl builds (to workaround
183  # crbug.com/538243).
184  if (!is_debug || is_nacl) {
185    configs -= [ "//build/config/compiler:default_optimization" ]
186
187    # Enable optimize for speed (-O2) over size (-Os).
188    configs += [ "//build/config/compiler:optimize_max" ]
189  }
190
191  # To enable AVX2 or other cpu optimization, pass flag here
192  if (!is_win) {
193    cflags = [
194      # "-mpopcnt",
195      # "-mavx2",
196      # "-mfma",
197      "-ffp-contract=fast",  # Enable fma vectorization for NEON.
198    ]
199  }
200}
201
202if (libyuv_use_neon) {
203  static_library("libyuv_neon") {
204    sources = [
205      # ARM Source Files
206      "source/compare_neon.cc",
207      "source/compare_neon64.cc",
208      "source/rotate_neon.cc",
209      "source/rotate_neon64.cc",
210      "source/row_neon.cc",
211      "source/row_neon64.cc",
212      "source/scale_neon.cc",
213      "source/scale_neon64.cc",
214    ]
215
216    deps = [ ":libyuv_internal" ]
217
218    public_configs = [ ":libyuv_config" ]
219
220    # Always enable optimization for Release and NaCl builds (to workaround
221    # crbug.com/538243).
222    if (!is_debug) {
223      configs -= [ "//build/config/compiler:default_optimization" ]
224
225      # Enable optimize for speed (-O2) over size (-Os).
226      # TODO(fbarchard): Consider optimize_speed which is O3.
227      configs += [ "//build/config/compiler:optimize_max" ]
228    }
229
230    if (current_cpu != "arm64") {
231      configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
232      cflags = [ "-mfpu=neon" ]
233    }
234  }
235}
236
237if (libyuv_use_msa) {
238  static_library("libyuv_msa") {
239    sources = [
240      # MSA Source Files
241      "source/compare_msa.cc",
242      "source/rotate_msa.cc",
243      "source/row_msa.cc",
244      "source/scale_msa.cc",
245    ]
246
247    deps = [ ":libyuv_internal" ]
248
249    public_configs = [ ":libyuv_config" ]
250  }
251}
252
253if (libyuv_use_lsx) {
254  static_library("libyuv_lsx") {
255    sources = [
256      # LSX Source Files
257      "source/rotate_lsx.cc",
258      "source/row_lsx.cc",
259      "source/scale_lsx.cc",
260    ]
261
262    cflags_cc = [
263      "-mlsx",
264      "-Wno-c++11-narrowing",
265    ]
266
267    deps = [ ":libyuv_internal" ]
268
269    public_configs = [ ":libyuv_config" ]
270  }
271}
272
273if (libyuv_use_lasx) {
274  static_library("libyuv_lasx") {
275    sources = [
276      # LASX Source Files
277      "source/row_lasx.cc",
278    ]
279
280    cflags_cc = [
281      "-mlasx",
282      "-Wno-c++11-narrowing",
283    ]
284
285    deps = [ ":libyuv_internal" ]
286
287    public_configs = [ ":libyuv_config" ]
288  }
289}
290
291if (libyuv_include_tests) {
292  config("libyuv_unittest_warnings_config") {
293    if (!is_win) {
294      cflags = [
295        # TODO(fbarchard): Fix sign and unused variable warnings.
296        "-Wno-sign-compare",
297        "-Wno-unused-variable",
298      ]
299    }
300    if (is_win) {
301      cflags = [
302        "/wd4245",  # signed/unsigned mismatch
303        "/wd4189",  # local variable is initialized but not referenced
304      ]
305    }
306  }
307  config("libyuv_unittest_config") {
308    defines = [ "GTEST_RELATIVE_PATH" ]
309  }
310
311  test("libyuv_unittest") {
312    testonly = true
313
314    sources = [
315      "unit_test/basictypes_test.cc",
316      "unit_test/color_test.cc",
317      "unit_test/compare_test.cc",
318      "unit_test/convert_argb_test.cc",
319      "unit_test/convert_test.cc",
320      "unit_test/cpu_test.cc",
321      "unit_test/cpu_thread_test.cc",
322      "unit_test/math_test.cc",
323      "unit_test/planar_test.cc",
324      "unit_test/rotate_argb_test.cc",
325      "unit_test/rotate_test.cc",
326      "unit_test/scale_argb_test.cc",
327      "unit_test/scale_plane_test.cc",
328      "unit_test/scale_rgb_test.cc",
329      "unit_test/scale_test.cc",
330      "unit_test/scale_uv_test.cc",
331      "unit_test/unit_test.cc",
332      "unit_test/unit_test.h",
333      "unit_test/video_common_test.cc",
334    ]
335
336    deps = [
337      ":libyuv",
338      "//testing/gtest",
339    ]
340
341    defines = []
342    if (libyuv_use_absl_flags) {
343      defines += [ "LIBYUV_USE_ABSL_FLAGS" ]
344      deps += [
345        "//third_party/abseil-cpp/absl/flags:flag",
346        "//third_party/abseil-cpp/absl/flags:parse",
347      ]
348    }
349
350    configs += [ ":libyuv_unittest_warnings_config" ]
351
352    public_deps = [ "//testing/gtest" ]
353    public_configs = [ ":libyuv_unittest_config" ]
354
355    if (is_linux || is_chromeos) {
356      cflags = [ "-fexceptions" ]
357    }
358    if (is_ios) {
359      configs -= [ "//build/config/compiler:default_symbols" ]
360      configs += [ "//build/config/compiler:symbols" ]
361      cflags = [ "-Wno-sometimes-uninitialized" ]
362    }
363    if (!is_ios && !libyuv_disable_jpeg) {
364      defines += [ "HAVE_JPEG" ]
365    }
366    if (is_android) {
367      deps += [ "//testing/android/native_test:native_test_native_code" ]
368    }
369
370    # TODO(YangZhang): These lines can be removed when high accuracy
371    # YUV to RGB to Neon is ported.
372    if ((target_cpu == "armv7" || target_cpu == "armv7s" ||
373         (target_cpu == "arm" && arm_version >= 7) || target_cpu == "arm64") &&
374        (arm_use_neon || arm_optionally_use_neon)) {
375      defines += [ "LIBYUV_NEON" ]
376    }
377
378    defines += [
379      # Enable the following 3 macros to turn off assembly for specified CPU.
380      # "LIBYUV_DISABLE_X86",
381      # "LIBYUV_DISABLE_NEON",
382      # Enable the following macro to build libyuv as a shared library (dll).
383      # "LIBYUV_USING_SHARED_LIBRARY"
384    ]
385  }
386
387  executable("compare") {
388    sources = [
389      # sources
390      "util/compare.cc",
391    ]
392    deps = [ ":libyuv" ]
393    if (is_linux || is_chromeos) {
394      cflags = [ "-fexceptions" ]
395    }
396  }
397
398  executable("yuvconvert") {
399    sources = [
400      # sources
401      "util/yuvconvert.cc",
402    ]
403    deps = [ ":libyuv" ]
404    if (is_linux || is_chromeos) {
405      cflags = [ "-fexceptions" ]
406    }
407  }
408
409  executable("yuvconstants") {
410    sources = [
411      # sources
412      "util/yuvconstants.c",
413    ]
414    deps = [ ":libyuv" ]
415    if (is_linux || is_chromeos) {
416      cflags = [ "-fexceptions" ]
417    }
418  }
419
420  executable("psnr") {
421    sources = [
422      # sources
423      "util/psnr.cc",
424      "util/psnr_main.cc",
425      "util/ssim.cc",
426    ]
427    deps = [ ":libyuv" ]
428
429    if (!is_ios && !libyuv_disable_jpeg) {
430      defines = [ "HAVE_JPEG" ]
431    }
432  }
433
434  executable("i444tonv12_eg") {
435    sources = [
436      # sources
437      "util/i444tonv12_eg.cc",
438    ]
439    deps = [ ":libyuv" ]
440  }
441
442  executable("cpuid") {
443    sources = [
444      # sources
445      "util/cpuid.c",
446    ]
447    deps = [ ":libyuv" ]
448  }
449}
450