aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-03-28 10:02:40 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-03-28 10:02:40 +0200
commit9e55ab1d39bf987d7df87a027c4331e9be309d09 (patch)
treed65e8c2900cae4077b4ca7b591be874c784d1382
parent7d50db8924b8ce4faf05cde737bce9114df58f0d (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.
-rw-r--r--doc/manual.cli33
-rw-r--r--libbuild2/c/init.cxx6
-rw-r--r--libbuild2/cc/common.hxx3
-rw-r--r--libbuild2/cc/init.cxx7
-rw-r--r--libbuild2/cc/pkgconfig.cxx47
-rw-r--r--libbuild2/cxx/init.cxx6
6 files changed, 85 insertions, 17 deletions
diff --git a/doc/manual.cli b/doc/manual.cli
index 910ca0a..36e36bd 100644
--- a/doc/manual.cli
+++ b/doc/manual.cli
@@ -2353,6 +2353,27 @@ the \c{details/} subdirectory with the \c{utility.hxx} header, then this
header would have been installed as
\c{.../include/libhello/details/utility.hxx}.
+\N|By default the generated \c{pkg-config} files will contain
+\c{install.include} and \c{install.lib} directories as header (\c{-I}) and
+library (\c{-L}) search paths, respectively. However, these can be customized
+with the \c{{c,cxx\}.pkgconfig.{include,lib\}} variables. For example,
+sometimes we may need to install headers into a subdirectory of the include
+directory but include them without this subdirectory:
+
+\
+# Install headers into hello/libhello/ subdirectory of, say,
+# /usr/include/ but include them as <libhello/*>.
+#
+hxx{*}:
+{
+ install = include/hello/libhello/
+ install.subdirs = true
+}
+
+lib{hello}: cxx.pkgconfig.include = include/hello/
+\
+
+|
\h2#intro-operations-dist|Distributing|
@@ -6508,12 +6529,12 @@ config.c
config.cxx
cc.id
- c.target
- c.target.cpu
- c.target.vendor
- c.target.system
- c.target.version
- c.target.class
+ cc.target
+ cc.target.cpu
+ cc.target.vendor
+ cc.target.system
+ cc.target.version
+ cc.target.class
config.cc.poptions
cc.poptions
diff --git a/libbuild2/c/init.cxx b/libbuild2/c/init.cxx
index be001a8..6725ca7 100644
--- a/libbuild2/c/init.cxx
+++ b/libbuild2/c/init.cxx
@@ -225,6 +225,9 @@ namespace build2
vp["cc.export.libs"],
vp["cc.export.impl_libs"],
+ vp["cc.pkconfig.include"],
+ vp["cc.pkconfig.lib"],
+
vp.insert_alias (vp["cc.stdlib"], "c.stdlib"), // Same as cc.stdlib.
vp["cc.runtime"],
@@ -276,6 +279,9 @@ namespace build2
vp.insert_alias (d.c_runtime, "c.runtime");
vp.insert_alias (d.c_importable, "c.importable");
+ vp.insert_alias (d.c_pkgconfig_include, "c.pkgconfig.include");
+ vp.insert_alias (d.c_pkgconfig_lib, "c.pkgconfig.lib");
+
auto& m (extra.set_module (new config_module (move (d))));
m.guess (rs, loc, extra.hints);
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
diff --git a/libbuild2/cxx/init.cxx b/libbuild2/cxx/init.cxx
index cd5169d..106668a 100644
--- a/libbuild2/cxx/init.cxx
+++ b/libbuild2/cxx/init.cxx
@@ -668,6 +668,9 @@ namespace build2
vp["cc.export.libs"],
vp["cc.export.impl_libs"],
+ vp["cc.pkconfig.include"],
+ vp["cc.pkconfig.lib"],
+
vp.insert<string> ("cxx.stdlib"),
vp["cc.runtime"],
@@ -733,6 +736,9 @@ namespace build2
vp.insert_alias (d.c_module_name, "cxx.module_name");
vp.insert_alias (d.c_importable, "cxx.importable");
+ vp.insert_alias (d.c_pkgconfig_include, "cxx.pkgconfig.include");
+ vp.insert_alias (d.c_pkgconfig_lib, "cxx.pkgconfig.lib");
+
auto& m (extra.set_module (new config_module (move (d))));
m.guess (rs, loc, extra.hints);