BUILD.gn 9.13 KB
Newer Older
1 2 3 4 5 6 7 8
# Copyright 2014 The LibYuv Project Authors. All rights reserved.
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.

9 10
import("libyuv.gni")
import("//testing/test.gni")
11

12 13 14
declare_args() {
  # Set to false to disable building with gflags.
  libyuv_use_gflags = true
15 16 17 18 19

  # When building a shared library using a target in WebRTC or
  # Chromium projects that depends on libyuv, setting this flag
  # to true makes libyuv symbols visible inside that library.
  libyuv_symbols_visible = false
20 21
}

22
config("libyuv_config") {
23
  include_dirs = [ "include" ]
24
  if (is_android && current_cpu == "arm64") {
25 26 27 28 29
    ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker64" ]
  }
  if (is_android && current_cpu != "arm64") {
    ldflags = [ "-Wl,--dynamic-linker,/system/bin/linker" ]
  }
30 31
}

32 33 34 35 36 37 38 39 40 41 42 43
# This target is built when no specific target is specified on the command line.
group("default") {
  testonly = true
  deps = [
    ":libyuv",
  ]
  if (libyuv_include_tests) {
    deps += [
      ":compare",
      ":cpuid",
      ":libyuv_unittest",
      ":psnr",
44
      ":yuvconvert",
45 46 47 48
    ]
  }
}

49
group("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 61 62
      ":libyuv_internal",
    ]
  }
63

64 65 66 67 68 69 70 71
  if (libyuv_use_neon) {
    deps += [ ":libyuv_neon" ]
  }

  if (libyuv_use_msa) {
    deps += [ ":libyuv_msa" ]
  }

72 73 74 75
  if (!is_ios) {
    # Make sure that clients of libyuv link with libjpeg. This can't go in
    # libyuv_internal because in Windows x64 builds that will generate a clang
    # build of libjpeg, and we don't want two copies.
76
    deps += [ "//third_party:jpeg" ]
77
  }
78 79 80
}

static_library("libyuv_internal") {
81 82
  visibility = [ ":*" ]

83
  sources = [
84
    # Headers
85 86 87 88 89 90 91 92 93 94 95 96
    "include/libyuv.h",
    "include/libyuv/basic_types.h",
    "include/libyuv/compare.h",
    "include/libyuv/convert.h",
    "include/libyuv/convert_argb.h",
    "include/libyuv/convert_from.h",
    "include/libyuv/convert_from_argb.h",
    "include/libyuv/cpu_id.h",
    "include/libyuv/mjpeg_decoder.h",
    "include/libyuv/planar_functions.h",
    "include/libyuv/rotate.h",
    "include/libyuv/rotate_argb.h",
97
    "include/libyuv/rotate_row.h",
98 99 100 101 102 103 104
    "include/libyuv/row.h",
    "include/libyuv/scale.h",
    "include/libyuv/scale_argb.h",
    "include/libyuv/scale_row.h",
    "include/libyuv/version.h",
    "include/libyuv/video_common.h",

105
    # Source Files
106 107
    "source/compare.cc",
    "source/compare_common.cc",
108
    "source/compare_gcc.cc",
109 110 111 112 113 114 115 116 117 118 119 120 121
    "source/compare_win.cc",
    "source/convert.cc",
    "source/convert_argb.cc",
    "source/convert_from.cc",
    "source/convert_from_argb.cc",
    "source/convert_jpeg.cc",
    "source/convert_to_argb.cc",
    "source/convert_to_i420.cc",
    "source/cpu_id.cc",
    "source/mjpeg_decoder.cc",
    "source/mjpeg_validate.cc",
    "source/planar_functions.cc",
    "source/rotate.cc",
122
    "source/rotate_any.cc",
123
    "source/rotate_argb.cc",
124 125 126
    "source/rotate_common.cc",
    "source/rotate_gcc.cc",
    "source/rotate_win.cc",
127 128
    "source/row_any.cc",
    "source/row_common.cc",
129
    "source/row_gcc.cc",
130 131
    "source/row_win.cc",
    "source/scale.cc",
132
    "source/scale_any.cc",
133 134
    "source/scale_argb.cc",
    "source/scale_common.cc",
135
    "source/scale_gcc.cc",
136 137 138 139
    "source/scale_win.cc",
    "source/video_common.cc",
  ]

140
  configs += [ ":libyuv_config" ]
141
  defines = []
142
  deps = []
143

144 145 146 147 148
  if (libyuv_symbols_visible) {
    configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
    configs += [ "//build/config/gcc:symbol_visibility_default" ]
  }

149 150
  if (!is_ios) {
    defines += [ "HAVE_JPEG" ]
151 152 153 154

    # Needed to pull in libjpeg headers. Can't add //third_party:jpeg to deps
    # because in Windows x64 build it will get compiled with clang.
    deps += [ "//third_party:jpeg_includes" ]
155
  }
156

157 158 159
  # Always enable optimization for Release and NaCl builds (to workaround
  # crbug.com/538243).
  if (!is_debug || is_nacl) {
160
    configs -= [ "//build/config/compiler:default_optimization" ]
161

162
    # Enable optimize for speed (-O2) over size (-Os).
163 164
    configs += [ "//build/config/compiler:optimize_max" ]
  }
165 166

  # To enable AVX2 or other cpu optimization, pass flag here
167
  if (!is_win) {
168
    cflags = [
169 170 171
      # "-mpopcnt",
      # "-mavx2",
      # "-mfma",
172 173
      "-ffp-contract=fast",  # Enable fma vectorization for NEON.
    ]
174
  }
175
}
176

177
if (libyuv_use_neon) {
178 179
  static_library("libyuv_neon") {
    sources = [
180
      # ARM Source Files
181 182 183 184 185 186 187 188 189
      "source/compare_neon.cc",
      "source/compare_neon64.cc",
      "source/rotate_neon.cc",
      "source/rotate_neon64.cc",
      "source/row_neon.cc",
      "source/row_neon64.cc",
      "source/scale_neon.cc",
      "source/scale_neon64.cc",
    ]
190

191 192 193 194
    deps = [
      ":libyuv_internal",
    ]

195
    public_configs = [ ":libyuv_config" ]
196

197 198 199 200
    # Always enable optimization for Release and NaCl builds (to workaround
    # crbug.com/538243).
    if (!is_debug) {
      configs -= [ "//build/config/compiler:default_optimization" ]
201

202
      # Enable optimize for speed (-O2) over size (-Os).
203
      # TODO(fbarchard): Consider optimize_speed which is O3.
204 205 206
      configs += [ "//build/config/compiler:optimize_max" ]
    }

207 208 209 210
    if (current_cpu != "arm64") {
      configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
      cflags = [ "-mfpu=neon" ]
    }
211
  }
212
}
213

214 215 216 217
if (libyuv_use_msa) {
  static_library("libyuv_msa") {
    sources = [
      # MSA Source Files
218
      "source/compare_msa.cc",
219
      "source/rotate_msa.cc",
220
      "source/row_msa.cc",
221
      "source/scale_msa.cc",
222 223
    ]

224 225 226 227
    deps = [
      ":libyuv_internal",
    ]

228 229 230 231
    public_configs = [ ":libyuv_config" ]
  }
}

232 233 234 235 236 237
if (libyuv_include_tests) {
  config("libyuv_unittest_warnings_config") {
    if (!is_win) {
      cflags = [
        # TODO(fbarchard): Fix sign and unused variable warnings.
        "-Wno-sign-compare",
238
        "-Wno-unused-variable",
239 240 241 242
      ]
    }
    if (is_win) {
      cflags = [
243 244
        "/wd4245",  # signed/unsigned mismatch
        "/wd4189",  # local variable is initialized but not referenced
245 246 247 248 249 250 251 252 253 254 255 256
      ]
    }
  }
  config("libyuv_unittest_config") {
    defines = [ "GTEST_RELATIVE_PATH" ]
  }

  test("libyuv_unittest") {
    testonly = true

    sources = [
      # sources
257
      # headers
258 259
      "unit_test/basictypes_test.cc",
      "unit_test/color_test.cc",
260
      "unit_test/compare_test.cc",
261 262
      "unit_test/convert_test.cc",
      "unit_test/cpu_test.cc",
263
      "unit_test/cpu_thread_test.cc",
264 265 266 267 268 269 270
      "unit_test/math_test.cc",
      "unit_test/planar_test.cc",
      "unit_test/rotate_argb_test.cc",
      "unit_test/rotate_test.cc",
      "unit_test/scale_argb_test.cc",
      "unit_test/scale_test.cc",
      "unit_test/unit_test.cc",
271
      "unit_test/unit_test.h",
272 273 274 275 276 277 278 279
      "unit_test/video_common_test.cc",
    ]

    deps = [
      ":libyuv",
      "//testing/gtest",
    ]

280 281 282 283 284 285
    defines = []
    if (libyuv_use_gflags) {
      defines += [ "LIBYUV_USE_GFLAGS" ]
      deps += [ "//third_party/gflags" ]
    }

286 287
    configs += [ ":libyuv_unittest_warnings_config" ]

288 289 290
    public_deps = [
      "//testing/gtest",
    ]
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
    public_configs = [ ":libyuv_unittest_config" ]

    if (is_linux) {
      cflags = [ "-fexceptions" ]
    }
    if (is_ios) {
      configs -= [ "//build/config/compiler:default_symbols" ]
      configs += [ "//build/config/compiler:symbols" ]
      cflags = [ "-Wno-sometimes-uninitialized" ]
    }
    if (!is_ios && !libyuv_disable_jpeg) {
      defines += [ "HAVE_JPEG" ]
    }
    if (is_android) {
      deps += [ "//testing/android/native_test:native_test_native_code" ]
    }

    # TODO(YangZhang): These lines can be removed when high accuracy
    # YUV to RGB to Neon is ported.
310 311
    if ((target_cpu == "armv7" || target_cpu == "armv7s" ||
         (target_cpu == "arm" && arm_version >= 7) || target_cpu == "arm64") &&
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
        (arm_use_neon || arm_optionally_use_neon)) {
      defines += [ "LIBYUV_NEON" ]
    }

    defines += [
      # Enable the following 3 macros to turn off assembly for specified CPU.
      # "LIBYUV_DISABLE_X86",
      # "LIBYUV_DISABLE_NEON",
      # Enable the following macro to build libyuv as a shared library (dll).
      # "LIBYUV_USING_SHARED_LIBRARY"
    ]
  }

  executable("compare") {
    sources = [
      # sources
328 329 330 331
      "util/compare.cc",
    ]
    deps = [
      ":libyuv",
332 333 334 335 336 337
    ]
    if (is_linux) {
      cflags = [ "-fexceptions" ]
    }
  }

338
  executable("yuvconvert") {
339 340
    sources = [
      # sources
341
      "util/yuvconvert.cc",
342 343 344
    ]
    deps = [
      ":libyuv",
345 346 347 348 349 350 351 352 353 354
    ]
    if (is_linux) {
      cflags = [ "-fexceptions" ]
    }
  }

  executable("psnr") {
    sources = [
      # sources
      "util/psnr.cc",
355 356 357 358 359
      "util/psnr_main.cc",
      "util/ssim.cc",
    ]
    deps = [
      ":libyuv",
360 361 362 363 364 365 366 367 368 369
    ]

    if (!is_ios && !libyuv_disable_jpeg) {
      defines = [ "HAVE_JPEG" ]
    }
  }

  executable("cpuid") {
    sources = [
      # sources
370 371 372 373
      "util/cpuid.c",
    ]
    deps = [
      ":libyuv",
374 375 376
    ]
  }
}