@@ -28,7 +28,7 @@ def __init__(
28
28
include_dirs : list [Path ],
29
29
object_files : list [Path ],
30
30
linker_args : list [str ],
31
- c_args : list [str ],
31
+ fortran_args : list [str ],
32
32
build_type : str ,
33
33
python_exe : str ,
34
34
):
@@ -46,12 +46,18 @@ def __init__(
46
46
self .include_dirs = []
47
47
self .substitutions = {}
48
48
self .objects = object_files
49
+ # Convert args to '' wrapped variant for meson
50
+ self .fortran_args = [
51
+ f"'{ x } '" if not (x .startswith ("'" ) and x .endswith ("'" )) else x
52
+ for x in fortran_args
53
+ ]
49
54
self .pipeline = [
50
55
self .initialize_template ,
51
56
self .sources_substitution ,
52
57
self .deps_substitution ,
53
58
self .include_substitution ,
54
59
self .libraries_substitution ,
60
+ self .fortran_args_substitution ,
55
61
]
56
62
self .build_type = build_type
57
63
self .python_exe = python_exe
@@ -109,6 +115,14 @@ def include_substitution(self) -> None:
109
115
[f"{ self .indent } '''{ inc } '''," for inc in self .include_dirs ]
110
116
)
111
117
118
+ def fortran_args_substitution (self ) -> None :
119
+ if self .fortran_args :
120
+ self .substitutions ["fortran_args" ] = (
121
+ f"{ self .indent } fortran_args: [{ ', ' .join ([arg for arg in self .fortran_args ])} ],"
122
+ )
123
+ else :
124
+ self .substitutions ["fortran_args" ] = ""
125
+
112
126
def generate_meson_build (self ):
113
127
for node in self .pipeline :
114
128
node ()
@@ -126,6 +140,7 @@ def __init__(self, *args, **kwargs):
126
140
self .build_type = (
127
141
"debug" if any ("debug" in flag for flag in self .fc_flags ) else "release"
128
142
)
143
+ self .fc_flags = _get_flags (self .fc_flags )
129
144
130
145
def _move_exec_to_root (self , build_dir : Path ):
131
146
walk_dir = Path (build_dir ) / self .meson_build_dir
@@ -203,3 +218,17 @@ def _prepare_sources(mname, sources, bdir):
203
218
if not Path (source ).suffix == ".pyf"
204
219
]
205
220
return extended_sources
221
+
222
+
223
+ def _get_flags (fc_flags ):
224
+ flag_values = []
225
+ flag_pattern = re .compile (r"--f(77|90)flags=(.*)" )
226
+
227
+ for flag in fc_flags :
228
+ match_result = flag_pattern .match (flag )
229
+ if match_result :
230
+ values = match_result .group (2 ).strip ().split ()
231
+ flag_values .extend (values )
232
+ # Hacky way to preserve order of flags
233
+ unique_flags = list (dict .fromkeys (flag_values ))
234
+ return unique_flags
0 commit comments