diff --git a/mesonbuild/compilers/__init__.py b/mesonbuild/compilers/__init__.py index 7be1b4c89..ea65c2144 100644 --- a/mesonbuild/compilers/__init__.py +++ b/mesonbuild/compilers/__init__.py @@ -66,9 +66,13 @@ __all__ = [ 'GnuObjCCompiler', 'GnuObjCPPCompiler', 'IntelGnuLikeCompiler', + 'IntelVisualStudioLikeCompiler', 'IntelCCompiler', 'IntelCPPCompiler', + 'IntelClCCompiler', + 'IntelClCPPCompiler', 'IntelFortranCompiler', + 'IntelClFortranCompiler', 'JavaCompiler', 'LLVMDCompiler', 'MonoCompiler', @@ -122,6 +126,7 @@ from .compilers import ( IntelGnuLikeCompiler, CcrxCompiler, VisualStudioLikeCompiler, + IntelVisualStudioLikeCompiler, ) from .c import ( CCompiler, @@ -132,6 +137,7 @@ from .c import ( GnuCCompiler, ElbrusCCompiler, IntelCCompiler, + IntelClCCompiler, PGICCompiler, CcrxCCompiler, VisualStudioCCompiler, @@ -145,6 +151,7 @@ from .cpp import ( GnuCPPCompiler, ElbrusCPPCompiler, IntelCPPCompiler, + IntelClCPPCompiler, PGICPPCompiler, CcrxCPPCompiler, VisualStudioCPPCompiler, @@ -164,6 +171,7 @@ from .fortran import ( ElbrusFortranCompiler, FlangFortranCompiler, IntelFortranCompiler, + IntelClFortranCompiler, NAGFortranCompiler, Open64FortranCompiler, PathScaleFortranCompiler, diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index e7c93388a..0cfcbc36a 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -16,7 +16,7 @@ import os.path import typing from .. import coredata -from ..mesonlib import MesonException, version_compare +from ..mesonlib import MesonException, version_compare, mlog from .c_function_attributes import C_FUNC_ATTRIBUTES from .clike import CLikeCompiler @@ -31,6 +31,7 @@ from .compilers import ( GnuCompiler, ElbrusCompiler, IntelGnuLikeCompiler, + IntelVisualStudioLikeCompiler, PGICompiler, CcrxCompiler, VisualStudioLikeCompiler, @@ -279,6 +280,36 @@ class ClangClCCompiler(VisualStudioLikeCompiler, VisualStudioLikeCCompilerMixin, self.id = 'clang-cl' +class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerMixin, CCompiler): + + """Intel "ICL" compiler abstraction.""" + + __have_warned = False + + def __init__(self, exelist, version, is_cross, exe_wrap, target): + CCompiler.__init__(self, exelist, version, is_cross, exe_wrap) + IntelVisualStudioLikeCompiler.__init__(self, target) + + def get_options(self): + opts = super().get_options() + c_stds = ['none', 'c89', 'c99', 'c11'] + opts.update({'c_std': coredata.UserComboOption('c_std', 'C language standard to use', + c_stds, + 'none')}) + return opts + + def get_option_compile_args(self, options): + args = [] + std = options['c_std'] + if std.value == 'c89': + if not self.__have_warned: + self.__have_warned = True + mlog.warning("ICL doesn't explicitly implement c89, setting the standard to 'none', which is close.") + elif std.value != 'none': + args.append('/Qstd:' + std.value) + return args + + class ArmCCompiler(ArmCompiler, CCompiler): def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, **kwargs): CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs) diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index eb716f7ed..8c40cedf9 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -2344,6 +2344,48 @@ class IntelGnuLikeCompiler(GnuLikeCompiler): return ['-prof-use'] +class IntelVisualStudioLikeCompiler(VisualStudioLikeCompiler): + + """Abstractions for ICL, the Intel compiler on Windows.""" + + def __init__(self, target: str): + super().__init__(target) + self.compiler_type = CompilerType.ICC_WIN + self.id = 'intel-cl' + + def compile(self, code, *, extra_args=None, **kwargs): + # This covers a case that .get('foo', []) doesn't, that extra_args is + if kwargs.get('mode', 'compile') != 'link': + extra_args = extra_args.copy() if extra_args is not None else [] + extra_args.extend([ + '/Qdiag-error:10006', # ignoring unknown option + '/Qdiag-error:10148', # Option not supported + '/Qdiag-error:10155', # ignoring argument required + '/Qdiag-error:10156', # ignoring not argument allowed + '/Qdiag-error:10157', # Ignoring argument of the wrong type + '/Qdiag-error:10158', # Argument must be separate. Can be hit by trying an option like -foo-bar=foo when -foo=bar is a valid option but -foo-bar isn't + ]) + return super().compile(code, extra_args, **kwargs) + + def get_toolset_version(self) -> Optional[str]: + # Avoid circular dependencies.... + from ..environment import search_version + + # ICL provides a cl.exe that returns the version of MSVC it tries to + # emulate, so we'll get the version from that and pass it to the same + # function the real MSVC uses to calculate the toolset version. + _, _, err = Popen_safe(['cl.exe']) + v1, v2, *_ = search_version(err).split('.') + version = int(v1 + v2) + return self._calculate_toolset_version(version) + + def get_linker_exelist(self): + return ['xilink'] + + def openmp_flags(self): + return ['/Qopenmp'] + + class ArmCompiler: # Functionality that is common to all ARM family compilers. def __init__(self, compiler_type): diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index fe2839a04..c5079cbcb 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -28,6 +28,7 @@ from .compilers import ( GnuCompiler, ElbrusCompiler, IntelGnuLikeCompiler, + IntelVisualStudioLikeCompiler, PGICompiler, ArmCompiler, ArmclangCompiler, @@ -483,6 +484,18 @@ class ClangClCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixin, Vi return self._get_options_impl(super().get_options(), cpp_stds) +class IntelClCPPCompiler(VisualStudioLikeCPPCompilerMixin, IntelVisualStudioLikeCompiler, CPPCompiler): + + def __init__(self, exelist, version, is_cross, exe_wrap, target): + CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap) + IntelVisualStudioLikeCompiler.__init__(self, target) + + def get_options(self): + # This has only been tested with verison 19.0, + cpp_stds = ['none', 'c++11', 'vc++11', 'c++14', 'vc++14', 'c++17', 'vc++17', 'c++latest'] + return self._get_options_impl(super().get_options(), cpp_stds) + + class ArmCPPCompiler(ArmCompiler, CPPCompiler): def __init__(self, exelist, version, compiler_type, is_cross, exe_wrap=None, **kwargs): CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap, **kwargs) diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py index 4f9b9ffa3..06e01d073 100644 --- a/mesonbuild/compilers/fortran.py +++ b/mesonbuild/compilers/fortran.py @@ -27,7 +27,8 @@ from .compilers import ( ClangCompiler, ElbrusCompiler, IntelGnuLikeCompiler, - PGICompiler + PGICompiler, + IntelVisualStudioLikeCompiler, ) from .clike import CLikeCompiler @@ -66,6 +67,7 @@ class FortranCompiler(CLikeCompiler, Compiler): for_machine = MachineChoice.HOST extra_flags = environment.coredata.get_external_args(for_machine, self.language) extra_flags += environment.coredata.get_external_link_args(for_machine, self.language) + extra_flags += self.get_always_args() # %% build the test executable pc = subprocess.Popen(self.exelist + extra_flags + [str(source_name), '-o', str(binary_name)]) pc.wait() @@ -239,6 +241,36 @@ class IntelFortranCompiler(IntelGnuLikeCompiler, FortranCompiler): def language_stdlib_only_link_flags(self): return ['-lifcore', '-limf'] +class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler): + + file_suffixes = ['f90', 'f', 'for', 'ftn', 'fpp'] + always_args = ['/nologo'] + + BUILD_ARGS = { + 'plain': [], + 'debug': ["/Zi", "/Od"], + 'debugoptimized': ["/Zi", "/O1"], + 'release': ["/O2"], + 'minsize': ["/Os"], + 'custom': [], + } + + def __init__(self, exelist, version, is_cross, target: str, exe_wrapper=None): + FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) + IntelVisualStudioLikeCompiler.__init__(self, target) + + default_warn_args = ['/warn:general', '/warn:truncated_source'] + self.warn_args = {'0': [], + '1': default_warn_args, + '2': default_warn_args + ['/warn:unused'], + '3': ['/warn:all']} + + def get_module_outdir_args(self, path) -> List[str]: + return ['/module:' + path] + + def get_buildtype_args(self, buildtype: str) -> List[str]: + return self.BUILD_ARGS[buildtype] + class PathScaleFortranCompiler(FortranCompiler): def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwags):