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