summaryrefslogtreecommitdiff
path: root/lib/spack/spack/compilers/cce.py
blob: e9377a0bb1bab778620353c0055d1d6f7c497b37 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os

from spack.compiler import Compiler, UnsupportedCompilerFlag
from spack.version import Version


class Cce(Compiler):
    """Cray compiler environment compiler."""

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # For old cray compilers on module based systems we replace
        # ``version_argument`` with the old value. Cannot be a property
        # as the new value is used in classmethods for path-based detection
        if not self.is_clang_based:
            self.version_argument = "-V"

    # Subclasses use possible names of C compiler
    cc_names = ["craycc"]

    # Subclasses use possible names of C++ compiler
    cxx_names = ["crayCC"]

    # Subclasses use possible names of Fortran 77 compiler
    f77_names = ["crayftn"]

    # Subclasses use possible names of Fortran 90 compiler
    fc_names = ["crayftn"]

    # MacPorts builds gcc versions with prefixes and -mp-X.Y suffixes.
    suffixes = [r"-mp-\d\.\d"]

    PrgEnv = "PrgEnv-cray"
    PrgEnv_compiler = "cce"

    @property
    def link_paths(self):
        if any(self.PrgEnv in m for m in self.modules):
            # Old module-based interface to cray compilers
            return {
                "cc": os.path.join("cce", "cc"),
                "cxx": os.path.join("case-insensitive", "CC"),
                "f77": os.path.join("cce", "ftn"),
                "fc": os.path.join("cce", "ftn"),
            }

        return {
            "cc": os.path.join("cce", "craycc"),
            "cxx": os.path.join("cce", "case-insensitive", "crayCC"),
            "f77": os.path.join("cce", "crayftn"),
            "fc": os.path.join("cce", "crayftn"),
        }

    @property
    def is_clang_based(self):
        version = self._real_version or self.version
        return version >= Version("9.0") and "classic" not in str(version)

    version_argument = "--version"
    version_regex = r"[Cc]ray (?:clang|C :|C\+\+ :|Fortran :) [Vv]ersion.*?(\d+(\.\d+)+)"

    @property
    def verbose_flag(self):
        return "-v"

    @property
    def debug_flags(self):
        return ["-g", "-G0", "-G1", "-G2", "-Gfast"]

    @property
    def openmp_flag(self):
        if self.is_clang_based:
            return "-fopenmp"
        return "-h omp"

    @property
    def cxx11_flag(self):
        if self.is_clang_based:
            return "-std=c++11"
        return "-h std=c++11"

    @property
    def cxx14_flag(self):
        if self.is_clang_based:
            return "-std=c++14"
        return "-h std=c++14"

    @property
    def cxx17_flag(self):
        if self.is_clang_based:
            return "-std=c++17"

    @property
    def c99_flag(self):
        if self.is_clang_based:
            return "-std=c99"
        elif self.real_version >= Version("8.4"):
            return "-h std=c99,noconform,gnu"
        elif self.real_version >= Version("8.1"):
            return "-h c99,noconform,gnu"
        raise UnsupportedCompilerFlag(self, "the C99 standard", "c99_flag", "< 8.1")

    @property
    def c11_flag(self):
        if self.is_clang_based:
            return "-std=c11"
        elif self.real_version >= Version("8.5"):
            return "-h std=c11,noconform,gnu"
        raise UnsupportedCompilerFlag(self, "the C11 standard", "c11_flag", "< 8.5")

    @property
    def cc_pic_flag(self):
        if self.is_clang_based:
            return "-fPIC"
        return "-h PIC"

    @property
    def cxx_pic_flag(self):
        if self.is_clang_based:
            return "-fPIC"
        return "-h PIC"

    @property
    def f77_pic_flag(self):
        if self.is_clang_based:
            return "-fPIC"
        return "-h PIC"

    @property
    def fc_pic_flag(self):
        if self.is_clang_based:
            return "-fPIC"
        return "-h PIC"

    @property
    def stdcxx_libs(self):
        # Cray compiler wrappers link to the standard C++ library
        # without additional flags.
        return ()