Commit a2fe35bc authored by Jose Fonseca's avatar Jose Fonseca

scons: Support Clang on Windows.

- Introduce 'gcc_compat' env flag, for all compilers that define __GNUC__,
  (which includes Clang when it's not emulating MSVC.)

- Clang doesn't support whole program optimization

- Disable enumerator value warnings (not sure why Clang warns about them,
  as my understanding is that MSVC promotes enums to unsigned ints
  automatically.)

This is not enough to build with Clang + AddressSanitizer though.  More
follow up changes will be required for that.
Reviewed-by: default avatarRoland Scheidegger <sroland@vmware.com>
Reviewed-by: Brian Paul's avatarBrian Paul <brianp@vmware.com>
parent dcc3baf7
......@@ -183,14 +183,15 @@ def generate(env):
# Detect gcc/clang not by executable name, but through pre-defined macros
# as autoconf does, to avoid drawing wrong conclusions when using tools
# that overrice CC/CXX like scan-build.
env['gcc'] = 0
env['gcc_compat'] = 0
env['clang'] = 0
env['msvc'] = 0
if host_platform.system() == 'Windows':
env['msvc'] = check_cc(env, 'MSVC', 'defined(_MSC_VER)', '/E')
if not env['msvc']:
env['gcc'] = check_cc(env, 'GCC', 'defined(__GNUC__) && !defined(__clang__)')
env['clang'] = check_cc(env, 'Clang', '__clang__')
env['gcc_compat'] = check_cc(env, 'GCC', 'defined(__GNUC__)')
env['clang'] = check_cc(env, 'Clang', '__clang__')
env['gcc'] = env['gcc_compat'] and not env['clang']
env['suncc'] = env['platform'] == 'sunos' and os.path.basename(env['CC']) == 'cc'
env['icc'] = 'icc' == os.path.basename(env['CC'])
......@@ -203,7 +204,7 @@ def generate(env):
platform = env['platform']
x86 = env['machine'] == 'x86'
ppc = env['machine'] == 'ppc'
gcc_compat = env['gcc'] or env['clang']
gcc_compat = env['gcc_compat']
msvc = env['msvc']
suncc = env['suncc']
icc = env['icc']
......@@ -450,13 +451,13 @@ def generate(env):
'/O2', # optimize for speed
]
if env['build'] == 'release':
ccflags += [
'/GL', # enable whole program optimization
]
if not env['clang']:
ccflags += [
'/GL', # enable whole program optimization
]
else:
ccflags += [
'/Oy-', # disable frame pointer omission
'/GL-', # disable whole program optimization
]
ccflags += [
'/W3', # warning level
......@@ -470,6 +471,10 @@ def generate(env):
'/wd4800', # forcing value to bool 'true' or 'false' (performance warning)
'/wd4996', # disable deprecated POSIX name warnings
]
if env['clang']:
ccflags += [
'-Wno-microsoft-enum-value', # enumerator value is not representable in underlying type 'int'
]
if env['machine'] == 'x86':
ccflags += [
'/arch:SSE2', # use the SSE2 instructions (default since MSVC 2012)
......@@ -556,7 +561,7 @@ def generate(env):
shlinkflags += ['-Wl,--enable-stdcall-fixup']
#shlinkflags += ['-Wl,--kill-at']
if msvc:
if env['build'] == 'release':
if env['build'] == 'release' and not env['clang']:
# enable Link-time Code Generation
linkflags += ['/LTCG']
env.Append(ARFLAGS = ['/LTCG'])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment