summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Tool/icl.py
blob: d59647ce970897faed2a72b313b75af6a8aeec80 (plain)
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
"""engine.SCons.Tool.icl

Tool-specific initialization for the Intel C/C++ compiler.

There normally shouldn't be any need to import this module directly.
It will usually be imported through the generic SCons.Tool.Tool()
selection method.

"""

#
# __COPYRIGHT__
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"

import os.path
import string

import SCons.Tool.msvc
import SCons.Util
import SCons.Warnings

# Find Intel compiler:
# Could enumerate subkeys here to be more flexible.
def get_intel_compiler_top(version):
    """
    Return the main path to the top-level dir of the Intel compiler,
    using the given version or latest if 0.
    The compiler will be in <top>/Bin/icl.exe,
    the include dir is <top>/Include, etc.
    """

    if version == 0:
        version = "7.0"                   # XXX: should scan for latest

    if not SCons.Util.can_read_reg:
        raise SCons.Errors.InternalError, "No Windows registry module was found"

    K = ('Software\\Intel\\' +
         'Intel(R) C/C++ Compiler for 32-bit apps, Version ' + version)
    # Note: v5 had slightly different key:
    #  HKCU\Software\Intel\Intel C/C++ Compiler for 32-bit apps, Version 5.0
    # Note no (R).
    try:
        k = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_CURRENT_USER, K)
    except SCons.Util.RegError:
        return None

    try:
        # On my machine, this returns:
        #  c:\Program Files\Intel\Compiler70
        top = SCons.Util.RegQueryValueEx(k, "Directory")[0]
    except SCons.Util.RegError:
        raise SCons.Errors.InternalError, "%s was not found in the registry."%K

    if os.path.exists(os.path.join(top, "ia32")):
        top = os.path.join(top, "ia32")

    if not os.path.exists(os.path.join(top, "Bin", "icl.exe")):
        raise SCons.Errors.InternalError, "Can't find Intel compiler in %s"%top

    return top


def generate(env):
    """Add Builders and construction variables for icl to an Environment."""
    SCons.Tool.msvc.generate(env)

    try:
        icltop = get_intel_compiler_top(0)
    except (SCons.Util.RegError, SCons.Errors.InternalError):
        icltop = None

    if icltop:
        env.PrependENVPath('INCLUDE', os.path.join(icltop, 'Include'))
        env.PrependENVPath('LIB', os.path.join(icltop, 'Lib'))
        env.PrependENVPath('PATH', os.path.join(icltop, 'Bin'))

    env['CC']        = 'icl'
    env['CXX']        = 'icl'
    env['LINK']        = 'xilink'

    # Look for license file dir.
    envlicdir = os.environ.get("INTEL_LICENSE_FILE", '')
    K = ('SOFTWARE\Intel\Licenses')
    try:
        k = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE, K)
        reglicdir = SCons.Util.RegQueryValueEx(k, "w_cpp")[0]
    except (AttributeError, SCons.Util.RegError):
        reglicdir = ""
    defaultlicdir = r'C:\Program Files\Common Files\Intel\Licenses'

    licdir = None
    for ld in [envlicdir, reglicdir]:
        if ld and os.path.exists(ld):
            licdir = ld
            break
    if not licdir:
        licdir = defaultlicdir
        if not os.path.exists(licdir):
            class ICLLicenseDirWarning(SCons.Warnings.Warning):
                pass
            SCons.Warnings.enableWarningClass(ICLLicenseDirWarning)
            SCons.Warnings.warn(ICLLicenseDirWarning,
                                "Intel license dir was not found."
                                "  Tried using the INTEL_LICENSE_FILE environment variable (%s), the registry (%s) and the default path (%s)."
                                "  Using the default path as a last resort."
                                    % (envlicdir, reglicdir, defaultlicdir))
    env['ENV']['INTEL_LICENSE_FILE'] = licdir

def exists(env):
    try:
        top = get_intel_compiler_top(0)
    except (SCons.Util.RegError, SCons.Errors.InternalError):
        top = None

    if not top:
        return env.Detect('icl')
    return top is not None