aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/dependencies/coarrays.py
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild/dependencies/coarrays.py')
-rw-r--r--mesonbuild/dependencies/coarrays.py78
1 files changed, 40 insertions, 38 deletions
diff --git a/mesonbuild/dependencies/coarrays.py b/mesonbuild/dependencies/coarrays.py
index 7f0b30e..84c3412 100644
--- a/mesonbuild/dependencies/coarrays.py
+++ b/mesonbuild/dependencies/coarrays.py
@@ -12,8 +12,39 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from ..mesonlib import listify
-from .base import CMakeDependency, DependencyMethods, ExternalDependency, PkgConfigDependency
+import functools
+import typing as T
+
+from .base import CMakeDependency, DependencyMethods, ExternalDependency, PkgConfigDependency, detect_compiler, factory_methods
+
+if T.TYPE_CHECKING:
+ from . base import DependencyType
+ from ..environment import Environment, MachineChoice
+
+
+@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CMAKE, DependencyMethods.SYSTEM})
+def coarray_factory(env: 'Environment', for_machine: 'MachineChoice',
+ kwargs: T.Dict[str, T.Any], methods: T.List[DependencyMethods]) -> T.List['DependencyType']:
+ fcid = detect_compiler('coarray', env, for_machine, 'fortran').get_id()
+ candidates = [] # type: T.List[DependencyType]
+
+ if fcid == 'gcc':
+ # OpenCoarrays is the most commonly used method for Fortran Coarray with GCC
+ if DependencyMethods.PKGCONFIG in methods:
+ for pkg in ['caf-openmpi', 'caf']:
+ candidates.append(functools.partial(
+ PkgConfigDependency, pkg, env, kwargs, language='fortran'))
+
+ if DependencyMethods.CMAKE in methods:
+ if 'modules' not in kwargs:
+ kwargs['modules'] = 'OpenCoarrays::caf_mpi'
+ candidates.append(functools.partial(
+ CMakeDependency, 'OpenCoarrays', env, kwargs, language='fortran'))
+
+ if DependencyMethods.SYSTEM in methods:
+ candidates.append(functools.partial(CoarrayDependency, env, kwargs))
+
+ return candidates
class CoarrayDependency(ExternalDependency):
@@ -29,53 +60,24 @@ class CoarrayDependency(ExternalDependency):
super().__init__('coarray', environment, kwargs, language='fortran')
kwargs['required'] = False
kwargs['silent'] = True
- self.is_found = False
- methods = listify(self.methods)
cid = self.get_compiler().get_id()
if cid == 'gcc':
- """ OpenCoarrays is the most commonly used method for Fortran Coarray with GCC """
-
- if set([DependencyMethods.AUTO, DependencyMethods.PKGCONFIG]).intersection(methods):
- for pkg in ['caf-openmpi', 'caf']:
- pkgdep = PkgConfigDependency(pkg, environment, kwargs, language=self.language)
- if pkgdep.found():
- self.compile_args = pkgdep.get_compile_args()
- self.link_args = pkgdep.get_link_args()
- self.version = pkgdep.get_version()
- self.is_found = True
- self.pcdep = pkgdep
- return
-
- if set([DependencyMethods.AUTO, DependencyMethods.CMAKE]).intersection(methods):
- if not kwargs.get('modules'):
- kwargs['modules'] = 'OpenCoarrays::caf_mpi'
- cmakedep = CMakeDependency('OpenCoarrays', environment, kwargs, language=self.language)
- if cmakedep.found():
- self.compile_args = cmakedep.get_compile_args()
- self.link_args = cmakedep.get_link_args()
- self.version = cmakedep.get_version()
- self.is_found = True
- return
-
- if DependencyMethods.AUTO in methods:
- # fallback to single image
- self.compile_args = ['-fcoarray=single']
- self.version = 'single image (fallback)'
- self.is_found = True
- return
-
+ # Fallback to single image
+ self.compile_args = ['-fcoarray=single']
+ self.version = 'single image (fallback)'
+ self.is_found = True
elif cid == 'intel':
- """ Coarrays are built into Intel compilers, no external library needed """
+ # Coarrays are built into Intel compilers, no external library needed
self.is_found = True
self.link_args = ['-coarray=shared']
self.compile_args = self.link_args
elif cid == 'intel-cl':
- """ Coarrays are built into Intel compilers, no external library needed """
+ # Coarrays are built into Intel compilers, no external library needed
self.is_found = True
self.compile_args = ['/Qcoarray:shared']
elif cid == 'nagfor':
- """ NAG doesn't require any special arguments for Coarray """
+ # NAG doesn't require any special arguments for Coarray
self.is_found = True
@staticmethod