Source

gpalign-cpp / SConstruct

Full commit
# -*- coding: utf-8 -*-
#----------------------------------------------------------------------------#
# SConstruct
# Lars Yencken <lars.yencken@gmail.com>
# vim: ts=4 sw=4 sts=4 et tw=78:
# Thu Nov 30 15:23:25 2006
#
#----------------------------------------------------------------------------#

""" Build instructions for the research codebase.
"""

#----------------------------------------------------------------------------#

import os
from os import path
import sys
from distutils import sysconfig
import py_compile
import re

#----------------------------------------------------------------------------#

debugMode = bool(ARGUMENTS.get('debug'))
multiThreadedMode = not bool(ARGUMENTS.get('nomt'))
profileMode = bool(ARGUMENTS.get('profile'))

def checkLibraries(env):
    """ Check whether the correct libraries exist, and thus whether building
        is possible.
    """
    # Some platform-specific customisations.
    platform = os.uname()[0].lower()
    if platform.endswith('bsd') or platform == 'darwin':
        env.Append(CXXFLAGS='-DBSD ')

    if platform == 'darwin':
        # Extra build parameters for OS X 
        env.Replace(SHLINKFLAGS='$LINKFLAGS -bundle -flat_namespace -undefined suppress')
        env.Replace(SHLIBSUFFIX='.so')

    print 'Configuring for platform: %s' % platform

    # Detect the presence of necessary dependencies.
    conf = Configure(env)

    if not conf.CheckLibWithHeader('m', 'math.h', 'c'):
        print "Can't find standard math libraries."
        Exit(1)

    if multiThreadedMode:
        if not conf.CheckLib('pthread'):
            print "Can't find pthread."
            Exit(1)

        if not conf.CheckLib('gomp'):
            print "Can't find gomp."
            Exit(1)

    if not conf.CheckLibWithHeader('cppunit', 'cppunit/ui/text/TestRunner.h',
            'c++'):
        print "Can't find cppunit."
        Exit(1)

    if not conf.CheckCXXHeader('boost/shared_ptr.hpp'):
        print "Can't find boost C++ libraries."
        Exit(1)

    env = conf.Finish()
    return env

#----------------------------------------------------------------------------#
# CONFIGURATION
#----------------------------------------------------------------------------#

# Set up the compilation environment.
env = Environment()

environmentVars = (
        'CPATH',
        'LD_LIBRARY_PATH',
        'LIBRARY_PATH',
    )

envDict = env['ENV']
for var in environmentVars:
    if var in os.environ:
        envDict[var] = os.environ[var]

if profileMode:
    print 'Using profiling targets'
    env.Append(DEBUG=True, CXXFLAGS='-O0 -g -pg -Wall', LINKFLAGS='-g -pg')
elif debugMode:
    print 'Using debugging targets'
    env.Append(DEBUG=True, CXXFLAGS='-O0 -g -Wall ', LINKFLAGS='-g')
else:
    print 'Using optimised targets'
    env.Append(DEBUG=False, CXXFLAGS='-O3 -DNDEBUG -Wall ')
    

if multiThreadedMode:
    print 'Multi-threaded mode'
    env.Append(CXXFLAGS='-fopenmp ')
else:
    print 'Single-threaded mode'
    env.Append(CXXFLAGS='-DNOMT')

# Configure the environment.
env = checkLibraries(env)

#----------------------------------------------------------------------------#

SConscript('src/SConscript', exports='env')
SConscript('src/tests/SConscript', exports='env')

#----------------------------------------------------------------------------#