BUILD.gn 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. # Copyright (c) 2013 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/c++/c++.gni")
  5. import("//build/config/chrome_build.gni")
  6. import("//build/config/chromecast_build.gni")
  7. import("//build/config/dcheck_always_on.gni")
  8. import("//build/config/features.gni")
  9. # Subprojects need to override arguments in {mac,ios}_sdk_overrides.gni in their
  10. # .gn config, but those arguments are only used on macOS. Including
  11. # mac_sdk_overrides.gni insures that this doesn't trigger an unused argument
  12. # warning.
  13. import("//build/config/ios/ios_sdk_overrides.gni")
  14. import("//build/config/mac/mac_sdk_overrides.gni")
  15. import("//build/config/pch.gni")
  16. import("//build/config/sanitizers/sanitizers.gni")
  17. import("//build/config/ui.gni")
  18. import("//build/toolchain/goma.gni")
  19. if (is_android) {
  20. import("//build/config/android/abi.gni")
  21. }
  22. # ==============================================
  23. # PLEASE DO NOT ADD MORE THINGS TO THIS LIST
  24. # ==============================================
  25. #
  26. # Legacy feature defines applied to all targets.
  27. #
  28. # These are applied to every single compile in the build and most of them are
  29. # only relevant to a few files. This bloats command lines and causes
  30. # unnecessary recompiles when flags are flipped.
  31. #
  32. # To pass defines to source code from the build, use the buildflag system which
  33. # will write headers containing the defines you need. This isolates the define
  34. # and means its definition can participate in the build graph, only recompiling
  35. # things when it actually changes.
  36. #
  37. # See //build/buildflag_header.gni for instructions on generating headers.
  38. #
  39. # This will also allow you to scope your build flag to a BUILD.gn file (or a
  40. # .gni file if you need it from more than one place) rather than making global
  41. # flags. See //build/config/BUILDCONFIG.gn for advice on where to define
  42. # build flags.
  43. config("feature_flags") {
  44. defines = []
  45. if (dcheck_always_on) {
  46. defines += [ "DCHECK_ALWAYS_ON=1" ]
  47. }
  48. if (use_udev) {
  49. # TODO(brettw) should probably be "=1".
  50. defines += [ "USE_UDEV" ]
  51. }
  52. if (use_aura) {
  53. defines += [ "USE_AURA=1" ]
  54. }
  55. if (use_glib) {
  56. defines += [ "USE_GLIB=1" ]
  57. }
  58. if (use_ozone && !is_android) {
  59. # Note that some Chrome OS builds unconditionally set |use_ozone| to true,
  60. # but they also build some targets with the Android toolchain. This ensures
  61. # that Android targets still build with USE_OZONE=0 in such cases.
  62. #
  63. # TODO(crbug.com/837032): Maybe this can be cleaned up if we can avoid
  64. # setting use_ozone globally.
  65. defines += [ "USE_OZONE=1" ]
  66. }
  67. if (is_asan || is_hwasan || is_lsan || is_tsan || is_msan) {
  68. defines += [ "MEMORY_TOOL_REPLACES_ALLOCATOR" ]
  69. }
  70. if (is_asan) {
  71. defines += [ "ADDRESS_SANITIZER" ]
  72. }
  73. if (is_lsan) {
  74. defines += [ "LEAK_SANITIZER" ]
  75. }
  76. if (is_tsan) {
  77. defines += [
  78. "THREAD_SANITIZER",
  79. "DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL=1",
  80. ]
  81. }
  82. if (is_msan) {
  83. defines += [ "MEMORY_SANITIZER" ]
  84. }
  85. if (is_ubsan || is_ubsan_vptr || is_ubsan_security) {
  86. defines += [ "UNDEFINED_SANITIZER" ]
  87. }
  88. if (is_official_build) {
  89. defines += [ "OFFICIAL_BUILD" ]
  90. }
  91. # ==============================================
  92. # PLEASE DO NOT ADD MORE THINGS TO THIS LIST
  93. # ==============================================
  94. #
  95. # See the comment at the top.
  96. }
  97. # Debug/release ----------------------------------------------------------------
  98. config("debug") {
  99. defines = [
  100. "_DEBUG",
  101. "DYNAMIC_ANNOTATIONS_ENABLED=1",
  102. ]
  103. if (is_nacl) {
  104. defines += [ "DYNAMIC_ANNOTATIONS_PREFIX=NACL_" ]
  105. }
  106. if (is_win) {
  107. if (!enable_iterator_debugging && !use_custom_libcxx) {
  108. # Iterator debugging is enabled by default by the compiler on debug
  109. # builds, and we have to tell it to turn it off.
  110. defines += [ "_HAS_ITERATOR_DEBUGGING=0" ]
  111. }
  112. } else if ((is_linux || is_chromeos) && current_cpu == "x64" &&
  113. enable_iterator_debugging) {
  114. # Enable libstdc++ debugging facilities to help catch problems early, see
  115. # http://crbug.com/65151 .
  116. # TODO(phajdan.jr): Should we enable this for all of POSIX?
  117. defines += [ "_GLIBCXX_DEBUG=1" ]
  118. }
  119. }
  120. config("release") {
  121. defines = [ "NDEBUG" ]
  122. # Sanitizers.
  123. if (is_tsan) {
  124. defines += [ "DYNAMIC_ANNOTATIONS_ENABLED=1" ]
  125. } else {
  126. defines += [ "NVALGRIND" ]
  127. if (!is_nacl) {
  128. # NaCl always enables dynamic annotations. Currently this value is set to
  129. # 1 for all .nexes.
  130. defines += [ "DYNAMIC_ANNOTATIONS_ENABLED=0" ]
  131. }
  132. }
  133. if (is_ios) {
  134. # Disable NSAssert and GTMDevAssert (from Google Toolbox for Mac). This
  135. # follows XCode's default behavior for Release builds.
  136. defines += [ "NS_BLOCK_ASSERTIONS=1" ]
  137. }
  138. }
  139. # Default libraries ------------------------------------------------------------
  140. # This config defines the default libraries applied to all targets.
  141. config("default_libs") {
  142. if (is_win) {
  143. # TODO(brettw) this list of defaults should probably be smaller, and
  144. # instead the targets that use the less common ones (e.g. wininet or
  145. # winspool) should include those explicitly.
  146. libs = [
  147. "advapi32.lib",
  148. "comdlg32.lib",
  149. "dbghelp.lib",
  150. "dnsapi.lib",
  151. "gdi32.lib",
  152. "msimg32.lib",
  153. "odbc32.lib",
  154. "odbccp32.lib",
  155. "oleaut32.lib",
  156. "shell32.lib",
  157. "shlwapi.lib",
  158. "user32.lib",
  159. "usp10.lib",
  160. "uuid.lib",
  161. "version.lib",
  162. "wininet.lib",
  163. "winmm.lib",
  164. "winspool.lib",
  165. "ws2_32.lib",
  166. # Please don't add more stuff here. We should actually be making this
  167. # list smaller, since all common things should be covered. If you need
  168. # some extra libraries, please just add a libs = [ "foo.lib" ] to your
  169. # target that needs it.
  170. ]
  171. if (current_os == "winuwp") {
  172. # These libraries are needed for Windows UWP (i.e. store apps).
  173. libs += [
  174. "dloadhelper.lib",
  175. "WindowsApp.lib",
  176. ]
  177. } else {
  178. # These libraries are not compatible with Windows UWP (i.e. store apps.)
  179. libs += [
  180. "delayimp.lib",
  181. "kernel32.lib",
  182. "ole32.lib",
  183. ]
  184. }
  185. } else if (is_android) {
  186. libs = [
  187. "dl",
  188. "m",
  189. ]
  190. } else if (is_mac) {
  191. # Targets should choose to explicitly link frameworks they require. Since
  192. # linking can have run-time side effects, nothing should be listed here.
  193. libs = []
  194. } else if (is_ios) {
  195. # The libraries listed here will be specified for both the target and the
  196. # host. Only the common ones should be listed here.
  197. frameworks = [
  198. "CoreFoundation.framework",
  199. "CoreGraphics.framework",
  200. "CoreText.framework",
  201. "Foundation.framework",
  202. ]
  203. } else if (is_linux || is_chromeos) {
  204. libs = [
  205. "dl",
  206. "pthread",
  207. "rt",
  208. ]
  209. }
  210. }
  211. group("common_deps") {
  212. visibility = [
  213. ":executable_deps",
  214. ":loadable_module_deps",
  215. ":shared_library_deps",
  216. ]
  217. # WARNING: This group is a dependency of **every executable and shared
  218. # library**. Please be careful adding new dependencies here.
  219. public_deps = []
  220. if (using_sanitizer) {
  221. public_deps += [ "//build/config/sanitizers:deps" ]
  222. }
  223. if (use_custom_libcxx) {
  224. public_deps += [ "//buildtools/third_party/libc++" ]
  225. }
  226. if (use_afl) {
  227. public_deps += [ "//third_party/afl" ]
  228. }
  229. if (is_android && use_order_profiling) {
  230. public_deps += [ "//base/android/orderfile:orderfile_instrumentation" ]
  231. }
  232. if (is_fuchsia) {
  233. public_deps +=
  234. [ "//third_party/fuchsia-sdk/sdk/build/config:runtime_library_group" ]
  235. if (is_asan) {
  236. public_deps += [ "//build/config/fuchsia:asan_runtime_library" ]
  237. }
  238. }
  239. }
  240. # Only the executable template in BUILDCONFIG.gn should reference this.
  241. group("executable_deps") {
  242. public_deps = [ ":common_deps" ]
  243. if (export_libcxxabi_from_executables) {
  244. public_deps += [ "//buildtools/third_party/libc++abi" ]
  245. }
  246. }
  247. # Only the loadable_module template in BUILDCONFIG.gn should reference this.
  248. group("loadable_module_deps") {
  249. public_deps = [ ":common_deps" ]
  250. }
  251. # Only the shared_library template in BUILDCONFIG.gn should reference this.
  252. group("shared_library_deps") {
  253. public_deps = [ ":common_deps" ]
  254. }
  255. # Executable configs -----------------------------------------------------------
  256. # Windows linker setup for EXEs and DLLs.
  257. if (is_win) {
  258. _windows_linker_configs = [
  259. "//build/config/win:sdk_link",
  260. "//build/config/win:common_linker_setup",
  261. ]
  262. }
  263. # This config defines the configs applied to all executables.
  264. config("executable_config") {
  265. configs = []
  266. if (is_win) {
  267. configs += _windows_linker_configs
  268. } else if (is_mac) {
  269. configs += [ "//build/config/mac:mac_dynamic_flags" ]
  270. } else if (is_ios) {
  271. configs += [
  272. "//build/config/ios:ios_dynamic_flags",
  273. "//build/config/ios:ios_executable_flags",
  274. ]
  275. } else if (is_linux || is_chromeos || is_android || current_os == "aix") {
  276. configs += [ "//build/config/gcc:executable_config" ]
  277. if (is_castos || is_cast_android) {
  278. configs += [ "//build/config/chromecast:executable_config" ]
  279. }
  280. }
  281. # If we're using the prebuilt instrumented libraries with the sanitizers, we
  282. # need to add ldflags to every binary to make sure they are picked up.
  283. if (prebuilt_instrumented_libraries_available) {
  284. configs += [ "//third_party/instrumented_libraries:prebuilt_ldflags" ]
  285. }
  286. if (use_locally_built_instrumented_libraries) {
  287. configs += [ "//third_party/instrumented_libraries:locally_built_ldflags" ]
  288. }
  289. configs += [ "//build/config/sanitizers:link_executable" ]
  290. }
  291. # Shared library configs -------------------------------------------------------
  292. # This config defines the configs applied to all shared libraries.
  293. config("shared_library_config") {
  294. configs = []
  295. if (is_win) {
  296. configs += _windows_linker_configs
  297. } else if (is_mac) {
  298. configs += [ "//build/config/mac:mac_dynamic_flags" ]
  299. } else if (is_ios) {
  300. configs += [
  301. "//build/config/ios:ios_dynamic_flags",
  302. "//build/config/ios:ios_shared_library_flags",
  303. ]
  304. } else if (is_castos || is_cast_android) {
  305. configs += [ "//build/config/chromecast:shared_library_config" ]
  306. } else if (is_linux || is_chromeos || current_os == "aix") {
  307. configs += [ "//build/config/gcc:shared_library_config" ]
  308. }
  309. # If we're using the prebuilt instrumented libraries with the sanitizers, we
  310. # need to add ldflags to every binary to make sure they are picked up.
  311. if (prebuilt_instrumented_libraries_available) {
  312. configs += [ "//third_party/instrumented_libraries:prebuilt_ldflags" ]
  313. }
  314. if (use_locally_built_instrumented_libraries) {
  315. configs += [ "//third_party/instrumented_libraries:locally_built_ldflags" ]
  316. }
  317. configs += [ "//build/config/sanitizers:link_shared_library" ]
  318. }
  319. # Add this config to your target to enable precompiled headers.
  320. #
  321. # Precompiled headers are done on a per-target basis. If you have just a couple
  322. # of files, the time it takes to precompile (~2 seconds) can actually be longer
  323. # than the time saved. On a Z620, a 100 file target compiles about 2 seconds
  324. # faster with precompiled headers, with greater savings for larger targets.
  325. #
  326. # Recommend precompiled headers for targets with more than 50 .cc files.
  327. config("precompiled_headers") {
  328. if (enable_precompiled_headers) {
  329. if (is_win) {
  330. # This is a string rather than a file GN knows about. It has to match
  331. # exactly what's in the /FI flag below, and what might appear in the
  332. # source code in quotes for an #include directive.
  333. precompiled_header = "build/precompile.h"
  334. # This is a file that GN will compile with the above header. It will be
  335. # implicitly added to the sources (potentially multiple times, with one
  336. # variant for each language used in the target).
  337. precompiled_source = "//build/precompile.cc"
  338. # Force include the header.
  339. cflags = [ "/FI$precompiled_header" ]
  340. } else if (is_mac || is_linux) {
  341. precompiled_source = "//build/precompile.h"
  342. }
  343. }
  344. }