| # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| declare_args() { |
| # The OS build is running on. |
| OS = "" |
| |
| # Specifies pkg-config program to retrieve information about packages. |
| pkg_config = "" |
| |
| # The logical root directory for headers and libraries. |
| # Trailing slash should not be added (except root path). |
| sysroot = "" |
| |
| # The libdir of the target board. e.g. /usr/lib64 |
| libdir = "" |
| |
| # The path to the directory where build artifacts are located. |
| build_root = "" |
| |
| # The path to src/platform2. |
| platform2_root = "" |
| |
| # Libbase revision number read from BASE_VER variable or file. |
| libbase_ver = "" |
| |
| # Set true to allow C++ code to use exceptions. |
| enable_exceptions = false |
| |
| # Set true if clang is used for C compiler. |
| clang_cc = false |
| |
| # Set true if clang is used for C++ compiler. |
| clang_cxx = false |
| |
| # Additional flags for C compiler. |
| external_cflags = [] |
| |
| # Additional flags for C++ compiler. |
| external_cxxflags = [] |
| |
| # Additional flags for C and C++ preprocessor. |
| external_cppflags = [] |
| |
| # Additional flags for C and C++ linker. |
| external_ldflags = [] |
| } |
| import("//common-mk/use.gni") |
| |
| assert(pkg_config != "", "pkg-config script path must be set") |
| assert(libbase_ver != -1, "libbase_ver must be set") |
| assert(libdir != "", "libdir must be set") |
| |
| if (target_os == "") { |
| target_os = host_os |
| } |
| if (target_cpu == "") { |
| target_cpu = host_cpu |
| } |
| if (current_cpu == "") { |
| current_cpu = target_cpu |
| } |
| if (current_os == "") { |
| current_os = target_os |
| } |
| |
| # Practically sysroot is used as a prefix of paths, e.g. |
| # "${sysroot}/usr/include". If sysroot is root (= "/"), it will be |
| # "//usr/include". However, in GN, paths starting with "//" represents the path |
| # to the GN root, rather than the file system root, which is unexpected. |
| # To support that case, replace sysroot with "/.", if sysroot is "/". |
| if (sysroot == "/") { |
| sysroot = "/." |
| } |
| |
| # All binary targets will get this list of configs by default. |
| _binary_target_configs = [ "//common-mk:compiler_defaults" ] |
| |
| if (!enable_exceptions) { |
| _binary_target_configs += [ "//common-mk:no_exceptions" ] |
| } |
| |
| if (!clang_cc) { |
| _binary_target_configs += [ "//common-mk:gcc_cflags_c" ] |
| } |
| if (!clang_cxx) { |
| _binary_target_configs += [ "//common-mk:gcc_cflags_cc" ] |
| } |
| |
| set_defaults("executable") { |
| configs = _binary_target_configs |
| configs += [ "//common-mk:pie" ] |
| } |
| |
| set_defaults("static_library") { |
| configs = _binary_target_configs |
| configs += [ |
| "//common-mk:pie", |
| "//common-mk:use_thin_archive", |
| ] |
| } |
| |
| set_defaults("shared_library") { |
| configs = _binary_target_configs |
| configs += [ "//common-mk:pic" ] |
| } |
| |
| set_defaults("source_set") { |
| configs = _binary_target_configs |
| } |
| |
| set_default_toolchain("//common-mk/toolchain") |
| |
| # In Chrome OS, pkg-config is commonly and widely used. |
| # It is not natively supported by GN. Instead, here a few special fields are |
| # injected to the executable, shared_library and static_library targets |
| # to support pkg-config. |
| # |
| # Args: |
| # pkg_deps(optional): A list of package names to be depend. |
| # A corresponding config is created, and then injected to |configs|. |
| # public_pkg_deps(optional): Similart to pkg_deps, but injected to |
| # |public_configs| instead. |
| # all_dependent_pkg_deps(optional): Similar to pkg_deps, but injected to |
| # |all_dependent_pkg_deps|. |
| |
| import("//common-mk/pkg_config.gni") |
| |
| template("_generate_config_rule") { |
| if (defined(invoker.pkg_deps) && invoker.pkg_deps != []) { |
| _pkg_deps_name = "_${target_name}-pkg_deps-config" |
| pkg_config(_pkg_deps_name) { |
| pkg_deps = invoker.pkg_deps |
| } |
| } |
| if (defined(invoker.public_pkg_deps) && invoker.public_pkg_deps != []) { |
| _public_pkg_deps_name = "_${target_name}-public_pkg_deps-config" |
| pkg_config(_public_pkg_deps_name) { |
| pkg_deps = invoker.public_pkg_deps |
| } |
| } |
| if (defined(invoker.all_dependent_pkg_deps) && |
| invoker.all_dependent_pkg_deps != []) { |
| _all_dependent_pkg_deps_name = |
| "_${target_name}-all_dependent_pkg_deps-config" |
| pkg_config(_all_dependent_pkg_deps_name) { |
| pkg_deps = invoker.all_dependent_pkg_deps |
| } |
| } |
| |
| target(invoker.target_type, target_name) { |
| forward_variables_from(invoker, |
| "*", |
| [ |
| "all_dependent_pkg_deps", |
| "pkg_deps", |
| "public_pkg_deps", |
| "target_type", |
| ]) |
| if (defined(_pkg_deps_name)) { |
| if (!defined(configs)) { |
| configs = [] |
| } |
| configs += [ ":${_pkg_deps_name}" ] |
| } |
| if (defined(_public_pkg_deps_name)) { |
| if (!defined(public_configs)) { |
| public_configs = [] |
| } |
| public_configs += [ ":${_public_pkg_deps_name}" ] |
| } |
| if (defined(_all_dependent_pkg_deps_name)) { |
| if (!defined(all_dependent_configs)) { |
| all_dependent_configs = [] |
| } |
| all_dependent_configs += [ ":${_all_dependent_pkg_deps_name}" ] |
| } |
| } |
| } |
| |
| template("executable") { |
| _generate_config_rule(target_name) { |
| forward_variables_from(invoker, "*") |
| target_type = "executable" |
| } |
| } |
| |
| template("shared_library") { |
| _generate_config_rule(target_name) { |
| forward_variables_from(invoker, "*") |
| target_type = "shared_library" |
| } |
| } |
| |
| template("static_library") { |
| _generate_config_rule(target_name) { |
| forward_variables_from(invoker, "*") |
| target_type = "static_library" |
| } |
| } |