aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-01-31 13:03:41 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-01-31 13:03:41 +0200
commit50ae0c791cf94199c4cdc1674d8562b1c00046ea (patch)
tree9c0edfc7f1fe23a5d6b4fc504aceb5d43506126e
parenta71590646f37b2696f857dd71a68b34e2f57d15c (diff)
Use -l representation of library names in pkg-config files for MSVC
Passing it as foo.lib triggers some (brain-dead) fragmentation logic in libpkgconf. Also, a C library built with MSVC can be used in MinGW (and vice versa) and so this is also a step in supporting that.
-rw-r--r--libbuild2/cc/pkgconfig.cxx43
1 files changed, 38 insertions, 5 deletions
diff --git a/libbuild2/cc/pkgconfig.cxx b/libbuild2/cc/pkgconfig.cxx
index 769cb8b..9d372e2 100644
--- a/libbuild2/cc/pkgconfig.cxx
+++ b/libbuild2/cc/pkgconfig.cxx
@@ -931,9 +931,18 @@ namespace build2
ps->push_back (prerequisite (*lt));
}
else
+ {
// If we couldn't find the library, then leave it as -l.
//
all = false;
+
+ if (tsys == "win32-msvc")
+ {
+ // Translate -l<name> to <name>.lib.
+ //
+ l = move (name += ".lib");
+ }
+ }
}
// If all the -l's resolved and there were no other options, then drop
@@ -1309,9 +1318,9 @@ namespace build2
}
};
- // Given a library save its -l-style library name.
+ // Given a library target, save its -l-style library name.
//
- auto save_library = [&os, this] (const file& l)
+ auto save_library_target = [&os, this] (const file& l)
{
// If available (it may not, in case of import-installed libraris),
// use the .pc file name to derive the -l library name (in case of
@@ -1351,6 +1360,29 @@ namespace build2
os << " -l" << n;
};
+ // Given a (presumably) compiler-specific library name, save its
+ // -l-style library name.
+ //
+ auto save_library_name = [&os, this] (const string& n)
+ {
+ if (tsys == "win32-msvc")
+ {
+ // Translate <name>.lib to -l<name>.
+ //
+ size_t p (path::traits_type::find_extension (n));
+
+ if (p != string::npos && icasecmp (n.c_str () + p + 1, "lib") == 0)
+ {
+ os << " -l" << string (n, 0, p);
+ return;
+ }
+
+ // Fall through and save as is.
+ }
+
+ os << ' ' << n;
+ };
+
// @@ TODO: support whole archive?
//
@@ -1389,7 +1421,8 @@ namespace build2
bool priv (false);
auto imp = [&priv] (const file&, bool la) {return priv && la;};
- auto lib = [&os, &save_library] (const file* const* c,
+ auto lib = [&save_library_target,
+ &save_library_name] (const file* const* c,
const string& p,
lflags,
bool)
@@ -1399,10 +1432,10 @@ namespace build2
if (l != nullptr)
{
if (l->is_a<libs> () || l->is_a<liba> ()) // See through libux.
- save_library (*l);
+ save_library_target (*l);
}
else
- os << ' ' << p; // Something "system'y", pass as is.
+ save_library_name (p); // Something "system'y", save as is.
};
auto opt = [] (const file&,