renamed SCons.Tool.ninja -> SCons.Tool.ninja_tool and added alias in tool loading...
[scons.git] / SCons / Tool / clang.py
blob3b9488f9e1bcfafa35c0418356d3835cd8f99261
1 # MIT License
3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 """Tool-specific initialization for clang.
26 There normally shouldn't be any need to import this module directly.
27 It will usually be imported through the generic SCons.Tool.Tool()
28 selection method.
29 """
31 # Based on SCons/Tool/gcc.py by Paweł Tomulik 2014 as a separate tool.
32 # Brought into the SCons mainline by Russel Winder 2017.
34 import os
35 import re
36 from subprocess import DEVNULL, PIPE
38 import SCons.Util
39 import SCons.Tool.cc
40 from SCons.Tool.clangCommon import get_clang_install_dirs
41 from SCons.Tool.MSCommon import msvc_setup_env_once
44 compilers = ['clang']
47 def generate(env) -> None:
48 """Add Builders and construction variables for clang to an Environment."""
49 SCons.Tool.cc.generate(env)
51 if env['PLATFORM'] == 'win32':
52 # Ensure that we have a proper path for clang
53 clang = SCons.Tool.find_program_path(
54 env, compilers[0], default_paths=get_clang_install_dirs(env['PLATFORM'])
56 if clang:
57 clang_bin_dir = os.path.dirname(clang)
58 env.AppendENVPath("PATH", clang_bin_dir)
60 # Set-up ms tools paths
61 msvc_setup_env_once(env)
63 env['CC'] = env.Detect(compilers) or 'clang'
64 if env['PLATFORM'] in ['cygwin', 'win32']:
65 env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
66 else:
67 env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS -fPIC')
69 # determine compiler version
70 if env['CC']:
71 kw = {
72 'stdout': PIPE,
73 'stderr': DEVNULL,
74 'universal_newlines': True,
76 cp = SCons.Action.scons_subproc_run(env, [env['CC'], '-dumpversion'], **kw)
77 line = cp.stdout
78 if line:
79 env['CCVERSION'] = line
81 env['CCDEPFLAGS'] = '-MMD -MF ${TARGET}.d'
82 env["NINJA_DEPFILE_PARSE_FORMAT"] = 'clang'
84 def exists(env):
85 return env.Detect(compilers)
87 # Local Variables:
88 # tab-width:4
89 # indent-tabs-mode:nil
90 # End:
91 # vim: set expandtab tabstop=4 shiftwidth=4: