Skip to content

Instantly share code, notes, and snippets.

@AbigailBuccaneer
Created January 20, 2016 16:57
Show Gist options
  • Save AbigailBuccaneer/45b7c0043fd94edf11bd to your computer and use it in GitHub Desktop.
Save AbigailBuccaneer/45b7c0043fd94edf11bd to your computer and use it in GitHub Desktop.
import os.path
import re
import subprocess
import SCons.Action
from SCons.Tool import cc
def detect_version(env, clang):
clang = env.subst(clang)
if not clang:
return None
version = None
pipe = SCons.Action._subproc(env, SCons.Util.CLVar(clang) + ['--version'],
stdin='devnull',
stderr='devnull',
stdout=subprocess.PIPE)
line = pipe.stdout.readline()
match = re.search(r'version ([^\s])', line)
if match:
version = match.group(0)
while pipe.stdout.readline():
pass
ret = pipe.wait()
if ret != 0:
return None
return version
def generate(env):
if 'CC' not in env:
env['CC'] = env.Detect('clang')
if 'CXX' not in env:
env['CXX'] = env.Detect('clang++')
cc.generate(env)
env['CCVERSION'] = detect_version(env, env.subst('$CC'))
env['CXXVERSION'] = detect_version(env, env.subst('$CXX'))
def exists(env):
return env.Detect('clang')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment