From 50ae0c791cf94199c4cdc1674d8562b1c00046ea Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 31 Jan 2020 13:03:41 +0200 Subject: 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. --- libbuild2/cc/pkgconfig.cxx | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'libbuild2/cc/pkgconfig.cxx') 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 to .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 .lib to -l. + // + 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 () || l->is_a ()) // 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&, -- cgit v1.1