15f9996aaSopenharmony_ci# Copyright (c) 2013 The Chromium Authors. All rights reserved. 25f9996aaSopenharmony_ci# Use of this source code is governed by a BSD-style license that can be 35f9996aaSopenharmony_ci# found in the LICENSE file. 45f9996aaSopenharmony_ci 55f9996aaSopenharmony_ciimport("//build/config/sysroot.gni") 65f9996aaSopenharmony_ci 75f9996aaSopenharmony_ci# Defines a config specifying the result of running pkg-config for the given 85f9996aaSopenharmony_ci# packages. Put the package names you want to query in the "packages" variable 95f9996aaSopenharmony_ci# inside the template invocation. 105f9996aaSopenharmony_ci# 115f9996aaSopenharmony_ci# You can also add defines via the "defines" variable. This can be useful to 125f9996aaSopenharmony_ci# add this to the config to pass defines that the library expects to get by 135f9996aaSopenharmony_ci# users of its headers. 145f9996aaSopenharmony_ci# 155f9996aaSopenharmony_ci# Example: 165f9996aaSopenharmony_ci# pkg_config("mything") { 175f9996aaSopenharmony_ci# packages = [ "mything1", "mything2" ] 185f9996aaSopenharmony_ci# defines = [ "ENABLE_AWESOME" ] 195f9996aaSopenharmony_ci# } 205f9996aaSopenharmony_ci# 215f9996aaSopenharmony_ci# You can also use "extra args" to filter out results (see pkg-config.py): 225f9996aaSopenharmony_ci# extra_args = [ "-v, "foo" ] 235f9996aaSopenharmony_ci# To ignore libs and ldflags (only cflags/defines will be set, which is useful 245f9996aaSopenharmony_ci# when doing manual dynamic linking), set: 255f9996aaSopenharmony_ci# ignore_libs = true 265f9996aaSopenharmony_ci 275f9996aaSopenharmony_cideclare_args() { 285f9996aaSopenharmony_ci # A pkg-config wrapper to call instead of trying to find and call the right 295f9996aaSopenharmony_ci # pkg-config directly. Wrappers like this are common in cross-compilation 305f9996aaSopenharmony_ci # environments. 315f9996aaSopenharmony_ci # Leaving it blank defaults to searching PATH for 'pkg-config' and relying on 325f9996aaSopenharmony_ci # the sysroot mechanism to find the right .pc files. 335f9996aaSopenharmony_ci pkg_config = "" 345f9996aaSopenharmony_ci 355f9996aaSopenharmony_ci # A optional pkg-config wrapper to use for tools built on the host. 365f9996aaSopenharmony_ci host_pkg_config = "" 375f9996aaSopenharmony_ci 385f9996aaSopenharmony_ci # cross systemroots place pkgconfig files at <systemroot>/usr/share/pkgconfig 395f9996aaSopenharmony_ci # and one of <systemroot>/usr/lib/pkgconfig or <systemroot>/usr/lib64/pkgconfig 405f9996aaSopenharmony_ci # depending on whether the systemroot is for a 32 or 64 bit architecture. 415f9996aaSopenharmony_ci # 425f9996aaSopenharmony_ci # When build under GYP, cross board builds specify the 'system_libdir' variable 435f9996aaSopenharmony_ci # as part of the GYP_DEFINES provided by the cross emerge build or simple 445f9996aaSopenharmony_ci # chrome build scheme. This variable permits controlling this for GN builds 455f9996aaSopenharmony_ci # in similar fashion by setting the `system_libdir` variable in the build's 465f9996aaSopenharmony_ci # args.gn file to 'lib' or 'lib64' as appropriate for the target architecture. 475f9996aaSopenharmony_ci system_libdir = "lib" 485f9996aaSopenharmony_ci} 495f9996aaSopenharmony_ci 505f9996aaSopenharmony_cipkg_config_script = "//build/config/linux/pkg-config.py" 515f9996aaSopenharmony_ci 525f9996aaSopenharmony_ci# Define the args we pass to the pkg-config script for other build files that 535f9996aaSopenharmony_ci# need to invoke it manually. 545f9996aaSopenharmony_cipkg_config_args = [] 555f9996aaSopenharmony_ci 565f9996aaSopenharmony_ciif (sysroot != "") { 575f9996aaSopenharmony_ci # Pass the sysroot if we're using one (it requires the CPU arch also). 585f9996aaSopenharmony_ci pkg_config_args += [ 595f9996aaSopenharmony_ci "-s", 605f9996aaSopenharmony_ci rebase_path(sysroot), 615f9996aaSopenharmony_ci "-a", 625f9996aaSopenharmony_ci current_cpu, 635f9996aaSopenharmony_ci ] 645f9996aaSopenharmony_ci} 655f9996aaSopenharmony_ci 665f9996aaSopenharmony_ciif (pkg_config != "") { 675f9996aaSopenharmony_ci pkg_config_args += [ 685f9996aaSopenharmony_ci "-p", 695f9996aaSopenharmony_ci pkg_config, 705f9996aaSopenharmony_ci ] 715f9996aaSopenharmony_ci} 725f9996aaSopenharmony_ci 735f9996aaSopenharmony_ci# Only use the custom libdir when building with the target sysroot. 745f9996aaSopenharmony_ciif (target_sysroot != "" && sysroot == target_sysroot) { 755f9996aaSopenharmony_ci pkg_config_args += [ 765f9996aaSopenharmony_ci "--system_libdir", 775f9996aaSopenharmony_ci system_libdir, 785f9996aaSopenharmony_ci ] 795f9996aaSopenharmony_ci} 805f9996aaSopenharmony_ci 815f9996aaSopenharmony_ciif (host_pkg_config != "") { 825f9996aaSopenharmony_ci host_pkg_config_args = [ 835f9996aaSopenharmony_ci "-p", 845f9996aaSopenharmony_ci host_pkg_config, 855f9996aaSopenharmony_ci ] 865f9996aaSopenharmony_ci} else { 875f9996aaSopenharmony_ci host_pkg_config_args = pkg_config_args 885f9996aaSopenharmony_ci} 895f9996aaSopenharmony_ci 905f9996aaSopenharmony_citemplate("pkg_config") { 915f9996aaSopenharmony_ci assert(defined(invoker.packages), 925f9996aaSopenharmony_ci "Variable |packages| must be defined to be a list in pkg_config.") 935f9996aaSopenharmony_ci config(target_name) { 945f9996aaSopenharmony_ci if (host_toolchain == current_toolchain) { 955f9996aaSopenharmony_ci args = host_pkg_config_args + invoker.packages 965f9996aaSopenharmony_ci } else { 975f9996aaSopenharmony_ci args = pkg_config_args + invoker.packages 985f9996aaSopenharmony_ci } 995f9996aaSopenharmony_ci if (defined(invoker.extra_args)) { 1005f9996aaSopenharmony_ci args += invoker.extra_args 1015f9996aaSopenharmony_ci } 1025f9996aaSopenharmony_ci 1035f9996aaSopenharmony_ci pkgresult = exec_script(pkg_config_script, args, "value") 1045f9996aaSopenharmony_ci cflags = pkgresult[1] 1055f9996aaSopenharmony_ci 1065f9996aaSopenharmony_ci foreach(include, pkgresult[0]) { 1075f9996aaSopenharmony_ci if (use_sysroot) { 1085f9996aaSopenharmony_ci # We want the system include paths to use -isystem instead of -I to 1095f9996aaSopenharmony_ci # suppress warnings in those headers. 1105f9996aaSopenharmony_ci include_relativized = rebase_path(include, root_build_dir) 1115f9996aaSopenharmony_ci cflags += [ "-isystem$include_relativized" ] 1125f9996aaSopenharmony_ci } else { 1135f9996aaSopenharmony_ci cflags += [ "-I$include" ] 1145f9996aaSopenharmony_ci } 1155f9996aaSopenharmony_ci } 1165f9996aaSopenharmony_ci 1175f9996aaSopenharmony_ci if (!defined(invoker.ignore_libs) || !invoker.ignore_libs) { 1185f9996aaSopenharmony_ci libs = pkgresult[2] 1195f9996aaSopenharmony_ci lib_dirs = pkgresult[3] 1205f9996aaSopenharmony_ci } 1215f9996aaSopenharmony_ci 1225f9996aaSopenharmony_ci forward_variables_from(invoker, 1235f9996aaSopenharmony_ci [ 1245f9996aaSopenharmony_ci "defines", 1255f9996aaSopenharmony_ci "visibility", 1265f9996aaSopenharmony_ci ]) 1275f9996aaSopenharmony_ci } 1285f9996aaSopenharmony_ci} 129