Source code

Revision control

Copy as Markdown

Other Tools

# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//chromium/build/config/c++/c++.gni")
import("//chromium/build/config/compiler/compiler.gni")
import("//chromium/build/config/sanitizers/sanitizers.gni")
import("//chromium/build/config/sysroot.gni")
import("//chromium/build/toolchain/toolchain.gni")
declare_args() {
# When non empty, overrides the target rpath value. This allows a user to
# make a Chromium build where binaries and shared libraries are meant to be
# installed into separate directories, like /usr/bin/chromium and
# /usr/lib/chromium for instance. It is useful when a build system that
# generates a whole target root filesystem (like Yocto) is used on top of gn,
# especially when cross-compiling.
# Note: this gn arg is similar to gyp target_rpath generator flag.
gcc_target_rpath = ""
ldso_path = ""
}
# This config causes functions not to be automatically exported from shared
# libraries. By default, all symbols are exported but this means there are
# lots of exports that slow everything down. In general we explicitly mark
# which functions we want to export from components.
#
# Some third_party code assumes all functions are exported so this is separated
# into its own config so such libraries can remove this config to make symbols
# public again.
#
config("symbol_visibility_hidden") {
cflags = [ "-fvisibility=hidden" ]
# Visibility attribute is not supported on AIX.
if (current_os != "aix") {
cflags_cc = [ "-fvisibility-inlines-hidden" ]
cflags_objcc = cflags_cc
}
}
# This config is usually set when :symbol_visibility_hidden is removed.
# It's often a good idea to set visibility explicitly, as there're flags
# which would error out otherwise (e.g. -fsanitize=cfi-unrelated-cast)
config("symbol_visibility_default") {
cflags = [ "-fvisibility=default" ]
}
# The rpath is the dynamic library search path. Setting this config on a link
# step will put the directory where the build generates shared libraries into
# the rpath.
#
# This is required for component builds since the build generates many shared
# libraries in the build directory that we expect to be automatically loaded.
# It will be automatically applied in this case by :executable_config.
#
# In non-component builds, certain test binaries may expect to load dynamic
# libraries from the current directory. As long as these aren't distributed,
# this is OK. For these cases use something like this:
#
# if ((is_linux || is_chromeos) && !is_component_build) {
# configs += [ "//chromium/build/config/gcc:rpath_for_built_shared_libraries" ]
# }
config("rpath_for_built_shared_libraries") {
if (!is_android && current_os != "aix") {
# Note: Android, Aix don't support rpath.
if (current_toolchain != default_toolchain || gcc_target_rpath == "") {
ldflags = [
# Want to pass "\$". GN will re-escape as required for ninja.
"-Wl,-rpath=\$ORIGIN",
]
} else {
ldflags = [ "-Wl,-rpath=${gcc_target_rpath}" ]
}
if (current_toolchain == default_toolchain && ldso_path != "") {
ldflags += [ "-Wl,--dynamic-linker=${ldso_path}" ]
}
}
}
if (is_component_build && !is_android) {
# See the rpath_for... config above for why this is necessary for component
# builds.
executable_and_shared_library_configs_ =
[ ":rpath_for_built_shared_libraries" ]
} else {
executable_and_shared_library_configs_ = []
}
# Settings for executables.
config("executable_config") {
configs = executable_and_shared_library_configs_
ldflags = [ "-pie" ]
if (is_android) {
ldflags += [
"-Bdynamic",
"-Wl,-z,nocopyreloc",
]
}
if (!is_android && current_os != "aix") {
ldflags += [
# TODO(GYP): Do we need a check on the binutils version here?
#
# Newer binutils don't set DT_RPATH unless you disable "new" dtags
# and the new DT_RUNPATH doesn't work without --no-as-needed flag.
"-Wl,--disable-new-dtags",
]
}
}
# Settings for shared libraries.
config("shared_library_config") {
configs = executable_and_shared_library_configs_
}