diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2017-04-22 14:27:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-22 14:27:06 +0300 |
commit | 33b5ddf35e4c3f7a651f3fff13b0c4227c87e225 (patch) | |
tree | 862436e2672fbb2919b606da809cb3ddc3e4c20f /mesonbuild | |
parent | e107017b3bc73d8f04d43d47f2ccb7eecc817aaa (diff) | |
parent | 35ffb1a7c262acbcd15e532855471b0cb38379b5 (diff) | |
download | meson-33b5ddf35e4c3f7a651f3fff13b0c4227c87e225.zip meson-33b5ddf35e4c3f7a651f3fff13b0c4227c87e225.tar.gz meson-33b5ddf35e4c3f7a651f3fff13b0c4227c87e225.tar.bz2 |
Merge pull request #1654 from dcbaker/c-cpp-link
Add a testcase for linking C and C++ static archives into a shared li…
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/build.py | 37 | ||||
-rw-r--r-- | mesonbuild/dependencies.py | 18 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 13 |
3 files changed, 51 insertions, 17 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index bcbe318..a5ebc34 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -868,6 +868,28 @@ You probably should put it in link_with instead.''') def get_aliases(self): return {} + def get_langs_used_by_deps(self): + ''' + Sometimes you want to link to a C++ library that exports C API, which + means the linker must link in the C++ stdlib, and we must use a C++ + compiler for linking. The same is also applicable for objc/objc++, etc, + so we can keep using clike_langs for the priority order. + + See: https://github.com/mesonbuild/meson/issues/1653 + ''' + langs = [] + # Check if any of the external libraries were written in this language + for dep in self.external_deps: + if dep.language not in langs: + langs.append(dep.language) + # Check if any of the internal libraries this target links to were + # written in this language + for link_target in self.link_targets: + for language in link_target.compilers: + if language not in langs: + langs.append(language) + return langs + def get_clike_dynamic_linker(self): ''' We use the order of languages in `clike_langs` to determine which @@ -878,9 +900,20 @@ You probably should put it in link_with instead.''') that can link compiled C. We don't actually need to add an exception for Vala here because of that. ''' + # Populate list of all compilers, not just those being used to compile + # sources in this target + if self.is_cross: + all_compilers = self.environment.coredata.cross_compilers + else: + all_compilers = self.environment.coredata.compilers + # Languages used by dependencies + dep_langs = self.get_langs_used_by_deps() + # Pick a compiler based on the language priority-order for l in clike_langs: - if l in self.compilers: - return self.compilers[l] + if l in self.compilers or l in dep_langs: + return all_compilers[l] + m = 'Could not get a dynamic linker for build target {!r}' + raise AssertionError(m.format(self.name)) def get_using_msvc(self): ''' diff --git a/mesonbuild/dependencies.py b/mesonbuild/dependencies.py index 39bf2b1..04a22f9 100644 --- a/mesonbuild/dependencies.py +++ b/mesonbuild/dependencies.py @@ -51,6 +51,7 @@ class DependencyMethods(Enum): class Dependency: def __init__(self, type_name, kwargs): self.name = "null" + self.language = None self.is_found = False self.type_name = type_name method = DependencyMethods(kwargs.get('method', 'auto')) @@ -570,11 +571,12 @@ class ExternalProgram: return self.name class ExternalLibrary(Dependency): - # TODO: Add `lang` to the parent Dependency object so that dependencies can - # be expressed for languages other than C-like - def __init__(self, name, link_args=None, language=None, silent=False): + # TODO: Add `language` support to all Dependency objects so that languages + # can be exposed for dependencies that support that (i.e., not pkg-config) + def __init__(self, name, link_args, language, silent=False): super().__init__('external', {}) self.name = name + self.language = language self.is_found = False self.link_args = [] self.lang_args = [] @@ -582,9 +584,13 @@ class ExternalLibrary(Dependency): self.is_found = True if not isinstance(link_args, list): link_args = [link_args] - if language: - self.lang_args = {language: link_args} - else: + self.lang_args = {language: link_args} + # We special-case Vala for now till the Dependency object gets + # proper support for exposing the language it was written in. + # Without this, vala-specific link args will end up in the C link + # args list if you link to a Vala library. + # This hack use to be in CompilerHolder.find_library(). + if language != 'vala': self.link_args = link_args if not silent: if self.is_found: diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index ed08987..eaaea73 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -982,14 +982,7 @@ class CompilerHolder(InterpreterObject): if required and not linkargs: l = self.compiler.language.capitalize() raise InterpreterException('{} library {!r} not found'.format(l, libname)) - # If this is set to None, the library and link arguments are for - # a C-like compiler. Otherwise, it's for some other language that has - # a find_library implementation. We do this because it's easier than - # maintaining a list of languages that can consume C libraries. - lang = None - if self.compiler.language == 'vala': - lang = 'vala' - lib = dependencies.ExternalLibrary(libname, linkargs, language=lang) + lib = dependencies.ExternalLibrary(libname, linkargs, self.compiler.language) return ExternalLibraryHolder(lib) def has_argument_method(self, args, kwargs): @@ -2320,9 +2313,11 @@ class Interpreter(InterpreterBase): raise InterpreterException('Input must be a string or a file') if isinstance(inputfile, str): inputfile = os.path.join(self.subdir, inputfile) + ifile_abs = os.path.join(self.environment.source_dir, inputfile) else: + ifile_abs = inputfile.absolute_path(self.environment.source_dir, + self.environment.build_dir) inputfile = inputfile.relative_name() - ifile_abs = os.path.join(self.environment.source_dir, inputfile) elif 'command' in kwargs and '@INPUT@' in kwargs['command']: raise InterpreterException('@INPUT@ used as command argument, but no input file specified.') # Validate output |