|
1 | 1 | # Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
2 |
| -# Copyright (c) 2020 Project CHIP Authors |
| 2 | +# Copyright (c) 2020-2024 Project CHIP Authors |
3 | 3 | #
|
4 | 4 | # Redistribution and use in source and binary forms, with or without
|
5 | 5 | # modification, are permitted provided that the following conditions are
|
|
43 | 43 | #
|
44 | 44 | # You can also use "extra args" to filter out results (see pkg-config.py):
|
45 | 45 | # extra_args = [ "-v, "foo" ]
|
| 46 | +# |
46 | 47 | # To ignore libs and ldflags (only cflags/defines will be set, which is useful
|
47 | 48 | # when doing manual dynamic linking), set:
|
48 | 49 | # ignore_libs = true
|
| 50 | +# |
| 51 | +# To allow the build to proceed if (any of) the requested packages are absent, set: |
| 52 | +# optional = true |
| 53 | +# In this case the resulting config object will be empty. |
49 | 54 |
|
50 | 55 | import("//build_overrides/build.gni")
|
51 | 56 | import("${build_root}/config/sysroot.gni")
|
@@ -109,37 +114,42 @@ template("pkg_config") {
|
109 | 114 | } else {
|
110 | 115 | args = pkg_config_args + invoker.packages
|
111 | 116 | }
|
| 117 | + if (defined(invoker.optional) && invoker.optional) { |
| 118 | + args += [ "-o" ] |
| 119 | + } |
112 | 120 | if (defined(invoker.extra_args)) {
|
113 | 121 | args += invoker.extra_args
|
114 | 122 | }
|
115 | 123 |
|
| 124 | + # pkgresult = [present, includes, cflags, libs, lib_dirs] |
116 | 125 | pkgresult = exec_script(pkg_config_script, args, "value")
|
117 |
| - cflags = pkgresult[1] |
| 126 | + if (pkgresult[0]) { |
| 127 | + cflags = pkgresult[2] |
118 | 128 |
|
119 |
| - foreach(include, pkgresult[0]) { |
120 |
| - cflags += [ "-I$include" ] |
121 |
| - } |
| 129 | + foreach(include, pkgresult[1]) { |
| 130 | + cflags += [ "-I$include" ] |
| 131 | + } |
122 | 132 |
|
123 |
| - if (!defined(invoker.ignore_libs) || !invoker.ignore_libs) { |
124 |
| - libs = pkgresult[2] |
125 |
| - lib_dirs = pkgresult[3] |
126 |
| - } |
| 133 | + if (!defined(invoker.ignore_libs) || !invoker.ignore_libs) { |
| 134 | + libs = pkgresult[3] |
| 135 | + lib_dirs = pkgresult[4] |
| 136 | + } |
127 | 137 |
|
128 |
| - # Link libraries statically for OSS-Fuzz fuzzer build |
129 |
| - if (oss_fuzz) { |
130 |
| - libs = [] |
131 |
| - ldflags = [ "-Wl,-Bstatic" ] |
132 |
| - foreach(lib, pkgresult[2]) { |
133 |
| - ldflags += [ "-l$lib" ] |
| 138 | + # Link libraries statically for OSS-Fuzz fuzzer build |
| 139 | + if (oss_fuzz) { |
| 140 | + libs = [] |
| 141 | + ldflags = [ "-Wl,-Bstatic" ] |
| 142 | + foreach(lib, pkgresult[3]) { |
| 143 | + ldflags += [ "-l$lib" ] |
| 144 | + } |
| 145 | + ldflags += [ "-Wl,-Bdynamic" ] |
| 146 | + lib_dirs = pkgresult[4] |
134 | 147 | }
|
135 |
| - ldflags += [ "-Wl,-Bdynamic" ] |
136 |
| - lib_dirs = pkgresult[3] |
137 |
| - } |
138 | 148 |
|
139 |
| - forward_variables_from(invoker, |
140 |
| - [ |
141 |
| - "defines", |
142 |
| - "visibility", |
143 |
| - ]) |
| 149 | + forward_variables_from(invoker, [ "defines" ]) |
| 150 | + } |
144 | 151 | }
|
| 152 | + |
| 153 | + # Always forward visibility |
| 154 | + forward_variables_from(invoker, [ "visibility" ]) |
145 | 155 | }
|
0 commit comments