diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py index 06e01d073..5de1de42c 100644 --- a/mesonbuild/compilers/fortran.py +++ b/mesonbuild/compilers/fortran.py @@ -31,6 +31,7 @@ from .compilers import ( IntelVisualStudioLikeCompiler, ) from .clike import CLikeCompiler +from .. import mlog from mesonbuild.mesonlib import ( EnvironmentException, MachineChoice, is_osx, LibType @@ -145,6 +146,25 @@ class FortranCompiler(CLikeCompiler, Compiler): end program main''' return self.find_library_impl(libname, env, extra_dirs, code, libtype) + def has_multi_arguments(self, args, env): + for arg in args[:]: + # some compilers, e.g. GCC, don't warn for unsupported warning-disable + # flags, so when we are testing a flag like "-Wno-forgotten-towel", also + # check the equivalent enable flag too "-Wforgotten-towel" + if arg.startswith('-Wno-'): + args.append('-W' + arg[5:]) + if arg.startswith('-Wl,'): + mlog.warning('{} looks like a linker argument, ' + 'but has_argument and other similar methods only ' + 'support checking compiler arguments. Using them ' + 'to check linker arguments are never supported, ' + 'and results are likely to be wrong regardless of ' + 'the compiler you are using. has_link_argument or ' + 'other similar method can be used instead.' + .format(arg)) + code = 'program main\ncall exit(0)\nend program main' + return self.has_arguments(args, env, code, mode='compile') + class GnuFortranCompiler(GnuCompiler, FortranCompiler): def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None, **kwargs): diff --git a/test cases/fortran/1 basic/meson.build b/test cases/fortran/1 basic/meson.build index 959ad3526..52e2d6f05 100644 --- a/test cases/fortran/1 basic/meson.build +++ b/test cases/fortran/1 basic/meson.build @@ -5,6 +5,9 @@ if fc.get_id() == 'gcc' add_global_arguments('-fbounds-check', language : 'fortran') endif +args = fc.first_supported_argument(['-ffree-form', '-free', '/free']) +assert(args != [], 'No arguments found?') + e = executable('simple', 'simple.f90', - fortran_args : '-ffree-form') + fortran_args : args) test('Simple Fortran', e)