2
0

BUILD.gn 9.5 KB

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