Made Fortran static libraries work. Closes #237.

pull/238/head
Jussi Pakkanen 9 years ago
parent 7c6e99149b
commit 5467b7d58b
  1. 6
      backends.py
  2. 13
      ninjabackend.py
  3. 6
      test cases/fortran/5 static/main.f95
  4. 5
      test cases/fortran/5 static/meson.build
  5. 17
      test cases/fortran/5 static/static_hello.f95

@ -220,6 +220,12 @@ class Backend():
if isinstance(target, build.Executable):
commands += dep.get_exe_args()
# Fortran rquires extra include directives.
if compiler.language == 'fortran':
for lt in target.link_targets:
priv_dir = os.path.join(lt.subdir, lt.get_basename() + lt.type_suffix())
incflag = compiler.get_include_args(priv_dir)
commands += incflag
return commands
def build_target_link_arguments(self, compiler, deps):

@ -1225,11 +1225,24 @@ rule FORTRAN_DEP_HACK
element.add_orderdep(d)
element.add_orderdep(pch_dep)
element.add_orderdep(extra_orderdeps)
for i in self.get_fortran_orderdeps(target, compiler):
element.add_orderdep(i)
element.add_item('DEPFILE', dep_file)
element.add_item('ARGS', commands)
element.write(outfile)
return rel_obj
# Fortran is a bit weird (again). When you link against a library, just compiling a source file
# requires the mod files that are output when single files are built. To do this right we would need to
# scan all inputs and write out explicit deps for each file. That is stoo slow and too much effort so
# instead just have an ordered dependendy on the library. This ensures all reqquired mod files are created.
# The real deps are then detected via dep file generation from the compiler. This breaks on compilers that
# produce incorrect dep files but such is life.
def get_fortran_orderdeps(self, target, compiler):
if compiler.language != 'fortran':
return []
return [os.path.join(lt.subdir, lt.filename) for lt in target.link_targets]
def generate_msvc_pch_command(self, target, compiler, pch):
if len(pch) != 2:
raise RuntimeError('MSVC requires one header and one source to produce precompiled headers.')

@ -0,0 +1,6 @@
program hello
use static_hello
implicit none
call static_say_hello()
end program hello

@ -0,0 +1,5 @@
project('try-static-library', 'fortran')
static_hello = static_library('static_hello', 'static_hello.f95')
executable('test_exe', 'main.f95', link_with : static_hello)

@ -0,0 +1,17 @@
module static_hello
implicit none
private
public :: static_say_hello
interface static_say_hello
module procedure say_hello
end interface static_say_hello
contains
subroutine say_hello
print *, "Static library called."
end subroutine say_hello
end module static_hello
Loading…
Cancel
Save