summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Lister <andrew.lister@stfc.ac.uk>2025-06-20 15:33:59 +0100
committerDylan Baker <dylan@pnwbakers.com>2025-06-27 09:29:55 -0700
commit68d29ef7f62df5481aa4de8eaf421f25243f4cb2 (patch)
tree6c19d50608dc012264a6ced7d6a1d41d9a2ab6cf
parentfea9f6918a6647430f4e22ca908f074b3e93e489 (diff)
downloadmeson-68d29ef7f62df5481aa4de8eaf421f25243f4cb2.tar.gz
compilers-fortran: Fix preprocessing when fortran uses concat operator
-rw-r--r--mesonbuild/compilers/fortran.py5
-rw-r--r--mesonbuild/compilers/mixins/gnu.py2
-rw-r--r--test cases/fortran/23 preprocess/main.f9012
-rw-r--r--test cases/fortran/23 preprocess/meson.build11
4 files changed, 26 insertions, 4 deletions
diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py
index 180a2dbfa..6f4f3d2c1 100644
--- a/mesonbuild/compilers/fortran.py
+++ b/mesonbuild/compilers/fortran.py
@@ -446,6 +446,11 @@ class IntelLLVMFortranCompiler(IntelFortranCompiler):
id = 'intel-llvm'
+ def get_preprocess_only_args(self) -> T.List[str]:
+ return ['-preprocess-only']
+
+ def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
+ return []
class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler):
diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py
index 9ea591e04..ddcd14a15 100644
--- a/mesonbuild/compilers/mixins/gnu.py
+++ b/mesonbuild/compilers/mixins/gnu.py
@@ -534,6 +534,8 @@ class GnuLikeCompiler(Compiler, metaclass=abc.ABCMeta):
# We want to allow preprocessing files with any extension, such as
# foo.c.in. In that case we need to tell GCC/CLANG to treat them as
# assembly file.
+ if self.language == 'fortran':
+ return self.get_preprocess_only_args()
lang = gnu_lang_map.get(self.language, 'assembler-with-cpp')
return self.get_preprocess_only_args() + [f'-x{lang}']
diff --git a/test cases/fortran/23 preprocess/main.f90 b/test cases/fortran/23 preprocess/main.f90
index 7cbc11cec..825174158 100644
--- a/test cases/fortran/23 preprocess/main.f90
+++ b/test cases/fortran/23 preprocess/main.f90
@@ -1,4 +1,14 @@
#define MYDEF program
MYDEF foo
- write (*,*) 'Hello, world!'
+ character(20) :: str
+#ifdef CORRECT
+ str = 'Hello, ' // 'world!'
+#else
+ str = 'Preprocessing error!'
+#endif
+ if (str /= 'Hello, world!') then
+ print *, 'Preprocessing failed.'
+ error stop 1
+ end if
+ stop 0
end MYDEF foo
diff --git a/test cases/fortran/23 preprocess/meson.build b/test cases/fortran/23 preprocess/meson.build
index b776940a9..88077d3c6 100644
--- a/test cases/fortran/23 preprocess/meson.build
+++ b/test cases/fortran/23 preprocess/meson.build
@@ -1,7 +1,12 @@
-project('preprocess', 'fortran')
+project('preprocess', 'fortran', meson_version: '>1.3.2')
fc = meson.get_compiler('fortran')
-pp_files = fc.preprocess('main.f90', output: '@PLAINNAME@')
+pp_files = fc.preprocess(
+ 'main.f90',
+ compile_args: ['-DCORRECT=true'],
+ output: '@PLAINNAME@')
-library('foo', pp_files)
+t = executable('foo', pp_files)
+
+test('check_result', t)