diff options
Diffstat (limited to 'mesonbuild/environment.py')
-rw-r--r-- | mesonbuild/environment.py | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 0809ac5..87d221d 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -59,6 +59,7 @@ from .compilers import ( IntelFortranCompiler, JavaCompiler, MonoCompiler, + CudaCompiler, VisualStudioCsCompiler, NAGFortranCompiler, Open64FortranCompiler, @@ -99,6 +100,17 @@ known_cpu_families = ( 'x86_64' ) +# Environment variables that each lang uses. +cflags_mapping = {'c': 'CFLAGS', + 'cpp': 'CXXFLAGS', + 'cu': 'CUFLAGS', + 'objc': 'OBJCFLAGS', + 'objcpp': 'OBJCXXFLAGS', + 'fortran': 'FFLAGS', + 'd': 'DFLAGS', + 'vala': 'VALAFLAGS'} + + def detect_gcovr(version='3.1', log=False): gcovr_exe = 'gcovr' try: @@ -410,6 +422,7 @@ class Environment: self.default_d = ['ldc2', 'ldc', 'gdc', 'dmd'] self.default_fortran = ['gfortran', 'g95', 'f95', 'f90', 'f77', 'ifort', 'pgfortran'] self.default_java = ['javac'] + self.default_cuda = ['nvcc'] self.default_rust = ['rustc'] self.default_swift = ['swiftc'] self.default_vala = ['valac'] @@ -417,6 +430,7 @@ class Environment: self.default_strip = ['strip'] self.vs_static_linker = ['lib'] self.clang_cl_static_linker = ['llvm-lib'] + self.cuda_static_linker = ['nvlink'] self.gcc_static_linker = ['gcc-ar'] self.clang_static_linker = ['llvm-ar'] self.default_pkgconfig = ['pkg-config'] @@ -737,6 +751,25 @@ class Environment: def detect_cpp_compiler(self, want_cross): return self._detect_c_or_cpp_compiler('cpp', want_cross) + def detect_cuda_compiler(self, want_cross): + popen_exceptions = {} + compilers, ccache, is_cross, exe_wrap = self._get_compilers('cuda', 'Cuda', want_cross) + for compiler in compilers: + if isinstance(compiler, str): + compiler = [compiler] + else: + raise EnvironmentException() + arg = '--version' + try: + p, out, err = Popen_safe(compiler + [arg]) + except OSError as e: + popen_exceptions[' '.join(compiler + [arg])] = e + continue + version = search_version(out) + cls = CudaCompiler + return cls(ccache + compiler, version, is_cross, exe_wrap) + raise EnvironmentException('Could not find suitable CUDA compiler: "' + ' '.join(compilers) + '"') + def detect_fortran_compiler(self, want_cross): popen_exceptions = {} compilers, ccache, is_cross, exe_wrap = self._get_compilers('fortran', want_cross) @@ -999,6 +1032,10 @@ class Environment: comp = self.detect_objc_compiler(False) if need_cross_compiler: cross_comp = self.detect_objc_compiler(True) + elif lang == 'cuda': + comp = self.environment.detect_cuda_compiler(False) + if need_cross_compiler: + cross_comp = self.environment.detect_cuda_compiler(True) elif lang == 'objcpp': comp = self.detect_objcpp_compiler(False) if need_cross_compiler: @@ -1057,7 +1094,12 @@ class Environment: if linker is not None: linkers = [linker] else: - if isinstance(compiler, compilers.VisualStudioCCompiler): + evar = 'AR' + if isinstance(compiler, compilers.CudaCompiler): + linkers = [self.cuda_static_linker, self.default_static_linker] + elif evar in os.environ: + linkers = [shlex.split(os.environ[evar])] + elif isinstance(compiler, compilers.VisualStudioCCompiler): linkers = [self.vs_static_linker, self.clang_cl_static_linker] elif isinstance(compiler, compilers.GnuCompiler): # Use gcc-ar if available; needed for LTO |