Repository: mesonbuild/meson

Issue:
Mix of C and Fortran sources + threads dependency = Backend setup failure
I'm trying to create a static library that contains a mixture of C and Fortran sources. It also needs `threads` dependency (for C part).
When I'm running `meson . build`, I get the following trace:
```
Build targets in project: 19
Found ninja-1.8.2 at /usr/bin/ninja
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/mesonbuild/mesonmain.py", line 365, in run
    app.generate()
  File "/usr/lib/python3.6/site-packages/mesonbuild/mesonmain.py", line 151, in generate
    self._generate(env)
  File "/usr/lib/python3.6/site-packages/mesonbuild/mesonmain.py", line 208, in _generate
    g.generate(intr)
  File "/usr/lib/python3.6/site-packages/mesonbuild/backend/ninjabackend.py", line 210, in generate
    self.generate_target(t, outfile)
  File "/usr/lib/python3.6/site-packages/mesonbuild/backend/ninjabackend.py", line 455, in generate_target
    obj_list.append(self.generate_single_compile(target, outfile, src, False, [], header_deps))
  File "/usr/lib/python3.6/site-packages/mesonbuild/backend/ninjabackend.py", line 2149, in generate_single_compile
    commands = self._generate_single_compile(target, compiler, is_generated)
  File "/usr/lib/python3.6/site-packages/mesonbuild/backend/ninjabackend.py", line 2074, in _generate_single_compile
    commands += self.generate_basic_compiler_args(target, compiler, no_warn_args)
  File "/usr/lib/python3.6/site-packages/mesonbuild/backend/backends.py", line 514, in generate_basic_compiler_args
    commands += compiler.thread_flags(self.environment)
AttributeError: 'GnuFortranCompiler' object has no attribute 'thread_flags'
```

Probably `backends.py` should just skip `thread_flags` if not supported by the compiler (maybe with a warning when all target compilers do not support it).

The current workaround is to split the target into C target and F target, but when `threads` dependency is implicit (e.g. part of `declare_dependency()`), it becomes annoying.
Mix of C and Fortran sources + threads dependency = Backend setup failure
I'm trying to create a static library that contains a mixture of C and Fortran sources. It also needs `threads` dependency (for C part).
When I'm running `meson . build`, I get the following trace:
```
Build targets in project: 19
Found ninja-1.8.2 at /usr/bin/ninja
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/mesonbuild/mesonmain.py", line 365, in run
    app.generate()
  File "/usr/lib/python3.6/site-packages/mesonbuild/mesonmain.py", line 151, in generate
    self._generate(env)
  File "/usr/lib/python3.6/site-packages/mesonbuild/mesonmain.py", line 208, in _generate
    g.generate(intr)
  File "/usr/lib/python3.6/site-packages/mesonbuild/backend/ninjabackend.py", line 210, in generate
    self.generate_target(t, outfile)
  File "/usr/lib/python3.6/site-packages/mesonbuild/backend/ninjabackend.py", line 455, in generate_target
    obj_list.append(self.generate_single_compile(target, outfile, src, False, [], header_deps))
  File "/usr/lib/python3.6/site-packages/mesonbuild/backend/ninjabackend.py", line 2149, in generate_single_compile
    commands = self._generate_single_compile(target, compiler, is_generated)
  File "/usr/lib/python3.6/site-packages/mesonbuild/backend/ninjabackend.py", line 2074, in _generate_single_compile
    commands += self.generate_basic_compiler_args(target, compiler, no_warn_args)
  File "/usr/lib/python3.6/site-packages/mesonbuild/backend/backends.py", line 514, in generate_basic_compiler_args
    commands += compiler.thread_flags(self.environment)
AttributeError: 'GnuFortranCompiler' object has no attribute 'thread_flags'
```

Probably `backends.py` should just skip `thread_flags` if not supported by the compiler (maybe with a warning when all target compilers do not support it).

The current workaround is to split the target into C target and F target, but when `threads` dependency is implicit (e.g. part of `declare_dependency()`), it becomes annoying.


Discussion:
> Probably backends.py should just skip thread_flags if not supported by the compiler (maybe with a warning when all target compilers do not support it).

Yes, this makes sense to me. The warning is difficult to implement though because of how the code is structured.
> Probably backends.py should just skip thread_flags if not supported by the compiler (maybe with a warning when all target compilers do not support it).

Yes, this makes sense to me. The warning is difficult to implement though because of how the code is structured.

Resolving patch:
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -871,6 +871,9 @@ def build_unix_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, i
                 args += ['-Wl,-rpath-link,' + lpaths]
         return args
 
+    def thread_flags(self, env):
+        return []
+
 
 GCC_STANDARD = 0
 GCC_OSX = 1


Test patch: