• 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
17config("libyuv_config") {
18  include_dirs = [ "include" ]
19  if (is_android && current_cpu == "arm64") {
20    ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker64" ]
21  }
22  if (is_android && current_cpu != "arm64") {
23    ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker" ]
24  }
25}
26
27# This target is built when no specific target is specified on the command line.
28group("default") {
29  testonly = true
30  deps = [
31    ":libyuv",
32  ]
33  if (libyuv_include_tests) {
34    deps += [
35      ":compare",
36      ":yuvconvert",
37      ":cpuid",
38      ":libyuv_unittest",
39      ":psnr",
40    ]
41  }
42}
43
44group("libyuv") {
45  public_configs = [ ":libyuv_config" ]
46
47  if (is_win && target_cpu == "x64") {
48    public_deps = [
49      ":libyuv_internal(//build/toolchain/win:clang_x64)",
50    ]
51  } else {
52    public_deps = [
53      ":libyuv_internal",
54    ]
55  }
56}
57
58static_library("libyuv_internal") {
59  sources = [
60    # Headers
61    "include/libyuv.h",
62    "include/libyuv/basic_types.h",
63    "include/libyuv/compare.h",
64    "include/libyuv/convert.h",
65    "include/libyuv/convert_argb.h",
66    "include/libyuv/convert_from.h",
67    "include/libyuv/convert_from_argb.h",
68    "include/libyuv/cpu_id.h",
69    "include/libyuv/mjpeg_decoder.h",
70    "include/libyuv/planar_functions.h",
71    "include/libyuv/rotate.h",
72    "include/libyuv/rotate_argb.h",
73    "include/libyuv/rotate_row.h",
74    "include/libyuv/row.h",
75    "include/libyuv/scale.h",
76    "include/libyuv/scale_argb.h",
77    "include/libyuv/scale_row.h",
78    "include/libyuv/version.h",
79    "include/libyuv/video_common.h",
80
81    # Source Files
82    "source/compare.cc",
83    "source/compare_common.cc",
84    "source/compare_gcc.cc",
85    "source/compare_win.cc",
86    "source/convert.cc",
87    "source/convert_argb.cc",
88    "source/convert_from.cc",
89    "source/convert_from_argb.cc",
90    "source/convert_jpeg.cc",
91    "source/convert_to_argb.cc",
92    "source/convert_to_i420.cc",
93    "source/cpu_id.cc",
94    "source/mjpeg_decoder.cc",
95    "source/mjpeg_validate.cc",
96    "source/planar_functions.cc",
97    "source/rotate.cc",
98    "source/rotate_any.cc",
99    "source/rotate_argb.cc",
100    "source/rotate_common.cc",
101    "source/rotate_dspr2.cc",
102    "source/rotate_gcc.cc",
103    "source/rotate_win.cc",
104    "source/row_any.cc",
105    "source/row_common.cc",
106    "source/row_dspr2.cc",
107    "source/row_gcc.cc",
108    "source/row_win.cc",
109    "source/scale.cc",
110    "source/scale_any.cc",
111    "source/scale_argb.cc",
112    "source/scale_common.cc",
113    "source/scale_dspr2.cc",
114    "source/scale_gcc.cc",
115    "source/scale_win.cc",
116    "source/video_common.cc",
117  ]
118
119  configs += [ ":libyuv_config" ]
120  defines = []
121  deps = []
122
123  if (!is_ios) {
124    defines += [ "HAVE_JPEG" ]
125    deps += [ "//third_party:jpeg" ]
126  }
127
128  if (libyuv_use_neon) {
129    deps += [ ":libyuv_neon" ]
130  }
131
132  if (libyuv_use_msa) {
133    deps += [ ":libyuv_msa" ]
134  }
135
136  # Always enable optimization for Release and NaCl builds (to workaround
137  # crbug.com/538243).
138  if (!is_debug || is_nacl) {
139    configs -= [ "//build/config/compiler:default_optimization" ]
140
141    # Enable optimize for speed (-O2) over size (-Os).
142    configs += [ "//build/config/compiler:optimize_max" ]
143  }
144
145  # To enable AVX2 or other cpu optimization, pass flag here
146  #  cflags = [ "-mavx2" ]
147}
148
149if (libyuv_use_neon) {
150  static_library("libyuv_neon") {
151    sources = [
152      # ARM Source Files
153      "source/compare_neon.cc",
154      "source/compare_neon64.cc",
155      "source/rotate_neon.cc",
156      "source/rotate_neon64.cc",
157      "source/row_neon.cc",
158      "source/row_neon64.cc",
159      "source/scale_neon.cc",
160      "source/scale_neon64.cc",
161    ]
162
163    public_configs = [ ":libyuv_config" ]
164
165    # Always enable optimization for Release and NaCl builds (to workaround
166    # crbug.com/538243).
167    if (!is_debug) {
168      configs -= [ "//build/config/compiler:default_optimization" ]
169
170      # Enable optimize for speed (-O2) over size (-Os).
171      configs += [ "//build/config/compiler:optimize_max" ]
172    }
173
174    if (current_cpu != "arm64") {
175      configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
176      cflags = [ "-mfpu=neon" ]
177    }
178  }
179}
180
181if (libyuv_use_msa) {
182  static_library("libyuv_msa") {
183    sources = [
184      # MSA Source Files
185      "source/rotate_msa.cc",
186      "source/row_msa.cc",
187      "source/scale_msa.cc",
188    ]
189
190    public_configs = [ ":libyuv_config" ]
191  }
192}
193
194if (libyuv_include_tests) {
195  config("libyuv_unittest_warnings_config") {
196    if (!is_win) {
197      cflags = [
198        # TODO(fbarchard): Fix sign and unused variable warnings.
199        "-Wno-sign-compare",
200        "-Wno-unused-variable",
201      ]
202    }
203    if (is_win) {
204      cflags = [
205        "/wd4245",  # signed/unsigned mismatch
206        "/wd4189",  # local variable is initialized but not referenced
207      ]
208    }
209  }
210  config("libyuv_unittest_config") {
211    defines = [ "GTEST_RELATIVE_PATH" ]
212  }
213
214  test("libyuv_unittest") {
215    testonly = true
216
217    sources = [
218      # sources
219      # headers
220      "unit_test/basictypes_test.cc",
221      "unit_test/color_test.cc",
222      "unit_test/compare_test.cc",
223      "unit_test/convert_test.cc",
224      "unit_test/cpu_test.cc",
225      "unit_test/math_test.cc",
226      "unit_test/planar_test.cc",
227      "unit_test/rotate_argb_test.cc",
228      "unit_test/rotate_test.cc",
229      "unit_test/scale_argb_test.cc",
230      "unit_test/scale_test.cc",
231      "unit_test/unit_test.cc",
232      "unit_test/unit_test.h",
233      "unit_test/video_common_test.cc",
234    ]
235
236    deps = [
237      ":libyuv",
238      "//testing/gtest",
239    ]
240
241    defines = []
242    if (libyuv_use_gflags) {
243      defines += [ "LIBYUV_USE_GFLAGS" ]
244      deps += [ "//third_party/gflags" ]
245    }
246
247    configs += [ ":libyuv_unittest_warnings_config" ]
248
249    public_deps = [
250      "//testing/gtest",
251    ]
252    public_configs = [ ":libyuv_unittest_config" ]
253
254    if (is_linux) {
255      cflags = [ "-fexceptions" ]
256    }
257    if (is_ios) {
258      configs -= [ "//build/config/compiler:default_symbols" ]
259      configs += [ "//build/config/compiler:symbols" ]
260      cflags = [ "-Wno-sometimes-uninitialized" ]
261    }
262    if (!is_ios && !libyuv_disable_jpeg) {
263      defines += [ "HAVE_JPEG" ]
264    }
265    if (is_android) {
266      deps += [ "//testing/android/native_test:native_test_native_code" ]
267    }
268
269    # TODO(YangZhang): These lines can be removed when high accuracy
270    # YUV to RGB to Neon is ported.
271    if ((target_cpu == "armv7" || target_cpu == "armv7s" ||
272         (target_cpu == "arm" && arm_version >= 7) || target_cpu == "arm64") &&
273        (arm_use_neon || arm_optionally_use_neon)) {
274      defines += [ "LIBYUV_NEON" ]
275    }
276
277    defines += [
278      # Enable the following 3 macros to turn off assembly for specified CPU.
279      # "LIBYUV_DISABLE_X86",
280      # "LIBYUV_DISABLE_NEON",
281      # "LIBYUV_DISABLE_DSPR2",
282      # Enable the following macro to build libyuv as a shared library (dll).
283      # "LIBYUV_USING_SHARED_LIBRARY"
284    ]
285  }
286
287  executable("compare") {
288    sources = [
289      # sources
290      "util/compare.cc",
291    ]
292    deps = [
293      ":libyuv",
294    ]
295    if (is_linux) {
296      cflags = [ "-fexceptions" ]
297    }
298  }
299
300  executable("yuvconvert") {
301    sources = [
302      # sources
303      "util/yuvconvert.cc",
304    ]
305    deps = [
306      ":libyuv",
307    ]
308    if (is_linux) {
309      cflags = [ "-fexceptions" ]
310    }
311  }
312
313  executable("psnr") {
314    sources = [
315      # sources
316      "util/psnr.cc",
317      "util/psnr_main.cc",
318      "util/ssim.cc",
319    ]
320    deps = [
321      ":libyuv",
322    ]
323
324    if (!is_ios && !libyuv_disable_jpeg) {
325      defines = [ "HAVE_JPEG" ]
326    }
327  }
328
329  executable("cpuid") {
330    sources = [
331      # sources
332      "util/cpuid.c",
333    ]
334    deps = [
335      ":libyuv",
336    ]
337  }
338}
339