diff options
author | Matthew Krupcale <mkrupcale@matthewkrupcale.com> | 2018-04-24 01:06:49 -0400 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2018-05-21 23:17:02 +0300 |
commit | 45cc001a40ff52254a0bd27718149dce8cebe73d (patch) | |
tree | d2619f359c7ba255138ef2ea6e08a09452b2eb8b /mesonbuild/compilers/c.py | |
parent | cf5fe1d4401505ac808b1b018a21dbcc30cfc9f5 (diff) | |
download | meson-45cc001a40ff52254a0bd27718149dce8cebe73d.zip meson-45cc001a40ff52254a0bd27718149dce8cebe73d.tar.gz meson-45cc001a40ff52254a0bd27718149dce8cebe73d.tar.bz2 |
Add support for finding libraries in Fortran projects
* mesonbuild/compilers/c.py: Make the `find_library` method more generic by allowing the user to supply the `code` for compiling and linking.
* mesonbuild/compilers/fortran.py: Use the methods inherited from `Compiler` base class where appropriate. Also reuse `CComiler` methods where applicable. This should be sufficient to get various compiler/linker arguments as well as to compile and link Fortran programs. This was tested with `gfortran` compiler, and while the other compilers ought to work for simple cases, their methods are primarily inherited from the base `FortranCompiler` class.
* test cases/fortran/10 find library/gzip.f90: Fortran module with some basic Fortran wrapper interfaces to `gzopen`, `gzwrite`, and `gzclose` C `zlib` functions.
* test cases/fortran/10 find library/main.f90: Fortran program using the `gzip` Fortran interface module to write some data to a gzip file.
* test cases/fortran/10 find library/meson.build: Meson build file for this test case. This demonstrates the ability to link the Fortran program against an external library.
Diffstat (limited to 'mesonbuild/compilers/c.py')
-rw-r--r-- | mesonbuild/compilers/c.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index 81c0229..13b3dcc 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -808,12 +808,11 @@ class CCompiler(Compiler): raise AssertionError('BUG: unknown libtype {!r}'.format(libtype)) return prefixes, suffixes - def find_library(self, libname, env, extra_dirs, libtype='default'): + def find_library_impl(self, libname, env, extra_dirs, code, libtype='default'): # 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; }' if extra_dirs and isinstance(extra_dirs, str): extra_dirs = [extra_dirs] # Gcc + co seem to prefer builtin lib dirs to -L dirs. @@ -838,6 +837,10 @@ class CCompiler(Compiler): return [trial] return None + def find_library(self, libname, env, extra_dirs, libtype='default'): + code = 'int main(int argc, char **argv) { return 0; }' + return self.find_library_impl(libname, env, extra_dirs, code, libtype) + def thread_flags(self, env): if for_haiku(self.is_cross, env): return [] |