BUILD.gn 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. # Copyright 2014 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import("//build/config/android/config.gni")
  5. import("//build/config/arm.gni")
  6. import("//build/config/chromeos/ui_mode.gni")
  7. import("//build/config/sanitizers/sanitizers.gni")
  8. import("//third_party/libvpx/libvpx_srcs.gni")
  9. import("//third_party/nasm/nasm_assemble.gni")
  10. # Sets the architecture name for building libvpx.
  11. if (current_cpu == "x86") {
  12. cpu_arch_full = "ia32"
  13. } else if (current_cpu == "x64") {
  14. if (is_msan) {
  15. cpu_arch_full = "generic"
  16. } else {
  17. cpu_arch_full = "x64"
  18. }
  19. } else if (current_cpu == "arm") {
  20. if (is_chromeos) {
  21. # ChromeOS gets highbd vp9 but other arm targets do not.
  22. cpu_arch_full = "arm-neon-highbd"
  23. } else if (arm_use_neon) {
  24. cpu_arch_full = "arm-neon"
  25. } else if (is_android) {
  26. cpu_arch_full = "arm-neon-cpu-detect"
  27. } else {
  28. cpu_arch_full = "arm"
  29. }
  30. } else if (current_cpu == "arm64") {
  31. if (is_chromeos || is_mac) {
  32. cpu_arch_full = "arm64-highbd"
  33. } else {
  34. cpu_arch_full = current_cpu
  35. }
  36. } else if (current_cpu == "riscv64") {
  37. cpu_arch_full = "generic"
  38. } else {
  39. cpu_arch_full = current_cpu
  40. }
  41. if (is_nacl) {
  42. platform_include_dir = "source/config/nacl"
  43. } else {
  44. # The mac configurations are currently a relic. They were useful when
  45. # x86inc.asm did not work for MACH_O but now the build is identical to the
  46. # linux config. iOS for arm on the other hand needs an apple-specific twist in
  47. # vpx_config.asm
  48. if (is_ios && current_cpu == "arm") {
  49. os_category = current_os
  50. } else if (is_posix || is_fuchsia) {
  51. # Should cover linux, fuchsia, mac, and the ios simulator.
  52. os_category = "linux"
  53. } else { # This should only match windows.
  54. os_category = current_os
  55. }
  56. platform_include_dir = "source/config/$os_category/$cpu_arch_full"
  57. }
  58. libvpx_include_dirs = [
  59. "source/config",
  60. platform_include_dir,
  61. "source/libvpx",
  62. ]
  63. config("libvpx_config") {
  64. include_dirs = libvpx_include_dirs
  65. # gn orders flags on a target before flags from configs. The default config
  66. # adds -Wall, and these flags have to be after -Wall -- so they need to come
  67. # from a config and can't be on the target directly.
  68. if (is_clang) {
  69. cflags = [
  70. # libvpx heavily relies on implicit enum casting.
  71. "-Wno-conversion",
  72. # libvpx does `if ((a == b))` in some places.
  73. "-Wno-parentheses-equality",
  74. # libvpx has many static functions in header, which trigger this warning.
  75. "-Wno-unused-function",
  76. ]
  77. } else if (!is_win) {
  78. cflags = [
  79. "-Wno-unused-function",
  80. "-Wno-sign-compare",
  81. ]
  82. }
  83. }
  84. # This config is applied to targets that depend on libvpx.
  85. config("libvpx_external_config") {
  86. include_dirs = [ "source/libvpx" ]
  87. }
  88. if (current_cpu == "x86" || (current_cpu == "x64" && !is_msan)) {
  89. nasm_assemble("libvpx_asm") {
  90. if (current_cpu == "x86") {
  91. sources = libvpx_srcs_x86_assembly
  92. } else if (current_cpu == "x64") {
  93. sources = libvpx_srcs_x86_64_assembly
  94. }
  95. defines = [ "CHROMIUM" ]
  96. if (is_android) {
  97. # On Android, define __ANDROID__ to use alternative standard library
  98. # functions.
  99. defines += [ "__ANDROID__" ]
  100. }
  101. include_dirs = libvpx_include_dirs
  102. }
  103. }
  104. if (current_cpu == "x86" || (current_cpu == "x64" && !is_msan)) {
  105. # The following targets are deliberately source_set rather than
  106. # static_library. The :libvpx target exposes these intrinsic implementations
  107. # via global function pointer symbols, which hides the object dependency at
  108. # link time. On Mac, this results in undefined references to the intrinsic
  109. # symbols.
  110. source_set("libvpx_intrinsics_mmx") {
  111. configs -= [ "//build/config/compiler:chromium_code" ]
  112. configs += [ "//build/config/compiler:no_chromium_code" ]
  113. configs += [ ":libvpx_config" ]
  114. if (!is_win) {
  115. cflags = [ "-mmmx" ]
  116. }
  117. if (current_cpu == "x86") {
  118. sources = libvpx_srcs_x86_mmx
  119. deps = [ ":libvpx_x86_headers" ]
  120. } else if (current_cpu == "x64") {
  121. sources = libvpx_srcs_x86_64_mmx
  122. deps = [ ":libvpx_x86_64_headers" ]
  123. }
  124. }
  125. source_set("libvpx_intrinsics_sse2") {
  126. configs -= [ "//build/config/compiler:chromium_code" ]
  127. configs += [ "//build/config/compiler:no_chromium_code" ]
  128. configs += [ ":libvpx_config" ]
  129. if (!is_win || is_clang) {
  130. cflags = [ "-msse2" ]
  131. }
  132. if (current_cpu == "x86") {
  133. sources = libvpx_srcs_x86_sse2
  134. deps = [ ":libvpx_x86_headers" ]
  135. } else if (current_cpu == "x64") {
  136. sources = libvpx_srcs_x86_64_sse2
  137. deps = [ ":libvpx_x86_64_headers" ]
  138. }
  139. }
  140. source_set("libvpx_intrinsics_ssse3") {
  141. configs -= [ "//build/config/compiler:chromium_code" ]
  142. configs += [ "//build/config/compiler:no_chromium_code" ]
  143. configs += [ ":libvpx_config" ]
  144. if (!is_win || is_clang) {
  145. cflags = [ "-mssse3" ]
  146. }
  147. if (current_cpu == "x86") {
  148. sources = libvpx_srcs_x86_ssse3
  149. deps = [ ":libvpx_x86_headers" ]
  150. } else if (current_cpu == "x64") {
  151. sources = libvpx_srcs_x86_64_ssse3
  152. deps = [ ":libvpx_x86_64_headers" ]
  153. }
  154. }
  155. source_set("libvpx_intrinsics_sse4_1") {
  156. configs -= [ "//build/config/compiler:chromium_code" ]
  157. configs += [ "//build/config/compiler:no_chromium_code" ]
  158. configs += [ ":libvpx_config" ]
  159. if (!is_win || is_clang) {
  160. cflags = [ "-msse4.1" ]
  161. }
  162. if (current_cpu == "x86") {
  163. deps = [ ":libvpx_x86_headers" ]
  164. sources = libvpx_srcs_x86_sse4_1
  165. } else if (current_cpu == "x64") {
  166. deps = [ ":libvpx_x86_64_headers" ]
  167. sources = libvpx_srcs_x86_64_sse4_1
  168. }
  169. }
  170. source_set("libvpx_intrinsics_avx") {
  171. configs -= [ "//build/config/compiler:chromium_code" ]
  172. configs += [ "//build/config/compiler:no_chromium_code" ]
  173. configs += [ ":libvpx_config" ]
  174. if (is_win) {
  175. cflags = [ "/arch:AVX" ]
  176. } else {
  177. cflags = [ "-mavx" ]
  178. }
  179. if (current_cpu == "x86") {
  180. deps = [ ":libvpx_x86_headers" ]
  181. sources = libvpx_srcs_x86_avx
  182. } else if (current_cpu == "x64") {
  183. deps = [ ":libvpx_x86_64_headers" ]
  184. sources = libvpx_srcs_x86_64_avx
  185. }
  186. }
  187. source_set("libvpx_intrinsics_avx2") {
  188. configs -= [ "//build/config/compiler:chromium_code" ]
  189. configs += [ "//build/config/compiler:no_chromium_code" ]
  190. configs += [ ":libvpx_config" ]
  191. if (is_win) {
  192. cflags = [ "/arch:AVX2" ]
  193. } else {
  194. cflags = [ "-mavx2" ]
  195. }
  196. if (current_cpu == "x86") {
  197. deps = [ ":libvpx_x86_headers" ]
  198. sources = libvpx_srcs_x86_avx2
  199. } else if (current_cpu == "x64") {
  200. deps = [ ":libvpx_x86_64_headers" ]
  201. sources = libvpx_srcs_x86_64_avx2
  202. }
  203. }
  204. source_set("libvpx_intrinsics_avx512") {
  205. configs -= [ "//build/config/compiler:chromium_code" ]
  206. configs += [ "//build/config/compiler:no_chromium_code" ]
  207. configs += [ ":libvpx_config" ]
  208. if (is_win) {
  209. # clang-cl does not accept this flag.
  210. # https://bugs.chromium.org/p/chromium/issues/detail?id=783370
  211. cflags = [ "/arch:AVX512" ]
  212. } else {
  213. cflags = [
  214. "-mavx512f",
  215. "-mavx512cd",
  216. "-mavx512bw",
  217. "-mavx512dq",
  218. "-mavx512vl",
  219. ]
  220. }
  221. if (current_cpu == "x86") {
  222. deps = [ ":libvpx_x86_headers" ]
  223. sources = libvpx_srcs_x86_avx512
  224. } else if (current_cpu == "x64") {
  225. deps = [ ":libvpx_x86_64_headers" ]
  226. sources = libvpx_srcs_x86_64_avx512
  227. }
  228. }
  229. }
  230. if (cpu_arch_full == "arm-neon-cpu-detect") {
  231. static_library("libvpx_intrinsics_neon") {
  232. configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
  233. configs += [ ":libvpx_config" ]
  234. cflags = [ "-mfpu=neon" ]
  235. sources = libvpx_srcs_arm_neon_cpu_detect_neon
  236. deps = [ ":libvpx_arm_neon_cpu_detect_headers" ]
  237. }
  238. }
  239. if (current_cpu == "arm") {
  240. if (cpu_arch_full == "arm-neon") {
  241. arm_assembly_sources = libvpx_srcs_arm_neon_assembly
  242. } else if (cpu_arch_full == "arm-neon-highbd") {
  243. arm_assembly_sources = libvpx_srcs_arm_neon_highbd_assembly
  244. } else if (cpu_arch_full == "arm-neon-cpu-detect") {
  245. arm_assembly_sources = libvpx_srcs_arm_neon_cpu_detect_assembly
  246. } else {
  247. arm_assembly_sources = libvpx_srcs_arm_assembly
  248. }
  249. }
  250. # Converts ARM assembly files to GAS style.
  251. if (current_cpu == "arm" && arm_assembly_sources != []) {
  252. action_foreach("convert_arm_assembly") {
  253. script = "//third_party/libvpx/run_perl.py"
  254. sources = arm_assembly_sources
  255. gen_file =
  256. get_label_info("//third_party/libvpx/source/libvpx", "root_gen_dir") +
  257. "/{{source_root_relative_dir}}/{{source_file_part}}.S"
  258. outputs = [ gen_file ]
  259. if (is_ios) {
  260. ads2gas_script =
  261. "//third_party/libvpx/source/libvpx/build/make/ads2gas_apple.pl"
  262. } else {
  263. ads2gas_script =
  264. "//third_party/libvpx/source/libvpx/build/make/ads2gas.pl"
  265. }
  266. args = [
  267. "-s",
  268. rebase_path(ads2gas_script, root_build_dir),
  269. "-i",
  270. "{{source}}",
  271. "-o",
  272. rebase_path(gen_file, root_build_dir),
  273. ]
  274. }
  275. static_library("libvpx_assembly_arm") {
  276. sources = get_target_outputs(":convert_arm_assembly")
  277. configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
  278. configs += [ ":libvpx_config" ]
  279. if (cpu_arch_full == "arm-neon" || cpu_arch_full == "arm-neon-cpu-detect" ||
  280. cpu_arch_full == "arm-neon-highbd") {
  281. asmflags = [ "-mfpu=neon" ]
  282. # allow asm files to include generated sources which match the source
  283. # tree layout, e.g., vpx_dsp/arm/...
  284. include_dirs = [ get_label_info("//third_party/libvpx/source/libvpx",
  285. "target_gen_dir") ]
  286. }
  287. deps = [ ":convert_arm_assembly" ]
  288. }
  289. }
  290. source_set("libvpx_x86_headers") {
  291. sources = libvpx_srcs_x86_headers
  292. }
  293. source_set("libvpx_x86_64_headers") {
  294. sources = libvpx_srcs_x86_64_headers
  295. }
  296. source_set("libvpx_arm_headers") {
  297. sources = libvpx_srcs_arm_headers
  298. }
  299. source_set("libvpx_arm_neon_headers") {
  300. sources = libvpx_srcs_arm_neon_headers
  301. }
  302. source_set("libvpx_arm_neon_cpu_detect_headers") {
  303. sources = libvpx_srcs_arm_neon_cpu_detect_headers
  304. }
  305. source_set("libvpx_arm64_headers") {
  306. sources = libvpx_srcs_arm64_headers
  307. }
  308. source_set("libvpx_arm_neon_highbd_headers") {
  309. sources = libvpx_srcs_arm_neon_highbd_headers
  310. }
  311. source_set("libvpx_arm64_highbd_headers") {
  312. sources = libvpx_srcs_arm64_highbd_headers
  313. }
  314. source_set("libvpx_mips_headers") {
  315. sources = libvpx_srcs_mips_headers
  316. }
  317. source_set("libvpx_nacl_headers") {
  318. sources = libvpx_srcs_nacl_headers
  319. }
  320. source_set("libvpx_generic_headers") {
  321. sources = libvpx_srcs_generic_headers
  322. }
  323. static_library("libvpx") {
  324. if (!is_debug && (is_win || is_chromeos)) {
  325. configs -= [ "//build/config/compiler:default_optimization" ]
  326. configs += [ "//build/config/compiler:optimize_max" ]
  327. }
  328. if (is_nacl) {
  329. sources = libvpx_srcs_generic
  330. public_deps = [ ":libvpx_generic_headers" ]
  331. } else if (current_cpu == "x86") {
  332. sources = libvpx_srcs_x86
  333. public_deps = [ ":libvpx_x86_headers" ]
  334. } else if (current_cpu == "x64") {
  335. if (is_msan) {
  336. sources = libvpx_srcs_generic
  337. public_deps = [ ":libvpx_generic_headers" ]
  338. } else {
  339. sources = libvpx_srcs_x86_64
  340. public_deps = [ ":libvpx_x86_64_headers" ]
  341. }
  342. } else if (current_cpu == "mipsel" || current_cpu == "mips64el") {
  343. sources = libvpx_srcs_mips
  344. public_deps = [ ":libvpx_mips_headers" ]
  345. } else if (current_cpu == "arm") {
  346. if (is_chromeos) {
  347. sources = libvpx_srcs_arm_neon_highbd
  348. public_deps = [ ":libvpx_arm_neon_highbd_headers" ]
  349. } else if (arm_use_neon) {
  350. sources = libvpx_srcs_arm_neon
  351. public_deps = [ ":libvpx_arm_neon_headers" ]
  352. } else if (is_android) {
  353. sources = libvpx_srcs_arm_neon_cpu_detect
  354. public_deps = [ ":libvpx_arm_neon_cpu_detect_headers" ]
  355. } else {
  356. sources = libvpx_srcs_arm
  357. public_deps = [ ":libvpx_arm_headers" ]
  358. }
  359. } else if (current_cpu == "arm64") {
  360. if (is_chromeos || is_win || is_mac) {
  361. sources = libvpx_srcs_arm64_highbd
  362. public_deps = [ ":libvpx_arm64_highbd_headers" ]
  363. } else {
  364. sources = libvpx_srcs_arm64
  365. public_deps = [ ":libvpx_arm64_headers" ]
  366. }
  367. } else if (current_cpu == "ppc64") {
  368. sources = libvpx_srcs_ppc64
  369. } else if (current_cpu == "riscv64") {
  370. sources = libvpx_srcs_generic
  371. public_deps = [ ":libvpx_generic_headers" ]
  372. }
  373. configs -= [ "//build/config/compiler:chromium_code" ]
  374. configs += [ "//build/config/compiler:no_chromium_code" ]
  375. configs += [ ":libvpx_config" ]
  376. deps = []
  377. if (current_cpu == "x86" || (current_cpu == "x64" && !is_msan)) {
  378. deps += [
  379. ":libvpx_asm",
  380. ":libvpx_intrinsics_avx",
  381. ":libvpx_intrinsics_avx2",
  382. ":libvpx_intrinsics_avx512",
  383. ":libvpx_intrinsics_mmx",
  384. ":libvpx_intrinsics_sse2",
  385. ":libvpx_intrinsics_sse4_1",
  386. ":libvpx_intrinsics_ssse3",
  387. ]
  388. }
  389. if (cpu_arch_full == "arm-neon-cpu-detect") {
  390. deps += [ ":libvpx_intrinsics_neon" ]
  391. }
  392. if (is_android) {
  393. deps += [ "//third_party/android_ndk:cpu_features" ]
  394. }
  395. if (current_cpu == "arm" && arm_assembly_sources != []) {
  396. deps += [ ":libvpx_assembly_arm" ]
  397. }
  398. public_configs = [ ":libvpx_external_config" ]
  399. }
  400. static_library("libvpxrc") {
  401. if (!is_debug && is_win) {
  402. configs -= [ "//build/config/compiler:default_optimization" ]
  403. configs += [ "//build/config/compiler:optimize_max" ]
  404. }
  405. sources = [
  406. "//third_party/libvpx/source/libvpx/vp8/vp8_ratectrl_rtc.cc",
  407. "//third_party/libvpx/source/libvpx/vp8/vp8_ratectrl_rtc.h",
  408. "//third_party/libvpx/source/libvpx/vp9/ratectrl_rtc.cc",
  409. "//third_party/libvpx/source/libvpx/vp9/ratectrl_rtc.h",
  410. "//third_party/libvpx/source/libvpx/vpx/internal/vpx_ratectrl_rtc.h",
  411. ]
  412. configs -= [ "//build/config/compiler:chromium_code" ]
  413. configs += [ "//build/config/compiler:no_chromium_code" ]
  414. configs += [ ":libvpx_config" ]
  415. public_deps = [ ":libvpx" ]
  416. public_configs = [ ":libvpx_external_config" ]
  417. }