From 55844093468d09005350baf9bd21a5022cfc30b2 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 5 Oct 2017 11:42:44 -0700 Subject: [PATCH] llvm: Add support for linking statically This adds support for the static kwarg to the llvm dependency. --- mesonbuild/dependencies/dev.py | 4 ++- test cases/frameworks/15 llvm/meson.build | 33 ++++++++++++++--------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index 858f12fb6..b9e35e167 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -139,6 +139,7 @@ class LLVMDependency(ExternalDependency): self.provided_modules = [] self.required_modules = set() self.llvmconfig = None + self.static = kwargs.get('static', False) self.__best_found = None # FIXME: Support multiple version requirements ala PkgConfigDependency req_version = kwargs.get('version', None) @@ -180,8 +181,9 @@ 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'] + list(self.required_modules))[:2] + [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)) diff --git a/test cases/frameworks/15 llvm/meson.build b/test cases/frameworks/15 llvm/meson.build index ee6f556dc..eb1b8d58c 100644 --- a/test cases/frameworks/15 llvm/meson.build +++ b/test cases/frameworks/15 llvm/meson.build @@ -1,12 +1,5 @@ project('llvmtest', ['c', 'cpp'], default_options : ['c_std=c99']) -llvm_dep = dependency( - 'llvm', - modules : ['bitwriter', 'asmprinter', 'executionengine', 'target', - 'mcjit', 'nativecodegen'], - required : true, -) - d = dependency('llvm', modules : 'not-found', required : false) assert(d.found() == false, 'not-found llvm module found') @@ -16,9 +9,23 @@ assert(d.found() == false, 'ancient llvm module found') d = dependency('llvm', optional_modules : 'not-found', required : false) assert(d.found() == true, 'optional module stopped llvm from being found.') -executable('sum', 'sum.c', dependencies : [ - llvm_dep, - dependency('zlib'), - meson.get_compiler('c').find_library('dl', required : false), - dependency('glib-2.0'), - ]) +foreach static : [true, false] + llvm_dep = dependency( + 'llvm', + modules : ['bitwriter', 'asmprinter', 'executionengine', 'target', + 'mcjit', 'nativecodegen'], + required : true, + static : static, + ) + name = static ? 'static' : 'dynamic' + executable( + 'sum-@0@'.format(name), + 'sum.c', + dependencies : [ + llvm_dep, + dependency('zlib'), + dependency('glib-2.0'), + meson.get_compiler('c').find_library('dl', required : false), + ] + ) +endforeach