BUILD.gn 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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/c++/c++.gni")
  5. import("//build/config/compiler/compiler.gni")
  6. import("//build/config/sanitizers/sanitizers.gni")
  7. import("//build/config/sysroot.gni")
  8. import("//build/toolchain/toolchain.gni")
  9. declare_args() {
  10. # When non empty, overrides the target rpath value. This allows a user to
  11. # make a Chromium build where binaries and shared libraries are meant to be
  12. # installed into separate directories, like /usr/bin/chromium and
  13. # /usr/lib/chromium for instance. It is useful when a build system that
  14. # generates a whole target root filesystem (like Yocto) is used on top of gn,
  15. # especially when cross-compiling.
  16. # Note: this gn arg is similar to gyp target_rpath generator flag.
  17. gcc_target_rpath = ""
  18. ldso_path = ""
  19. }
  20. # This config causes functions not to be automatically exported from shared
  21. # libraries. By default, all symbols are exported but this means there are
  22. # lots of exports that slow everything down. In general we explicitly mark
  23. # which functions we want to export from components.
  24. #
  25. # Some third_party code assumes all functions are exported so this is separated
  26. # into its own config so such libraries can remove this config to make symbols
  27. # public again.
  28. #
  29. # See http://gcc.gnu.org/wiki/Visibility
  30. config("symbol_visibility_hidden") {
  31. cflags = [ "-fvisibility=hidden" ]
  32. # Visibility attribute is not supported on AIX.
  33. if (current_os != "aix") {
  34. cflags_cc = [ "-fvisibility-inlines-hidden" ]
  35. cflags_objcc = cflags_cc
  36. }
  37. }
  38. # This config is usually set when :symbol_visibility_hidden is removed.
  39. # It's often a good idea to set visibility explicitly, as there're flags
  40. # which would error out otherwise (e.g. -fsanitize=cfi-unrelated-cast)
  41. config("symbol_visibility_default") {
  42. cflags = [ "-fvisibility=default" ]
  43. }
  44. # The rpath is the dynamic library search path. Setting this config on a link
  45. # step will put the directory where the build generates shared libraries into
  46. # the rpath.
  47. #
  48. # This is required for component builds since the build generates many shared
  49. # libraries in the build directory that we expect to be automatically loaded.
  50. # It will be automatically applied in this case by :executable_config.
  51. #
  52. # In non-component builds, certain test binaries may expect to load dynamic
  53. # libraries from the current directory. As long as these aren't distributed,
  54. # this is OK. For these cases use something like this:
  55. #
  56. # if ((is_linux || is_chromeos) && !is_component_build) {
  57. # configs += [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
  58. # }
  59. config("rpath_for_built_shared_libraries") {
  60. if (!is_android && current_os != "aix" && !is_castos) {
  61. # Note: Android, Aix don't support rpath. Chromecast has its own logic for
  62. # setting the rpath in //build/config/chromecast.
  63. if (current_toolchain != default_toolchain || gcc_target_rpath == "") {
  64. ldflags = [
  65. # Want to pass "\$". GN will re-escape as required for ninja.
  66. "-Wl,-rpath=\$ORIGIN",
  67. ]
  68. } else {
  69. ldflags = [ "-Wl,-rpath=${gcc_target_rpath}" ]
  70. }
  71. if (current_toolchain == default_toolchain && ldso_path != "") {
  72. ldflags += [ "-Wl,--dynamic-linker=${ldso_path}" ]
  73. }
  74. }
  75. }
  76. if (is_component_build && !is_android) {
  77. # See the rpath_for... config above for why this is necessary for component
  78. # builds.
  79. executable_and_shared_library_configs_ =
  80. [ ":rpath_for_built_shared_libraries" ]
  81. } else {
  82. executable_and_shared_library_configs_ = []
  83. }
  84. # Settings for executables.
  85. config("executable_config") {
  86. configs = executable_and_shared_library_configs_
  87. ldflags = [ "-pie" ]
  88. if (is_android) {
  89. ldflags += [
  90. "-Bdynamic",
  91. "-Wl,-z,nocopyreloc",
  92. ]
  93. }
  94. if (!is_android && current_os != "aix") {
  95. ldflags += [
  96. # TODO(GYP): Do we need a check on the binutils version here?
  97. #
  98. # Newer binutils don't set DT_RPATH unless you disable "new" dtags
  99. # and the new DT_RUNPATH doesn't work without --no-as-needed flag.
  100. "-Wl,--disable-new-dtags",
  101. ]
  102. }
  103. }
  104. # Settings for shared libraries.
  105. config("shared_library_config") {
  106. configs = executable_and_shared_library_configs_
  107. }