aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-10-06 11:08:29 -0700
committerDylan Baker <dylan@pnwbakers.com>2017-10-25 10:07:50 -0700
commit3aa97d4ab577948daaae4a702e248ab2ccfa3dda (patch)
tree2c07e3ae3a0eec1b1e07b531e53a133187a713a2
parent55844093468d09005350baf9bd21a5022cfc30b2 (diff)
downloadmeson-3aa97d4ab577948daaae4a702e248ab2ccfa3dda.zip
meson-3aa97d4ab577948daaae4a702e248ab2ccfa3dda.tar.gz
meson-3aa97d4ab577948daaae4a702e248ab2ccfa3dda.tar.bz2
llvm: fix static vs dynamic linking
LLVM >= 3.9 provides an llvm-config that has a sane mechanism for selecting static vs dynamic linking. LLVM < 3.9 (but >= 3.5) not so much. For those older LLVM versions, llvm-config will always provide arguments for statically linking LLVM, even if there is a library for dynamic linking. Fixes #2442
-rw-r--r--mesonbuild/dependencies/dev.py58
1 files changed, 52 insertions, 6 deletions
diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py
index b9e35e1..2ab2847 100644
--- a/mesonbuild/dependencies/dev.py
+++ b/mesonbuild/dependencies/dev.py
@@ -16,6 +16,7 @@
# development purposes, such as testing, debugging, etc..
import os
+import re
import shlex
import shutil
@@ -181,18 +182,63 @@ class LLVMDependency(ExternalDependency):
opt_modules = stringlistify(extract_as_list(kwargs, 'optional_modules'))
self.check_components(opt_modules, required=False)
- link_args = ['--link-static', '--system-libs'] if self.static else ['--link-shared']
- p, out = Popen_safe(
- [self.llvmconfig, '--libs', '--ldflags'] + link_args + list(self.required_modules))[:2]
- if p.returncode != 0:
- raise DependencyException('Could not generate libs for LLVM.')
- self.link_args = strip_system_libdirs(environment, shlex.split(out))
p, out = Popen_safe([self.llvmconfig, '--cppflags'])[:2]
if p.returncode != 0:
raise DependencyException('Could not generate includedir for LLVM.')
cargs = mesonlib.OrderedSet(shlex.split(out))
self.compile_args = list(cargs.difference(self.__cpp_blacklist))
+ if version_compare(self.version, '>= 3.9'):
+ self._set_new_link_args()
+ else:
+ self._set_old_link_args()
+ self.link_args = strip_system_libdirs(environment, self.link_args)
+
+ def _set_new_link_args(self):
+ """How to set linker args for LLVM versions >= 3.9"""
+ link_args = ['--link-static', '--system-libs'] if self.static else ['--link-shared']
+ p, out = Popen_safe(
+ [self.llvmconfig, '--libs', '--ldflags'] + link_args + list(self.required_modules))[:2]
+ if p.returncode != 0:
+ raise DependencyException('Could not generate libs for LLVM.')
+ self.link_args = shlex.split(out)
+
+ def _set_old_link_args(self):
+ """Setting linker args for older versions of llvm.
+
+ Old versions of LLVM bring an extra level of insanity with them.
+ llvm-config will provide the correct arguments for static linking, but
+ not for shared-linnking, we have to figure those out ourselves, because
+ of course we do.
+ """
+ if self.static:
+ p, out = Popen_safe(
+ [self.llvmconfig, '--libs', '--ldflags', '--system-libs'] + list(self.required_modules))[:2]
+ if p.returncode != 0:
+ raise DependencyException('Could not generate libs for LLVM.')
+ self.link_args = shlex.split(out)
+ else:
+ # llvm-config will provide arguments for static linking, so we get
+ # to figure out for ourselves what to link with. We'll do that by
+ # checking in the directory provided by --libdir for a library
+ # called libLLVM-<ver>.(so|dylib|dll)
+ p, out = Popen_safe([self.llvmconfig, '--libdir'])[:2]
+ if p.returncode != 0:
+ raise DependencyException('Could not generate libs for LLVM.')
+ libdir = out.strip()
+
+ expected_name = 'libLLVM-{}'.format(self.version)
+ re_name = re.compile(r'{}.(so|dll|dylib)'.format(expected_name))
+
+ for file_ in os.listdir(libdir):
+ if re_name.match(file_):
+ self.link_args = ['-L{}'.format(libdir),
+ '-l{}'.format(os.path.splitext(file_.lstrip('lib'))[0])]
+ break
+ else:
+ raise DependencyException(
+ 'Could not find a dynamically linkable library for LLVM.')
+
def check_components(self, modules, required=True):
"""Check for llvm components (modules in meson terms).