summaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-11-12 10:13:36 -0800
committerDylan Baker <dylan@pnwbakers.com>2025-11-19 10:48:48 -0800
commitdf0139510791507181051d865472833f5fc2b442 (patch)
tree5bbfa7b60ab529b5fcd4b6dc7c70f743e01b7512 /mesonbuild
parent0e6fd84db2299b45d9abbe42cb461fa7e49b27c3 (diff)
downloadmeson-df0139510791507181051d865472833f5fc2b442.tar.gz
compilers: Remove Environment parameter from Compiler.openmp_flags
I've done the compile and link flags in one commit since they're so closely related
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/compilers/compilers.py6
-rw-r--r--mesonbuild/compilers/fortran.py8
-rw-r--r--mesonbuild/compilers/mixins/apple.py15
-rw-r--r--mesonbuild/compilers/mixins/clang.py2
-rw-r--r--mesonbuild/compilers/mixins/elbrus.py2
-rw-r--r--mesonbuild/compilers/mixins/gnu.py4
-rw-r--r--mesonbuild/compilers/mixins/intel.py7
-rw-r--r--mesonbuild/compilers/mixins/microchip.py4
-rw-r--r--mesonbuild/compilers/mixins/pgi.py2
-rw-r--r--mesonbuild/compilers/mixins/visualstudio.py10
-rw-r--r--mesonbuild/dependencies/misc.py8
-rw-r--r--mesonbuild/linkers/linkers.py2
12 files changed, 31 insertions, 39 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 929274ae4..046c5b157 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -970,11 +970,11 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
def thread_link_flags(self, env: 'Environment') -> T.List[str]:
return self.linker.thread_flags(env)
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
raise EnvironmentException('Language %s does not support OpenMP flags.' % self.get_display_language())
- def openmp_link_flags(self, env: Environment) -> T.List[str]:
- return self.openmp_flags(env)
+ def openmp_link_flags(self) -> T.List[str]:
+ return self.openmp_flags()
def language_stdlib_only_link_flags(self) -> T.List[str]:
return []
diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py
index 3668f24a0..d643e4469 100644
--- a/mesonbuild/compilers/fortran.py
+++ b/mesonbuild/compilers/fortran.py
@@ -383,7 +383,7 @@ class SunFortranCompiler(FortranCompiler):
def get_module_outdir_args(self, path: str) -> T.List[str]:
return ['-moddir=' + path]
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
return ['-xopenmp']
@@ -506,7 +506,7 @@ class PathScaleFortranCompiler(FortranCompiler):
'3': default_warn_args,
'everything': default_warn_args}
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
return ['-mp']
@@ -654,7 +654,7 @@ class Open64FortranCompiler(FortranCompiler):
'3': default_warn_args,
'everything': default_warn_args}
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
return ['-mp']
@@ -695,5 +695,5 @@ class NAGFortranCompiler(FortranCompiler):
def get_std_exe_link_args(self) -> T.List[str]:
return self.get_always_args()
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
return ['-openmp']
diff --git a/mesonbuild/compilers/mixins/apple.py b/mesonbuild/compilers/mixins/apple.py
index a66c682a9..02aab0d12 100644
--- a/mesonbuild/compilers/mixins/apple.py
+++ b/mesonbuild/compilers/mixins/apple.py
@@ -10,7 +10,6 @@ from ...mesonlib import MesonException
if T.TYPE_CHECKING:
from ..._typing import ImmutableListProtocol
- from ...environment import Environment
from ...envconfig import MachineInfo
from ..compilers import Compiler
else:
@@ -31,7 +30,7 @@ class AppleCompilerMixin(Compiler):
# Older versions of mypy can't figure this out
info: MachineInfo
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
"""Flags required to compile with OpenMP on Apple.
The Apple Clang Compiler doesn't have builtin support for OpenMP, it
@@ -40,23 +39,19 @@ class AppleCompilerMixin(Compiler):
:return: A list of arguments
"""
- m = env.machines[self.for_machine]
- assert m is not None, 'for mypy'
- if m.cpu_family.startswith('x86'):
+ if self.info.cpu_family.startswith('x86'):
root = '/usr/local'
else:
root = '/opt/homebrew'
return self.__BASE_OMP_FLAGS + [f'-I{root}/opt/libomp/include']
- def openmp_link_flags(self, env: Environment) -> T.List[str]:
- m = env.machines[self.for_machine]
- assert m is not None, 'for mypy'
- if m.cpu_family.startswith('x86'):
+ def openmp_link_flags(self) -> T.List[str]:
+ if self.info.cpu_family.startswith('x86'):
root = '/usr/local'
else:
root = '/opt/homebrew'
- link = self.find_library('omp', env, [f'{root}/opt/libomp/lib'])
+ link = self.find_library('omp', self.environment, [f'{root}/opt/libomp/lib'])
if not link:
raise MesonException("Couldn't find libomp")
return self.__BASE_OMP_FLAGS + link
diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py
index 5c3310062..a09dfe51f 100644
--- a/mesonbuild/compilers/mixins/clang.py
+++ b/mesonbuild/compilers/mixins/clang.py
@@ -164,7 +164,7 @@ class ClangCompiler(GnuLikeCompiler):
return super().has_function(funcname, prefix, env, extra_args=extra_args,
dependencies=dependencies)
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
if mesonlib.version_compare(self.version, '>=3.8.0'):
return ['-fopenmp']
elif mesonlib.version_compare(self.version, '>=3.7.0'):
diff --git a/mesonbuild/compilers/mixins/elbrus.py b/mesonbuild/compilers/mixins/elbrus.py
index 978a565ed..800f20a97 100644
--- a/mesonbuild/compilers/mixins/elbrus.py
+++ b/mesonbuild/compilers/mixins/elbrus.py
@@ -95,5 +95,5 @@ class ElbrusCompiler(GnuLikeCompiler):
args.append('-std=' + std)
return args
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
return ['-fopenmp']
diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py
index 6a6f48606..54ea3ef9b 100644
--- a/mesonbuild/compilers/mixins/gnu.py
+++ b/mesonbuild/compilers/mixins/gnu.py
@@ -402,7 +402,7 @@ class GnuLikeCompiler(Compiler, metaclass=abc.ABCMeta):
return gnulike_default_include_dirs(tuple(self.get_exelist(ccache=False)), self.language).copy()
@abc.abstractmethod
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
pass
def gnu_symbol_visibility_args(self, vistype: str) -> T.List[str]:
@@ -599,7 +599,7 @@ class GnuCompiler(GnuLikeCompiler):
def get_pch_suffix(self) -> str:
return 'gch'
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
return ['-fopenmp']
def has_arguments(self, args: T.List[str], env: 'Environment', code: str,
diff --git a/mesonbuild/compilers/mixins/intel.py b/mesonbuild/compilers/mixins/intel.py
index 32cbdf010..5391c842a 100644
--- a/mesonbuild/compilers/mixins/intel.py
+++ b/mesonbuild/compilers/mixins/intel.py
@@ -20,9 +20,6 @@ from .gnu import GnuLikeCompiler
from .visualstudio import VisualStudioLikeCompiler
from ...options import OptionKey
-if T.TYPE_CHECKING:
- from ...environment import Environment
-
# XXX: avoid circular dependencies
# TODO: this belongs in a posix compiler class
# NOTE: the default Intel optimization is -O2, unlike GNU which defaults to -O0.
@@ -82,7 +79,7 @@ class IntelGnuLikeCompiler(GnuLikeCompiler):
def get_pch_name(self, name: str) -> str:
return os.path.basename(name) + '.' + self.get_pch_suffix()
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
if mesonlib.version_compare(self.version, '>=15.0.0'):
return ['-qopenmp']
else:
@@ -158,7 +155,7 @@ class IntelVisualStudioLikeCompiler(VisualStudioLikeCompiler):
version = int(v1 + v2)
return self._calculate_toolset_version(version)
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
return ['/Qopenmp']
def get_debug_args(self, is_debug: bool) -> T.List[str]:
diff --git a/mesonbuild/compilers/mixins/microchip.py b/mesonbuild/compilers/mixins/microchip.py
index 0dc7618a2..14ebb4cf8 100644
--- a/mesonbuild/compilers/mixins/microchip.py
+++ b/mesonbuild/compilers/mixins/microchip.py
@@ -138,8 +138,8 @@ class Xc32Compiler(CompilerBase):
def thread_flags(self, env: Environment) -> T.List[str]:
return []
- def openmp_flags(self, env: Environment) -> T.List[str]:
- return Compiler.openmp_flags(self, env)
+ def openmp_flags(self) -> T.List[str]:
+ return Compiler.openmp_flags(self)
def get_pic_args(self) -> T.List[str]:
return Compiler.get_pic_args(self)
diff --git a/mesonbuild/compilers/mixins/pgi.py b/mesonbuild/compilers/mixins/pgi.py
index fddc8378f..92a995b70 100644
--- a/mesonbuild/compilers/mixins/pgi.py
+++ b/mesonbuild/compilers/mixins/pgi.py
@@ -51,7 +51,7 @@ class PGICompiler(Compiler):
return ['-fPIC']
return []
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
return ['-mp']
def get_preprocess_only_args(self) -> T.List[str]:
diff --git a/mesonbuild/compilers/mixins/visualstudio.py b/mesonbuild/compilers/mixins/visualstudio.py
index 02727fb7a..9ed35bd1b 100644
--- a/mesonbuild/compilers/mixins/visualstudio.py
+++ b/mesonbuild/compilers/mixins/visualstudio.py
@@ -204,10 +204,10 @@ class VisualStudioLikeCompiler(Compiler, metaclass=abc.ABCMeta):
objname = os.path.splitext(source)[0] + '.obj'
return objname, ['/Yc' + header, '/Fp' + pchname, '/Fo' + objname]
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
return ['/openmp']
- def openmp_link_flags(self, env: Environment) -> T.List[str]:
+ def openmp_link_flags(self) -> T.List[str]:
return []
# FIXME, no idea what these should be.
@@ -493,12 +493,12 @@ class ClangClCompiler(VisualStudioLikeCompiler):
else:
return dep.get_compile_args()
- def openmp_link_flags(self, env: Environment) -> T.List[str]:
+ def openmp_link_flags(self) -> T.List[str]:
# see https://github.com/mesonbuild/meson/issues/5298
- libs = self.find_library('libomp', env, [])
+ libs = self.find_library('libomp', self.environment, [])
if libs is None:
raise mesonlib.MesonBugException('Could not find libomp')
- return super().openmp_link_flags(env) + libs
+ return super().openmp_link_flags() + libs
def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.List[str]:
args: T.List[str] = []
diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py
index 74326827c..0e55ad620 100644
--- a/mesonbuild/dependencies/misc.py
+++ b/mesonbuild/dependencies/misc.py
@@ -121,19 +121,19 @@ class OpenMPDependency(SystemDependency):
# No macro defined for OpenMP, but OpenMP 3.1 is supported.
self.version = '3.1'
self.is_found = True
- self.compile_args = self.link_args = self.clib_compiler.openmp_flags(environment)
+ self.compile_args = self.link_args = self.clib_compiler.openmp_flags()
return
if self.clib_compiler.get_id() == 'pgi':
# through at least PGI 19.4, there is no macro defined for OpenMP, but OpenMP 3.1 is supported.
self.version = '3.1'
self.is_found = True
- self.compile_args = self.link_args = self.clib_compiler.openmp_flags(environment)
+ self.compile_args = self.link_args = self.clib_compiler.openmp_flags()
return
# Set these now so they're available for the following compiler checks
try:
- self.compile_args.extend(self.clib_compiler.openmp_flags(environment))
- self.link_args.extend(self.clib_compiler.openmp_link_flags(environment))
+ self.compile_args.extend(self.clib_compiler.openmp_flags())
+ self.link_args.extend(self.clib_compiler.openmp_link_flags())
except mesonlib.MesonException as e:
mlog.warning('OpenMP support not available because:', str(e), fatal=False)
return
diff --git a/mesonbuild/linkers/linkers.py b/mesonbuild/linkers/linkers.py
index c43c9d59f..bb4b2f7dc 100644
--- a/mesonbuild/linkers/linkers.py
+++ b/mesonbuild/linkers/linkers.py
@@ -73,7 +73,7 @@ class StaticLinker:
def thread_link_flags(self, env: 'Environment') -> T.List[str]:
return []
- def openmp_flags(self, env: Environment) -> T.List[str]:
+ def openmp_flags(self) -> T.List[str]:
return []
def get_option_link_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: