• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2023 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import("perfetto.gni")
16
17declare_args() {
18  # These are provided by chromium's build/config/linux/pkg_config.gni, but
19  # need to be defined if they have not been already.
20  if (perfetto_use_pkgconfig) {
21    if (!defined(pkg_config)) {
22      pkg_config = "pkg-config"
23    }
24    if (!defined(host_pkg_config)) {
25      host_pkg_config = "pkg-config"
26    }
27  }
28}
29
30# Defines a config specifying the result of running pkg-config for the given
31# packages. Put the package names you want to query in the "pkg_deps" variable
32# inside the template invocation.
33template("pkg_config") {
34  config(target_name) {
35    assert(defined(invoker.pkg_deps), "pkg_deps must be set")
36    if (perfetto_use_pkgconfig) {
37      forward_variables_from(invoker, "*")
38
39      if (current_toolchain == host_toolchain) {
40        _cmd = host_pkg_config
41      } else {
42        _cmd = pkg_config
43      }
44      _pkg_config_result =
45          exec_script("//gn/pkg-config_wrapper.py", [ _cmd ] + pkg_deps, "json")
46
47      if (_pkg_config_result.cflags != []) {
48        if (!defined(cflags)) {
49          cflags = []
50        }
51        cflags += _pkg_config_result.cflags
52      }
53      if (_pkg_config_result.libs != []) {
54        if (!defined(libs)) {
55          libs = []
56        }
57        libs += _pkg_config_result.libs
58      }
59      if (_pkg_config_result.lib_dirs != []) {
60        if (!defined(lib_dirs)) {
61          lib_dirs = []
62        }
63        lib_dirs += _pkg_config_result.lib_dirs
64      }
65      if (_pkg_config_result.ldflags != []) {
66        if (!defined(ldflags)) {
67          ldflags = []
68        }
69        ldflags += _pkg_config_result.ldflags
70      }
71    } else {  # !perfetto_use_pkgconfig
72      not_needed(invoker, "*")
73    }
74  }
75}
76