diff options
-rw-r--r-- | mesonbuild/compilers/d.py | 68 |
1 files changed, 45 insertions, 23 deletions
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 9ad0599..abf9297 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -286,20 +286,25 @@ class DCompiler(Compiler): # The flags might have been added by pkg-config files, # and are therefore out of the user's control. for arg in args: + # Translate OS specific arguments first. + osargs = [] + if is_windows(): + osargs = cls.translate_arg_to_windows(arg) + elif is_osx(): + osargs = cls.translate_arg_to_osx(arg) + if osargs: + dcargs.extend(osargs) + continue + + # Translate common D arguments here. if arg == '-pthread': continue if arg.startswith('-Wl,'): + # Translate linker arguments here. linkargs = arg[arg.index(',') + 1:].split(',') for la in linkargs: - if la.startswith('--out-implib='): - # Import library name for MSVC targets - dcargs.append('-L=/IMPLIB:' + la[13:].strip()) - continue dcargs.append('-L=' + la.strip()) continue - elif arg.startswith('-install_name'): - dcargs.append('-L=' + arg) - continue elif arg.startswith('-link-defaultlib') or arg.startswith('-linker'): # these are special arguments to the LDC linker call, # arguments like "-link-defaultlib-shared" do *not* @@ -312,7 +317,7 @@ class DCompiler(Compiler): # translate library link flag dcargs.append('-L=' + arg) continue - elif arg.startswith('-L/') or arg.startswith('-L./'): + elif arg.startswith('-L'): # we need to handle cases where -L is set by e.g. a pkg-config # setting to select a linker search path. We can however not # unconditionally prefix '-L' with '-L' because the user might @@ -327,26 +332,43 @@ class DCompiler(Compiler): # or other objects that we need to link. dcargs.append('-L=' + arg) continue - elif arg.startswith('-mscrtlib='): - mscrtlib = arg[10:].lower() - if cls is LLVMDCompiler: - # Default crt libraries for LDC2 must be excluded for other - # selected crt options. - if mscrtlib != 'libcmt': - dcargs.append('-L=/NODEFAULTLIB:libcmt') - dcargs.append('-L=/NODEFAULTLIB:libvcruntime') + dcargs.append(arg) - # Fixes missing definitions for printf-functions in VS2017 - if mscrtlib.startswith('msvcrt'): - dcargs.append('-L=/DEFAULTLIB:legacy_stdio_definitions.lib') + return dcargs - dcargs.append(arg) + @classmethod + def translate_arg_to_windows(cls, arg): + args = [] + if arg.startswith('-Wl,'): + # Translate linker arguments here. + linkargs = arg[arg.index(',') + 1:].split(',') + for la in linkargs: + if la.startswith('--out-implib='): + # Import library name + args.append('-L=/IMPLIB:' + la[13:].strip()) + elif arg.startswith('-mscrtlib='): + args.append(arg) + mscrtlib = arg[10:].lower() + if cls is LLVMDCompiler: + # Default crt libraries for LDC2 must be excluded for other + # selected crt options. + if mscrtlib != 'libcmt': + args.append('-L=/NODEFAULTLIB:libcmt') + args.append('-L=/NODEFAULTLIB:libvcruntime') + + # Fixes missing definitions for printf-functions in VS2017 + if mscrtlib.startswith('msvcrt'): + args.append('-L=/DEFAULTLIB:legacy_stdio_definitions.lib') - continue - dcargs.append(arg) + return args - return dcargs + @classmethod + def translate_arg_to_osx(cls, arg): + args = [] + if arg.startswith('-install_name'): + args.append('-L=' + arg) + return args def get_debug_args(self, is_debug): return clike_debug_args[is_debug] |