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 5import("//build/config/sysroot.gni") 6 7# Defines a config specifying the result of running pkg-config for the given 8# packages. Put the package names you want to query in the "packages" variable 9# inside the template invocation. 10# 11# You can also add defines via the "defines" variable. This can be useful to 12# add this to the config to pass defines that the library expects to get by 13# users of its headers. 14# 15# Example: 16# pkg_config("mything") { 17# packages = [ "mything1", "mything2" ] 18# defines = [ "ENABLE_AWESOME" ] 19# } 20# 21# You can also use "extra args" to filter out results (see pkg-config.py): 22# extra_args = [ "-v, "foo" ] 23# To ignore libs and ldflags (only cflags/defines will be set, which is useful 24# when doing manual dynamic linking), set: 25# ignore_libs = true 26 27declare_args() { 28 # A pkg-config wrapper to call instead of trying to find and call the right 29 # pkg-config directly. Wrappers like this are common in cross-compilation 30 # environments. 31 # Leaving it blank defaults to searching PATH for 'pkg-config' and relying on 32 # the sysroot mechanism to find the right .pc files. 33 pkg_config = "" 34 35 # A optional pkg-config wrapper to use for tools built on the host. 36 host_pkg_config = "" 37 38 # cross systemroots place pkgconfig files at <systemroot>/usr/share/pkgconfig 39 # and one of <systemroot>/usr/lib/pkgconfig or <systemroot>/usr/lib64/pkgconfig 40 # depending on whether the systemroot is for a 32 or 64 bit architecture. 41 # 42 # When build under GYP, cross board builds specify the 'system_libdir' variable 43 # as part of the GYP_DEFINES provided by the cross emerge build or simple 44 # chrome build scheme. This variable permits controlling this for GN builds 45 # in similar fashion by setting the `system_libdir` variable in the build's 46 # args.gn file to 'lib' or 'lib64' as appropriate for the target architecture. 47 system_libdir = "lib" 48} 49 50pkg_config_script = "//build/config/linux/pkg-config.py" 51 52# Define the args we pass to the pkg-config script for other build files that 53# need to invoke it manually. 54pkg_config_args = [] 55 56if (sysroot != "") { 57 # Pass the sysroot if we're using one (it requires the CPU arch also). 58 pkg_config_args += [ 59 "-s", 60 rebase_path(sysroot), 61 "-a", 62 current_cpu, 63 ] 64} 65 66if (pkg_config != "") { 67 pkg_config_args += [ 68 "-p", 69 pkg_config, 70 ] 71} 72 73# Only use the custom libdir when building with the target sysroot. 74if (target_sysroot != "" && sysroot == target_sysroot) { 75 pkg_config_args += [ 76 "--system_libdir", 77 system_libdir, 78 ] 79} 80 81if (host_pkg_config != "") { 82 host_pkg_config_args = [ 83 "-p", 84 host_pkg_config, 85 ] 86} else { 87 host_pkg_config_args = pkg_config_args 88} 89 90template("pkg_config") { 91 assert(defined(invoker.packages), 92 "Variable |packages| must be defined to be a list in pkg_config.") 93 config(target_name) { 94 if (host_toolchain == current_toolchain) { 95 args = host_pkg_config_args + invoker.packages 96 } else { 97 args = pkg_config_args + invoker.packages 98 } 99 if (defined(invoker.extra_args)) { 100 args += invoker.extra_args 101 } 102 103 pkgresult = exec_script(pkg_config_script, args, "value") 104 cflags = pkgresult[1] 105 106 foreach(include, pkgresult[0]) { 107 if (use_sysroot) { 108 # We want the system include paths to use -isystem instead of -I to 109 # suppress warnings in those headers. 110 include_relativized = rebase_path(include, root_build_dir) 111 cflags += [ "-isystem$include_relativized" ] 112 } else { 113 cflags += [ "-I$include" ] 114 } 115 } 116 117 if (!defined(invoker.ignore_libs) || !invoker.ignore_libs) { 118 libs = pkgresult[2] 119 lib_dirs = pkgresult[3] 120 } 121 122 forward_variables_from(invoker, 123 [ 124 "defines", 125 "visibility", 126 ]) 127 } 128} 129