• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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("libyuv.gni")
10import("//testing/test.gni")
11
12declare_args() {
13  # Set to false to disable building with gflags.
14  libyuv_use_gflags = true
15
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
20}
21
22config("libyuv_config") {
23  include_dirs = [ "include" ]
24  if (is_android && current_cpu == "arm64") {
25    ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker64" ]
26  }
27  if (is_android && current_cpu != "arm64") {
28    ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker" ]
29  }
30}
31
32# 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",
41      ":cpuid",
42      ":libyuv_unittest",
43      ":psnr",
44      ":yuvconvert",
45    ]
46  }
47}
48
49group("libyuv") {
50  all_dependent_configs = [ ":libyuv_config" ]
51  deps = []
52
53  if (is_win && target_cpu == "x64") {
54    # Compile with clang in order to get inline assembly
55    public_deps = [
56      ":libyuv_internal(//build/toolchain/win:win_clang_x64)",
57    ]
58  } else {
59    public_deps = [
60      ":libyuv_internal",
61    ]
62  }
63
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  }
82}
83
84static_library("libyuv_internal") {
85  visibility = [ ":*" ]
86
87  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",
129    "source/rotate_gcc.cc",
130    "source/rotate_win.cc",
131    "source/row_any.cc",
132    "source/row_common.cc",
133    "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",
139    "source/scale_gcc.cc",
140    "source/scale_win.cc",
141    "source/video_common.cc",
142  ]
143
144  configs += [ ":libyuv_config" ]
145  defines = []
146  deps = []
147
148  if (libyuv_symbols_visible) {
149    configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
150    configs += [ "//build/config/gcc:symbol_visibility_default" ]
151  }
152
153  if (!is_ios) {
154    defines += [ "HAVE_JPEG" ]
155
156    # 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" ]
159  }
160
161  # Always enable optimization for Release and NaCl builds (to workaround
162  # crbug.com/538243).
163  if (!is_debug || is_nacl) {
164    configs -= [ "//build/config/compiler:default_optimization" ]
165
166    # Enable optimize for speed (-O2) over size (-Os).
167    configs += [ "//build/config/compiler:optimize_max" ]
168  }
169
170  # To enable AVX2 or other cpu optimization, pass flag here
171  if (!is_win) {
172    cflags = [
173      # "-mpopcnt",
174      # "-mavx2",
175      # "-mfma",
176      "-ffp-contract=fast",  # Enable fma vectorization for NEON.
177    ]
178  }
179}
180
181if (libyuv_use_neon) {
182  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
195    deps = [
196      ":libyuv_internal",
197    ]
198
199    public_configs = [ ":libyuv_config" ]
200
201    # 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" ]
205
206      # Enable optimize for speed (-O2) over size (-Os).
207      # TODO(fbarchard): Consider optimize_speed which is O3.
208      configs += [ "//build/config/compiler:optimize_max" ]
209    }
210
211    if (current_cpu != "arm64") {
212      configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
213      cflags = [ "-mfpu=neon" ]
214    }
215  }
216}
217
218if (libyuv_use_msa) {
219  static_library("libyuv_msa") {
220    sources = [
221      # MSA Source Files
222      "source/compare_msa.cc",
223      "source/rotate_msa.cc",
224      "source/row_msa.cc",
225      "source/scale_msa.cc",
226    ]
227
228    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
250    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",
260        "-Wno-unused-variable",
261      ]
262    }
263    if (is_win) {
264      cflags = [
265        "/wd4245",  # signed/unsigned mismatch
266        "/wd4189",  # local variable is initialized but not referenced
267      ]
268    }
269  }
270  config("libyuv_unittest_config") {
271    defines = [ "GTEST_RELATIVE_PATH" ]
272  }
273
274  test("libyuv_unittest") {
275    testonly = true
276
277    sources = [
278      # sources
279      # headers
280      "unit_test/basictypes_test.cc",
281      "unit_test/color_test.cc",
282      "unit_test/compare_test.cc",
283      "unit_test/convert_test.cc",
284      "unit_test/cpu_test.cc",
285      "unit_test/cpu_thread_test.cc",
286      "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",
293      "unit_test/unit_test.h",
294      "unit_test/video_common_test.cc",
295    ]
296
297    deps = [
298      ":libyuv",
299      "//testing/gtest",
300    ]
301
302    defines = []
303    if (libyuv_use_gflags) {
304      defines += [ "LIBYUV_USE_GFLAGS" ]
305      deps += [ "//third_party/gflags" ]
306    }
307
308    configs += [ ":libyuv_unittest_warnings_config" ]
309
310    public_deps = [
311      "//testing/gtest",
312    ]
313    public_configs = [ ":libyuv_unittest_config" ]
314
315    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.
332    if ((target_cpu == "armv7" || target_cpu == "armv7s" ||
333         (target_cpu == "arm" && arm_version >= 7) || target_cpu == "arm64") &&
334        (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",
342      # 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
350      "util/compare.cc",
351    ]
352    deps = [
353      ":libyuv",
354    ]
355    if (is_linux) {
356      cflags = [ "-fexceptions" ]
357    }
358  }
359
360  executable("yuvconvert") {
361    sources = [
362      # sources
363      "util/yuvconvert.cc",
364    ]
365    deps = [
366      ":libyuv",
367    ]
368    if (is_linux) {
369      cflags = [ "-fexceptions" ]
370    }
371  }
372
373  executable("psnr") {
374    sources = [
375      # sources
376      "util/psnr.cc",
377      "util/psnr_main.cc",
378      "util/ssim.cc",
379    ]
380    deps = [
381      ":libyuv",
382    ]
383
384    if (!is_ios && !libyuv_disable_jpeg) {
385      defines = [ "HAVE_JPEG" ]
386    }
387  }
388
389  executable("cpuid") {
390    sources = [
391      # sources
392      "util/cpuid.c",
393    ]
394    deps = [
395      ":libyuv",
396    ]
397  }
398}
399