aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/build.py2
-rw-r--r--mesonbuild/compilers.py13
-rw-r--r--mesonbuild/interpreter.py2
-rwxr-xr-xrun_unittests.py20
4 files changed, 29 insertions, 8 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 3d41cda..6170f84 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -823,6 +823,8 @@ class Executable(BuildTarget):
class StaticLibrary(BuildTarget):
def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs):
+ if 'pic' not in kwargs and 'b_staticpic' in environment.coredata.base_options:
+ kwargs['pic'] = environment.coredata.base_options['b_staticpic'].value
super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs)
if 'cs' in self.compilers:
raise InvalidArguments('Static libraries not supported for C#.')
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index 3cf761a..bb733a7 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -190,7 +190,10 @@ base_options = {
'always'),
'b_ndebug' : coredata.UserBooleanOption('b_ndebug',
'Disable asserts',
- False)
+ False),
+ 'b_staticpic' : coredata.UserBooleanOption('b_staticpic',
+ 'Build static libraries as position independent',
+ True),
}
def sanitizer_compile_args(value):
@@ -1521,7 +1524,7 @@ class GnuDCompiler(DCompiler):
self.warn_args = {'1': ['-Wall', '-Wdeprecated'],
'2': ['-Wall', '-Wextra', '-Wdeprecated'],
'3': ['-Wall', '-Wextra', '-Wdeprecated', '-Wpedantic']}
- self.base_options = ['b_colorout', 'b_sanitize']
+ self.base_options = ['b_colorout', 'b_sanitize', 'b_staticpic']
def get_colorout_args(self, colortype):
if mesonlib.version_compare(self.version, '>=4.9.0'):
@@ -1909,7 +1912,7 @@ class GnuCompiler:
self.gcc_type = gcc_type
self.defines = defines or {}
self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage',
- 'b_colorout', 'b_ndebug']
+ 'b_colorout', 'b_ndebug', 'b_staticpic']
if self.gcc_type != GCC_OSX:
self.base_options.append('b_lundef')
self.base_options.append('b_asneeded')
@@ -2055,7 +2058,7 @@ class ClangCompiler():
self.id = 'clang'
self.clang_type = clang_type
self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage',
- 'b_ndebug']
+ 'b_ndebug', 'b_staticpic']
if self.clang_type != CLANG_OSX:
self.base_options.append('b_lundef')
self.base_options.append('b_asneeded')
@@ -2285,7 +2288,7 @@ class GnuFortranCompiler(FortranCompiler):
def get_define(self, define):
if define in self.defines:
- return defines[define]
+ return self.defines[define]
def get_always_args(self):
return ['-pipe']
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index be19bab..92b997a 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1117,7 +1117,7 @@ class Interpreter():
if not os.path.isfile(mesonfile):
raise InvalidArguments('Missing Meson file in %s' % mesonfile)
with open(mesonfile, encoding='utf8') as mf:
- code = mf.read()
+ code = mf.read()
if len(code.strip()) == 0:
raise InvalidCode('Builder file is empty.')
assert(isinstance(code, str))
diff --git a/run_unittests.py b/run_unittests.py
index 644a31a..5cd7d0f 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -15,7 +15,7 @@
import unittest, os, sys, shutil
import subprocess
-import re
+import re, json
import tempfile
from mesonbuild.environment import detect_ninja
@@ -29,12 +29,12 @@ def get_soname(fname):
return m.group(1)
class LinuxlikeTests(unittest.TestCase):
-
def setUp(self):
super().setUp()
src_root = os.path.dirname(__file__)
self.builddir = tempfile.mkdtemp()
self.meson_command = [sys.executable, os.path.join(src_root, 'meson.py')]
+ self.mconf_command = [sys.executable, os.path.join(src_root, 'mesonconf.py')]
self.ninja_command = [detect_ninja(), '-C', self.builddir]
self.common_test_dir = os.path.join(src_root, 'test cases/common')
self.output = b''
@@ -49,6 +49,13 @@ class LinuxlikeTests(unittest.TestCase):
def build(self):
self.output += subprocess.check_output(self.ninja_command)
+ def setconf(self, arg):
+ self.output += subprocess.check_output(self.mconf_command + [arg, self.builddir])
+
+ def get_compdb(self):
+ with open(os.path.join(self.builddir, 'compile_commands.json')) as ifile:
+ return json.load(ifile)
+
def test_basic_soname(self):
testdir = os.path.join(self.common_test_dir, '4 shared')
self.init(testdir)
@@ -65,5 +72,14 @@ class LinuxlikeTests(unittest.TestCase):
soname = get_soname(lib1)
self.assertEqual(soname, b'prefixsomelib.suffix')
+ def test_pic(self):
+ testdir = os.path.join(self.common_test_dir, '3 static')
+ self.init(testdir)
+ compdb = self.get_compdb()
+ self.assertTrue('-fPIC' in compdb[0]['command'])
+ self.setconf('-Db_staticpic=true')
+ self.build()
+ self.assertFalse('-fPIC' not in compdb[0]['command'])
+
if __name__ == '__main__':
unittest.main()