aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2017-07-20 18:00:15 +0530
committerJussi Pakkanen <jpakkane@gmail.com>2017-07-23 02:12:00 +0300
commitde2d59cc27777562e55091633331aa478a877afd (patch)
treea4a2a593e86076ddfcc213ee9fcfe14447a4e0b6
parentb3d048e93a55feaedadb1efae72de0b8871eefab (diff)
downloadmeson-de2d59cc27777562e55091633331aa478a877afd.zip
meson-de2d59cc27777562e55091633331aa478a877afd.tar.gz
meson-de2d59cc27777562e55091633331aa478a877afd.tar.bz2
find_library: Ignore libs on MSVC properly
In addition to filtering libs out while generating the command-line, we must also filter them out in find_library() otherwise these libs will be detected as "found" on Windows with MSVC. Closes https://github.com/mesonbuild/meson/issues/1509
-rw-r--r--mesonbuild/compilers/c.py11
-rw-r--r--mesonbuild/compilers/compilers.py4
-rwxr-xr-xrun_unittests.py17
3 files changed, 27 insertions, 5 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index d93c7cc..5de39d4 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -676,11 +676,11 @@ class CCompiler(Compiler):
raise RuntimeError('BUG: {!r} check failed unexpectedly'.format(n))
def find_library(self, libname, env, extra_dirs):
+ # These libraries are either built-in or invalid
+ if libname in self.ignore_libs:
+ return []
# First try if we can just add the library as -l.
- code = '''int main(int argc, char **argv) {
- return 0;
-}
- '''
+ code = 'int main(int argc, char **argv) { return 0; }'
if extra_dirs and isinstance(extra_dirs, str):
extra_dirs = [extra_dirs]
# Gcc + co seem to prefer builtin lib dirs to -L dirs.
@@ -811,6 +811,7 @@ class IntelCCompiler(IntelCompiler, CCompiler):
class VisualStudioCCompiler(CCompiler):
std_warn_args = ['/W3']
std_opt_args = ['/O2']
+ ignore_libs = ('m', 'c', 'pthread')
def __init__(self, exelist, version, is_cross, exe_wrap, is_64):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
@@ -941,7 +942,7 @@ class VisualStudioCCompiler(CCompiler):
# Translate GNU-style -lfoo library name to the import library
elif i.startswith('-l'):
name = i[2:]
- if name in ('m', 'c', 'pthread'):
+ if name in cls.ignore_libs:
# With MSVC, these are provided by the C runtime which is
# linked in by default
continue
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 77b3cb9..3c993ac 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -593,6 +593,10 @@ class CompilerArgs(list):
self.__iadd__(args)
class Compiler:
+ # Libraries to ignore in find_library() since they are provided by the
+ # compiler or the C library. Currently only used for MSVC.
+ ignore_libs = ()
+
def __init__(self, exelist, version):
if isinstance(exelist, str):
self.exelist = [exelist]
diff --git a/run_unittests.py b/run_unittests.py
index 875ba65..ff5a015 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -1431,6 +1431,23 @@ class WindowsTests(BasePlatformTests):
self.assertPathEqual(prog.get_command()[0], sys.executable)
self.assertPathBasenameEqual(prog.get_path(), 'test-script-ext.py')
+ def test_ignore_libs(self):
+ '''
+ Test that find_library on libs that are to be ignored returns an empty
+ array of arguments. Must be a unit test because we cannot inspect
+ ExternalLibraryHolder from build files.
+ '''
+ testdir = os.path.join(self.platform_test_dir, '1 basic')
+ env = Environment(testdir, self.builddir, self.meson_command,
+ get_fake_options(self.prefix), [])
+ cc = env.detect_c_compiler(False)
+ if cc.id != 'msvc':
+ raise unittest.SkipTest('Not using MSVC')
+ # To force people to update this test, and also test
+ self.assertEqual(set(cc.ignore_libs), {'c', 'm', 'pthread'})
+ for l in cc.ignore_libs:
+ self.assertEqual(cc.find_library(l, env, []), [])
+
class LinuxlikeTests(BasePlatformTests):
'''