BUILD.gn 9.7 KB

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