BUILD.gn 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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/apple/symbols.gni")
  5. import("//build/config/c++/c++.gni")
  6. import("//build/config/mac/mac_sdk.gni")
  7. import("//build/config/sysroot.gni")
  8. import("//build/toolchain/goma.gni")
  9. import("//build/toolchain/rbe.gni")
  10. # This is included by reference in the //build/config/compiler config that
  11. # is applied to all targets. It is here to separate out the logic.
  12. config("compiler") {
  13. # These flags are shared between the C compiler and linker.
  14. common_mac_flags = []
  15. # CPU architecture.
  16. if (current_cpu == "x64") {
  17. clang_arch = "x86_64"
  18. } else if (current_cpu == "x86") {
  19. clang_arch = "i386"
  20. } else if (current_cpu == "arm64") {
  21. clang_arch = current_cpu
  22. } else {
  23. assert(false, "unknown current_cpu $current_cpu")
  24. }
  25. if (host_os == "mac") {
  26. common_mac_flags += [
  27. "-arch",
  28. clang_arch,
  29. ]
  30. } else {
  31. common_mac_flags += [ "--target=$clang_arch-apple-macos" ]
  32. }
  33. # This is here so that all files get recompiled after an Xcode update.
  34. # (defines are passed via the command line, and build system rebuild things
  35. # when their commandline changes). Nothing should ever read this define.
  36. defines = [ "CR_XCODE_VERSION=$xcode_version" ]
  37. asmflags = common_mac_flags
  38. cflags = common_mac_flags
  39. # Without this, the constructors and destructors of a C++ object inside
  40. # an Objective C struct won't be called, which is very bad.
  41. cflags_objcc = [ "-fobjc-call-cxx-cdtors" ]
  42. ldflags = common_mac_flags
  43. if (save_unstripped_output) {
  44. ldflags += [ "-Wcrl,unstripped," + rebase_path(root_out_dir) ]
  45. }
  46. if (export_libcxxabi_from_executables) {
  47. ldflags += [ "-Wl,-undefined,dynamic_lookup" ]
  48. }
  49. }
  50. # This is included by reference in the //build/config/compiler:runtime_library
  51. # config that is applied to all targets. It is here to separate out the logic
  52. # that is Mac-only. Please see that target for advice on what should go in
  53. # :runtime_library vs. :compiler.
  54. config("runtime_library") {
  55. common_flags = [
  56. "-isysroot",
  57. rebase_path(sysroot, root_build_dir),
  58. "-mmacos-version-min=$mac_deployment_target",
  59. ]
  60. asmflags = common_flags
  61. cflags = common_flags
  62. ldflags = common_flags
  63. # Prevent Mac OS X AssertMacros.h (included by system header) from defining
  64. # macros that collide with common names, like 'check', 'require', and
  65. # 'verify'.
  66. # http://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/AssertMacros.h
  67. defines = [ "__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0" ]
  68. }
  69. # On Mac, this is used for everything except static libraries.
  70. config("mac_dynamic_flags") {
  71. ldflags = [ "-Wl,-ObjC" ] # Always load Objective-C categories and classes.
  72. if (is_component_build) {
  73. ldflags += [
  74. # Path for loading shared libraries for unbundled binaries.
  75. "-Wl,-rpath,@loader_path/.",
  76. # Path for loading shared libraries for bundled binaries. Get back from
  77. # Binary.app/Contents/MacOS.
  78. "-Wl,-rpath,@loader_path/../../..",
  79. ]
  80. # Path for loading shared libraries for unbundled binaries for
  81. # the host toolchain (see https://crbug.com/1315433). Only used
  82. # for when building for iOS.
  83. if (target_os == "ios" && current_toolchain == host_toolchain) {
  84. ldflags += [
  85. "-Wl,-rpath,@loader_path/" +
  86. rebase_path(get_label_info(":mac_dynamic_flags", "root_out_dir"),
  87. root_build_dir),
  88. ]
  89. }
  90. }
  91. }
  92. # The ldflags referenced below are handled by
  93. # //build/toolchain/apple/linker_driver.py.
  94. # Remove this config if a target wishes to change the arguments passed to the
  95. # strip command during linking. This config by default strips all symbols
  96. # from a binary, but some targets may wish to specify an exports file to
  97. # preserve specific symbols.
  98. config("strip_all") {
  99. if (enable_stripping) {
  100. ldflags = [ "-Wcrl,strip,-x,-S" ]
  101. }
  102. }
  103. # When building with Goma, all inputs must be relative to the build directory.
  104. # If using the system Xcode, which typically resides outside the build root, a
  105. # symlink to the SDK is created in the build directory, and the path to that
  106. # link is stored in $mac_sdk_path. If an action references a file in the SDK as
  107. # an input, GN will complain that no target generates the file because it is
  108. # below the $root_build_dir. The below action lists as outputs the files in the
  109. # SDK that are referenced as inputs to actions, so that GN thinks a target has
  110. # generated them. The list is centralized here, as multiple targets need to
  111. # reference the same files, and an output can only be generated once.
  112. #
  113. # The symbolic link for $mac_sdk_path is set up by
  114. # //build/config/apple/sdk_info.py in //build/config/mac/mac_sdk.gni.
  115. if (use_system_xcode && (use_goma || use_remoteexec) && target_os == "mac" &&
  116. current_toolchain == default_toolchain) {
  117. action("sdk_inputs") {
  118. script = "//build/noop.py"
  119. outputs = [
  120. "$mac_sdk_path/usr/include/mach/exc.defs",
  121. "$mac_sdk_path/usr/include/mach/mach_exc.defs",
  122. "$mac_sdk_path/usr/include/mach/notify.defs",
  123. ]
  124. }
  125. } else {
  126. group("sdk_inputs") {
  127. if (current_toolchain != default_toolchain) {
  128. public_deps = [ ":sdk_inputs($default_toolchain)" ]
  129. }
  130. }
  131. }