From 9e55ab1d39bf987d7df87a027c4331e9be309d09 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 28 Mar 2022 10:02:40 +0200 Subject: Add ability to customize pkg-config header and library search paths Specifically, {cc,c,cxx}.pkgconfig.{include,lib} variables specify header (-I) and library (-L) search paths to use in the generated .pc files instead of the default install.{include,lib}. Relative paths are resolved as install paths. --- libbuild2/cc/pkgconfig.cxx | 47 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) (limited to 'libbuild2/cc/pkgconfig.cxx') diff --git a/libbuild2/cc/pkgconfig.cxx b/libbuild2/cc/pkgconfig.cxx index 29d9155..d4ceb88 100644 --- a/libbuild2/cc/pkgconfig.cxx +++ b/libbuild2/cc/pkgconfig.cxx @@ -1507,20 +1507,46 @@ namespace build2 // install without actual install and remove the file if it exists. // // @@ Shouldn't we use target's install value rather than install.lib - // in case it gets installed into a custom location? + // in case it gets installed into a custom location? I suppose one + // can now use cc.pkgconfig.lib to customize this. // using install::resolve_dir; - dir_path ldir (resolve_dir (g, - cast (g["install.lib"]), - false /* fail_unknown */)); - if (ldir.empty ()) + small_vector ldirs; + + if (const dir_paths* ds = cast_null (g[c_pkgconfig_lib])) + { + for (const dir_path& d: *ds) + { + bool f (ldirs.empty ()); + + ldirs.push_back (resolve_dir (g, d, !f /* fail_unknown */)); + + if (f && ldirs.back ().empty ()) + break; + } + } + else + ldirs.push_back (resolve_dir (g, + cast (g["install.lib"]), + false /* fail_unknown */)); + + if (!ldirs.empty () && ldirs.front ().empty ()) { rmfile (ctx, p, 3 /* verbosity */); return; } - dir_path idir (resolve_dir (g, cast (g["install.include"]))); + small_vector idirs; + + if (const dir_paths* ds = cast_null (g[c_pkgconfig_include])) + { + for (const dir_path& d: *ds) + idirs.push_back (resolve_dir (g, d)); + } + else + idirs.push_back (resolve_dir (g, + cast (g["install.include"]))); // Note that generation can take some time if we have a large number of // prerequisite libraries. @@ -1666,13 +1692,11 @@ namespace build2 return n; }; - // @@ TODO: support whole archive? - // - // Cflags. // os << "Cflags:"; - os << " -I" << escape (idir.string ()); + for (const dir_path& d: idirs) + os << " -I" << escape (d.string ()); save_poptions (x_export_poptions); save_poptions (c_export_poptions); os << endl; @@ -1691,7 +1715,8 @@ namespace build2 // While we don't need it for a binless library itselt, it may be // necessary to resolve its binful dependencies. // - os << " -L" << escape (ldir.string ()); + for (const dir_path& d: ldirs) + os << " -L" << escape (d.string ()); // Now process ourselves as if we were being linked to something (so // pretty similar to link_rule::append_libraries()). We also reuse -- cgit v1.1