Repository: mesonbuild/meson

Issue:
depscan.dd is not found with Fortran preprocessing
**Describe the bug**
I have an error if I use Fortran prepropressing with Meson.
```
meson compile -C builddir4
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /usr/bin/ninja -C /home/alexis/Bureau/git/hsl/juliahsl/builddir4
ninja: Entering directory `/home/alexis/Bureau/git/hsl/juliahsl/builddir4'
ninja: error: loading 'preprocessor.p/depscan.dd': No such file or directory
```

**To Reproduce**
```
fc = meson.get_compiler('fortran')
libhsl_src = []
libhsl_src += files(file1.f, file2.f, file3.f90)
pp_libhsl_src = fc.preprocess(libhsl_src,
                              compile_args : ['-Dmetis_nodend=juliahsl_metis', '-DMETIS_NODEND=juliahsl_metis'],
                              output: '@PLAINNAME@')
```

**Expected behavior**
I expect to not have an error. it's working fine with `cc.preprocess(...)` where `cc=meson.get_compiler('c')`.

**system parameters**
* Is this a [cross build](https://mesonbuild.com/Cross-compilation.html) or just a plain native build (for the same computer)?
No

* what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)
Ubuntu 22.04

* what Python version are you using e.g. 3.8.0 
3.10

* what `meson --version`
1.0.1

* what `ninja --version` if it's a Ninja build
1.10.1.



Discussion:
cc @xclaesse 
@eli-schwartz 
I did a small project to reproduce the error: https://github.com/mesonbuild/meson/compare/master...amontoison:meson:fortran_preprocess

I hope that it will help to the solve the issue :crossed_fingers:  
@Volker-Weissmann
You fixed a few things recently for Fortran compilers.
Do you have an idea how to solve this issue?

I don't understand why Meson needs a depscan.dd to preprocess files. It should only need it for the compilation.

Resolving patch:
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -2954,6 +2954,8 @@ def generate_single_compile(self, target: build.BuildTarget, src,
     def add_dependency_scanner_entries_to_element(self, target, compiler, element, src):
         if not self.should_use_dyndeps_for_target(target):
             return
+        if isinstance(target, build.CompileTarget):
+            return
         extension = os.path.splitext(src.fname)[1][1:]
         if extension != 'C':
             extension = extension.lower()


Test patch:
diff --git a/test cases/fortran/22 preprocess/main.f90 b/test cases/fortran/22 preprocess/main.f90
new file mode 100644
--- /dev/null
+++ b/test cases/fortran/22 preprocess/main.f90	
@@ -0,0 +1,4 @@
+#define MYDEF program
+MYDEF foo
+    write (*,*) 'Hello, world!'
+end MYDEF foo
diff --git a/test cases/fortran/22 preprocess/meson.build b/test cases/fortran/22 preprocess/meson.build
new file mode 100644
--- /dev/null
+++ b/test cases/fortran/22 preprocess/meson.build	
@@ -0,0 +1,7 @@
+project('preprocess', 'fortran')
+
+fc = meson.get_compiler('fortran')
+
+pp_files = fc.preprocess('main.f90', output: '@PLAINNAME@')
+
+library('foo', pp_files)