Skip to content

Instantly share code, notes, and snippets.

@mortoray
Created August 6, 2017 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortoray/0c7485fa04afb8f4db099132e7b1e723 to your computer and use it in GitHub Desktop.
Save mortoray/0c7485fa04afb8f4db099132e7b1e723 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import os
import subprocess
setupConfFile = 'setup.conf'
vars = Variables(setupConfFile)
vars.AddVariables(
PathVariable('BOOST_PREFIX','Where boost was installed', '/usr/' ),
PathVariable('BUILD_DIR','Intermediate build directory', 'build', PathVariable.PathIsDirCreate),
PathVariable('DIST_DIR','Redistributable package directory', 'dist', PathVariable.PathIsDirCreate),
PathVariable('LLVM_DIR','Where LLVM is installed', '/opt/llvm/install' ),
PathVariable('GMP_DIR','Where GMP is installed', '/usr/' ),
EnumVariable('BUILD_TYPE','Optimization/debug build type',
allowed_values=('release','debug'), default='release' )
)
baseEnv = Environment(
variables = vars,
BUILD_LIB='$BUILD_DIR/lib',
LIBPATH=['$BUILD_DIR/lib','$BOOST_PREFIX/lib'],
# there are some generated includes so include both source include and build include
CPPPATH=['#include', 'include'],
tools=['default','textfile'],
)
#print baseEnv.Dump()
baseEnv['ABS_BUILD_DIR']=os.path.join(os.getcwd(),baseEnv['BUILD_DIR'])
baseEnv["IS_DARWIN"] = baseEnv['PLATFORM'] == "darwin"
if baseEnv["IS_DARWIN"]:
baseEnv.Append(CPPDEFINES = '-DIS_DARWIN')
baseEnv["IS_POSIX"] = baseEnv['PLATFORM'] == "posix"
if baseEnv["IS_POSIX"]:
baseEnv.Append(CPPDEFINES = '-DIS_POSIX')
# Make assumption that it's linux, the only one we support now
baseEnv["IS_LINUX"] = baseEnv['IS_POSIX']
if baseEnv['IS_LINUX']:
baseEnv.Append(CPPDEFINES = '-DIS_LINUX')
# setup compiler flags
if baseEnv['BUILD_TYPE'] == 'release':
baseEnv.Append(CXXFLAGS = ['-O3', '-g3', '-ggdb3'])
else:
baseEnv.Append(CXXFLAGS = ['-g3', '-ggdb3'])
# expose basic flags in case building foreign code
baseEnv['BASE_CXXFLAGS'] = baseEnv['CXXFLAGS']
# our own code has stricter requirements
baseEnv.Append(CXXFLAGS = ['-Wall', '-Wconversion','-Wextra',
'-Wno-sign-conversion', # This is just a pain with enums
'-Wno-unused-private-field' #these should probably be fixed in our code
])
# TODO: add -Wsuggset-override above (lots of work)
if baseEnv['IS_DARWIN']:
baseEnv.Append(CXXFLAGS = ['-Wno-potentially-evaluated-expression', #potential compiler bug?
'-Wno-inconsistent-missing-override', #we'll get to this eventually
])
# do it here rather than CPPPATH to suppress warnings on system file
baseEnv.Append(CXXFLAGS = ['-isystem','$BOOST_PREFIX/include'])
# Enable C++11 mode
baseEnv.Append(CXXFLAGS = ['-std=c++11'] )
# Prevent unknowns to avoid surprises
unknown = vars.UnknownVariables()
if unknown:
print "Unknown variables:", unknown.keys()
Exit(1)
Help(vars.GenerateHelpText(baseEnv))
# setup libraries
conf = Configure(baseEnv)
libs = ['boost_unit_test_framework','boost_program_options']
if baseEnv["IS_POSIX"]:
libs.extend( ['rt','dl'] )
for lib in libs:
if not conf.CheckLib(lib):
Exit(1)
baseEnv = conf.Finish()
# It doesn't save variables which match the default!!!
#SCONS: http://scons.tigris.org/issues/show_bug.cgi?id=2827
vars.Save(setupConfFile,baseEnv)
# used to call unit test programs
def call_unit_test(target, source, env):
app = str(source[0].abspath)
test_env = {
'LD_LIBRARY_PATH': ':'.join( env.subst( env['LIBPATH'] ) ),
'LEAF_PATH': '$ABS_BUILD_DIR',
}
if subprocess.call([app], env=test_env) == 0:
open(str(target[0]),'w').write("PASSED\n")
else:
return 1
# Adds the target as something that should be executed during a 'check' build
# The target is placed in the '.check' directory to prevent it from being built
# by default. All targets are then aliased to 'check' so a 'scons check' will do
# the check build.
def add_unit_test( env, node, alias = 'check' ):
test_target = '#/.check/' + node[0].path
test_node = env.Command( test_target, node, call_unit_test )
env.Alias( alias, test_node )
env.AlwaysBuild( test_node )
baseEnv.AddMethod( add_unit_test, 'AddUnitTest' )
baseEnv.Clean([], '#/.check/' )
# Call the ohter build files
Export('baseEnv')
#baseEnv.VariantDir(baseEnv['BUILD_DIR'],'src',duplicate=0)
baseEnv.SConscript('src/SConscript', variant_dir=baseEnv['BUILD_DIR'], duplicate=0)
#baseEnv.VariantDir(baseEnv['DIST_DIR'], 'package', duplicate=0)
baseEnv.SConscript('package/SConscript', variant_dir=baseEnv['DIST_DIR'], duplicate =0)
# Only things in build directory get built, this excludes the .test directory
Default(baseEnv['BUILD_DIR'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment