diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-03-28 10:02:40 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2022-03-28 10:02:40 +0200 |
commit | 9e55ab1d39bf987d7df87a027c4331e9be309d09 (patch) | |
tree | d65e8c2900cae4077b4ca7b591be874c784d1382 /libbuild2/cc | |
parent | 7d50db8924b8ce4faf05cde737bce9114df58f0d (diff) |
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.
Diffstat (limited to 'libbuild2/cc')
-rw-r--r-- | libbuild2/cc/common.hxx | 3 | ||||
-rw-r--r-- | libbuild2/cc/init.cxx | 7 | ||||
-rw-r--r-- | libbuild2/cc/pkgconfig.cxx | 47 |
3 files changed, 46 insertions, 11 deletions
diff --git a/libbuild2/cc/common.hxx b/libbuild2/cc/common.hxx index 78442f8..81cebda 100644 --- a/libbuild2/cc/common.hxx +++ b/libbuild2/cc/common.hxx @@ -102,6 +102,9 @@ namespace build2 const variable& c_export_libs; const variable& c_export_impl_libs; + const variable& c_pkgconfig_include; + const variable& c_pkgconfig_lib; + const variable& x_stdlib; // x.stdlib const variable& c_runtime; // cc.runtime diff --git a/libbuild2/cc/init.cxx b/libbuild2/cc/init.cxx index affc4ab..5c15835 100644 --- a/libbuild2/cc/init.cxx +++ b/libbuild2/cc/init.cxx @@ -113,6 +113,13 @@ namespace build2 vp.insert<vector<name>> ("cc.export.libs"); vp.insert<vector<name>> ("cc.export.impl_libs"); + // 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. + // + vp.insert<dir_paths> ("cc.pkconfig.include"); + vp.insert<dir_paths> ("cc.pkconfig.lib"); + // Hint variables (not overridable). // vp.insert<string> ("config.cc.id", false); 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<dir_path> (g["install.lib"]), - false /* fail_unknown */)); - if (ldir.empty ()) + small_vector<dir_path, 1> ldirs; + + if (const dir_paths* ds = cast_null<dir_paths> (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<dir_path> (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<dir_path> (g["install.include"]))); + small_vector<dir_path, 1> idirs; + + if (const dir_paths* ds = cast_null<dir_paths> (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<dir_path> (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 |