@@ -231,7 +231,7 @@ def __init__(self, target: CMakeTarget, env: 'Environment', for_machine: Machine
231
231
if target .install_paths :
232
232
self .install_dir = target .install_paths [0 ]
233
233
234
- self .languages = [] # type: T.List [str]
234
+ self .languages = set () # type: T.Set [str]
235
235
self .sources = [] # type: T.List[Path]
236
236
self .generated = [] # type: T.List[Path]
237
237
self .generated_ctgt = [] # type: T.List[CustomTargetReference]
@@ -250,19 +250,40 @@ def __init__(self, target: CMakeTarget, env: 'Environment', for_machine: Machine
250
250
self .name = _sanitize_cmake_name (self .name )
251
251
252
252
self .generated_raw = [] # type: T.List[Path]
253
+
253
254
for i in target .files :
254
- # Determine the meson language
255
+ languages = set () # type: T.Set[str]
256
+ src_suffixes = set () # type: T.Set[str]
257
+
258
+ # Insert suffixes
259
+ for j in i .sources :
260
+ if not j .suffix :
261
+ continue
262
+ src_suffixes .add (j .suffix [1 :])
263
+
264
+ # Determine the meson language(s)
265
+ # Extract the default language from the explicit CMake field
255
266
lang_cmake_to_meson = {val .lower (): key for key , val in language_map .items ()}
256
- lang = lang_cmake_to_meson .get (i .language .lower (), 'c' )
257
- if lang not in self .languages :
258
- self .languages += [lang ]
259
- if lang not in self .compile_opts :
260
- self .compile_opts [lang ] = []
267
+ languages .add (lang_cmake_to_meson .get (i .language .lower (), 'c' ))
268
+
269
+ # Determine missing languages from the source suffixes
270
+ for sfx in src_suffixes :
271
+ for key , val in lang_suffixes .items ():
272
+ if sfx in val :
273
+ languages .add (key )
274
+ break
275
+
276
+ # Register the new languages and initialize the compile opts array
277
+ for lang in languages :
278
+ self .languages .add (lang )
279
+ if lang not in self .compile_opts :
280
+ self .compile_opts [lang ] = []
261
281
262
282
# Add arguments, but avoid duplicates
263
283
args = i .flags
264
284
args += ['-D{}' .format (x ) for x in i .defines ]
265
- self .compile_opts [lang ] += [x for x in args if x not in self .compile_opts [lang ]]
285
+ for lang in languages :
286
+ self .compile_opts [lang ] += [x for x in args if x not in self .compile_opts [lang ]]
266
287
267
288
# Handle include directories
268
289
self .includes += [x .path for x in i .includes if x .path not in self .includes and not x .isSystem ]
0 commit comments