Example #1
0
def configure(conf):
    env = conf.env

    if os.environ.has_key('FREETYPE2_INCLUDE'):
        env.AppendUnique(CPPPATH =
                         os.environ['FREETYPE2_INCLUDE'].split(os.pathsep))
    else:
        try:
            env.ParseConfig('freetype-config --cflags')
        except OSError: pass

    if os.environ.has_key('FREETYPE2_LIBPATH'):
        env.AppendUnique(LIBPATH = [os.environ['FREETYPE2_LIBPATH']])

    if env['PLATFORM'] == 'darwin':
        config.configure('osx', conf)
        if not conf.CheckOSXFramework('CoreServices'):
            raise Exception, 'Need CoreServices framework'
        if not conf.CheckOSXFramework('ApplicationServices'):
            raise Exception, 'Need ApplicationServices framework'

    config.require_header(conf, 'ft2build.h')
    config.require_lib(conf, 'freetype')

    config.check_home(conf, 'zlib', lib_suffix = '') # TODO Hack!
    config.require_lib(conf, 'z')

    return True
Example #2
0
def configure(conf):
    env = conf.env

    config.check_home(conf, 'GL')

    if env['PLATFORM'] == 'darwin':
        config.configure('osx', conf)

        if not (conf.CheckOSXFramework('OpenGL')
                and conf.CheckCHeader('OpenGL/gl.h')):
            raise Exception, 'Need OpenGL'

    else:
        if env['PLATFORM'] == 'win32':
            glulib = 'glu32'
            gllib = 'opengl32'

        else:
            glulib = 'GLU'
            gllib = 'GL'

        config.require_lib(conf, gllib)
        config.require_lib(conf, glulib)

    return True
Example #3
0
def configure(conf):
    env = conf.env

    if os.environ.has_key('OPENSSL_HOME'):
        home = os.environ['OPENSSL_HOME']
        if os.path.exists(home + '/inc32') and os.path.exists(home + '/out32'):
            env.AppendUnique(CPPPATH = [home + '/inc32'])
            env.AppendUnique(LIBPATH = [home + '/out32'])
        else:
            env.AppendUnique(CPPPATH = [home + '/include'])
            if os.path.exists(home + '/lib'):
                env.AppendUnique(LIBPATH = [home + '/lib'])
            else:
                env.AppendUnique(LIBPATH = [home])

    if env['PLATFORM'] == 'posix': config.check_lib(conf, 'dl')

    if (conf.CheckCHeader('openssl/ssl.h') and
        (config.check_lib(conf, 'crypto') and
         config.check_lib(conf, 'ssl')) or
        (config.check_lib(conf, 'libeay32') and
         config.check_lib(conf, 'ssleay32'))):

        if env['PLATFORM'] == 'win32':
            for lib in ['wsock32', 'advapi32', 'gdi32', 'user32']:
                config.require_lib(conf, lib)
 
        env.AppendUnique(CPPDEFINES = ['HAVE_OPENSSL'])
        return True

    else: raise Exception, 'Need openssl'
Example #4
0
def configure(conf):
    env = conf.env

    config.check_home(conf, 'GL')

    if env['PLATFORM'] == 'darwin':
        config.configure('osx', conf)

        if not (conf.CheckOSXFramework('OpenGL') and
                conf.CheckCHeader('OpenGL/gl.h')):
            raise Exception, 'Need OpenGL'

    else:
        if env['PLATFORM'] == 'win32':
            glulib = 'glu32'
            gllib = 'opengl32'

        else:
            glulib = 'GLU'
            gllib = 'GL'

        config.require_lib(conf, gllib)
        config.require_lib(conf, glulib)

    return True
Example #5
0
def configure(conf, cxx = True, threads = True):
    env = conf.env

    # See http://dmalloc.com/
    if env.get('dmalloc'):
        libname = 'dmalloc'

        if threads: libname += 'th'
        if cxx: libname += 'cxx'

        if cxx: lang = 'C++'
        else: lang = None

        config.require_lib(conf, libname, language = lang)


    # See http://linux.die.net/man/3/efence
    if env.get('efence'): config.require_lib(conf, 'efence')


    # See http://code.google.com/p/google-perftools
    if env.get('tcmalloc'):
        if conf.CheckCXXHeader('google/tcmalloc.h'):
            env.AppendUnique(CPPDEFINES = ['HAVE_TCMALLOC_H'])

        libname = 'tcmalloc'
        #if env.get('debug'): libname += '_debug'

        config.require_lib(conf, libname)
        config.require_lib(conf, 'unwind')

        if env.get('static') or env.get('mostly_static'):
            env.AppendUnique(LINKFLAGS = ['-Wl,--eh-frame-hdr'])

        env.AppendUnique(CCFLAGS = [
                '-fno-builtin-malloc', '-fno-builtin-calloc',
                '-fno-builtin-realloc', '-fno-builtin-free'])


    # See http://libcwd.sourceforge.net/
    if env.get('cwd'):
        libname = 'cwd'
        if threads:
            libname += '_r'
            env.AppendUnique(CPPDEFINES = ['LIBCWD_THREAD_SAFE'])

        if env.get('debug'):
            env.AppendUnique(CPPDEFINES = ['CWDEBUG'])

        if conf.CheckCXXHeader('libcwd/sys.h'):
            env.AppendUnique(CPPDEFINES = ['HAVE_LIBCWD'])

        config.require_lib(conf, libname)

        # libcwd does not work if libdl is included anywhere earlier
        requrie_lib(conf, 'dl')


    return True
Example #6
0
def configure_deps(conf):
    env = conf.env

    # zlib
    config.configure('zlib', conf)

    # libbzip2
    config.configure('libbzip2', conf)

    # XML
    config.configure('xml', conf)

    # OpenSSL
    config.configure('openssl', conf)

    # V8
    config.configure('v8', conf, False)

    # libsqlite
    config.configure('libsqlite', conf)

    # boost
    config.configure('boost', conf, version = '1.40',
                     hdrs = ['version', 'iostreams/stream'],
                     libs = ['iostreams', 'system', 'filesystem', 'regex'])

    # pthread
    if env['PLATFORM'] != 'win32': config.configure('pthreads', conf)

    # wsock32 & D3D9
    if env['PLATFORM'] == 'win32':
        config.require_lib(conf, 'wsock32')
        config.require_lib(conf, 'setupapi')

    # OSX frameworks
    if env['PLATFORM'] == 'darwin':
        if not (config.configure('osx', conf) and
                conf.CheckOSXFramework('ApplicationServices') and
                conf.CheckOSXFramework('IOKit') and
                conf.CheckOSXFramework('CoreFoundation')):
            raise Exception, \
                'Need ApplicationServices, IOKit & CoreFoundation frameworks'

    # Valgrind
    config.configure('valgrind', conf)

    # Debug
    if env.get('debug', 0):
        if conf.CheckCHeader('execinfo.h') and conf.CheckCHeader('bfd.h') and \
                config.check_lib(conf, 'iberty') and \
                config.check_lib(conf, 'bfd'):
            env.AppendUnique(CPPDEFINES = ['HAVE_CBANG_BACKTRACE'])

        elif env.get('backtrace_debugger', 0):
            raise Exception, \
                "execinfo.h, bfd.h and libbfd needed for backtrace_debuger"

        env.AppendUnique(CPPDEFINES =
                         ['DEBUG_LEVEL=' + str(env.get('debug_level', 1))])
Example #7
0
def configure(conf, cxx=True, threads=True):
    env = conf.env

    # See http://dmalloc.com/
    if env.get('dmalloc'):
        libname = 'dmalloc'

        if threads: libname += 'th'
        if cxx: libname += 'cxx'

        if cxx: lang = 'C++'
        else: lang = None

        config.require_lib(conf, libname, language=lang)

    # See http://linux.die.net/man/3/efence
    if env.get('efence'): config.require_lib(conf, 'efence')

    # See http://code.google.com/p/google-perftools
    if env.get('tcmalloc'):
        if conf.CheckCXXHeader('google/tcmalloc.h'):
            env.AppendUnique(CPPDEFINES=['HAVE_TCMALLOC_H'])

        libname = 'tcmalloc'
        #if env.get('debug'): libname += '_debug'

        config.require_lib(conf, libname)
        config.require_lib(conf, 'unwind')

        if env.get('static') or env.get('mostly_static'):
            env.AppendUnique(LINKFLAGS=['-Wl,--eh-frame-hdr'])

        env.AppendUnique(CCFLAGS=[
            '-fno-builtin-malloc', '-fno-builtin-calloc',
            '-fno-builtin-realloc', '-fno-builtin-free'
        ])

    # See http://libcwd.sourceforge.net/
    if env.get('cwd'):
        libname = 'cwd'
        if threads:
            libname += '_r'
            env.AppendUnique(CPPDEFINES=['LIBCWD_THREAD_SAFE'])

        if env.get('debug'):
            env.AppendUnique(CPPDEFINES=['CWDEBUG'])

        if conf.CheckCXXHeader('libcwd/sys.h'):
            env.AppendUnique(CPPDEFINES=['HAVE_LIBCWD'])

        config.require_lib(conf, libname)

        # libcwd does not work if libdl is included anywhere earlier
        requrie_lib(conf, 'dl')

    return True
Example #8
0
def configure(conf):
    env = conf.env

    config.check_home(conf, 'GLEW')

    if env['PLATFORM'] == 'win32':
        glewlib = 'glew32s' # The static version
        env.AppendUnique(CPPDEFINES = ['GLEW_BUILD=GLEW_STATIC'])

    else: glewlib = 'GLEW'

    config.require_header(conf, 'GL/glew.h')
    config.require_lib(conf, glewlib)

    return True
Example #9
0
def configure(conf):
    env = conf.env

    configure_deps(conf)

    # Libprotomol paths
    if home:
        env.Append(CPPPATH = [home + '/src'])
        env.Prepend(LIBPATH = [home])

    # Library name
    lib = 'protomol'
    if env.get('fah', 0): lib += '-fah'

    config.require_lib(conf, lib)
Example #10
0
def configure(conf):
    env = conf.env

    config.check_home(conf, 'GLEW')

    if env['PLATFORM'] == 'win32':
        glewlib = 'glew32s'  # The static version
        env.AppendUnique(CPPDEFINES=['GLEW_BUILD=GLEW_STATIC'])

    else:
        glewlib = 'GLEW'

    config.require_header(conf, 'GL/glew.h')
    config.require_lib(conf, glewlib)

    return True
Example #11
0
def configure(conf):
    env = conf.env

    # pthread
    if env['PLATFORM'] != 'win32':
        config.configure('pthreads', conf)

    # wsock32
    if env['PLATFORM'] == 'win32':
        config.require_lib(conf, 'wsock32')

    config.check_home(conf, 'libsqlite', '', '')

    if config.check_lib(conf, 'sqlite3') and \
            config.check_header(conf, 'sqlite3.h'):
        env.AppendUnique(CPPDEFINES=['HAVE_LIBSQLITE'])
        return True

    return False
Example #12
0
def configure(conf):
    env = conf.env

    # pthread
    if env['PLATFORM'] != 'win32':
        config.configure('pthreads', conf)

    # wsock32
    if env['PLATFORM'] == 'win32':
        config.require_lib(conf, 'wsock32')

    config.check_home(conf, 'libsqlite', '', '')

    if config.check_lib(conf, 'sqlite3') and \
            config.check_header(conf, 'sqlite3.h'):
        env.AppendUnique(CPPDEFINES = ['HAVE_LIBSQLITE'])
        return True

    return False
Example #13
0
def configure_deps(conf):
    env = conf.env

    # libfah
    if env.get('fah', 0): config.configure('libfah', conf)

    # DIAG Options
    if env.get('qrdiag', 0): env.AppendUnique(CPPDEFINES = ['HAVE_QRDIAG'])

    # GUI Options
    if env.get('gui',0):
        if env['PLATFORM'] == 'win32': config.require_lib(conf, 'wsock32')
        else: config.require_lib(conf, 'pthread')

        env.AppendUnique(CPPDEFINES = ['HAVE_GUI'])

    # LAPACK
    have_lapack = False
    lapack = env.get('lapack', 'any')
    if lapack == '1' or lapack is True: lapack = 'any'
    elif lapack == '0' or lapack is False: lapack = 'none'

    if lapack != 'none':
        # Intel MKL LAPACK
        if not have_lapack and lapack in ['any', 'mkl']:
            have_lapack = config.configure('mkl', conf)
            if have_lapack:
                env.AppendUnique(CPPDEFINES = ['HAVE_MKL_LAPACK'])
            elif lapack == 'mkl':
                raise Exception, "Missing MKL LAPACK"

        # System LAPACK
        if not have_lapack and lapack in ['any', 'system']:
            have_lapack = config.configure('lapack', conf)
            if not have_lapack and lapack == 'lapack':
                raise Exception, "Missing LAPACK"

        # SimTK LAPACK
        if not have_lapack and lapack in ['any', 'simtk']:
            config.check_home(conf, 'simtk_lapack')

            if (config.check_lib(conf, 'SimTKlapack') and
                config.check_cxx_header(conf, 'SimTKlapack.h')):

                env.AppendUnique(CPPDEFINES = ['HAVE_SIMTK_LAPACK'])
                have_lapack = True
 
            elif lapack == 'simtk_lapack':
                raise Exception, "Missing SimTK LAPACK"

        if not have_lapack: raise Exception, "Missing LAPACK"
						
    # OpenMM
    openmm = env.get('openmm', 0)
    if openmm:
        home = config.check_env('OPENMM_HOME', True)

        conf.env.AppendUnique(CPPPATH = [home + 'olla/include'])
        conf.env.AppendUnique(CPPPATH = [home + 'openmmapi/include'])
        config.require_cxx_header(conf, 'OpenMM.h')
        config.require_cxx_header(conf, 'openmm/Kernel.h')

        conf.env.Prepend(LIBPATH = [home])
        config.require_lib(conf, 'OpenMM')

        env.AppendUnique(CPPDEFINES = ['HAVE_OPENMM'])
						
    # LTMD OpenMM
    ltmd = env.get('ltmdopenmm', 0)
    if ltmd and openmm:
        config.check_home(conf, 'ltmdopenmm')
        config.require_lib(conf, 'OpenMMLTMD')
        env.AppendUnique(CPPDEFINES = ['HAVE_OPENMM_LTMD'])
			

    # Gromacs
    gromacs = env.get('gromacs', 0)
    if gromacs: config.configure('gromacs', conf)


    # Gromacs Standard
    gromacs_standard = env.get('gromacs_standard', 0)
    if gromacs_standard:
        config.check_home(conf, 'gromacs')
        config.require_lib(conf, 'md')
        config.require_lib(conf, 'gmx')
        env.AppendUnique(CPPDEFINES = ['HAVE_GROMACS'])
Example #14
0
def configure(conf, cstd='c99'):
    env = conf.env

    conf.AddTests({'check_rdynamic': check_rdynamic})

    if env.GetOption('clean'): return

    # Decider hack.  Works around some SCons bugs.
    env.Decider(decider_hack(env))

    # Get options
    debug = int(env.get('debug'))
    optimize = int(env.get('optimize'))
    if optimize == -1: optimize = not debug
    globalopt = int(env.get('globalopt'))
    sse2 = int(env.get('sse2'))
    sse3 = int(env.get('sse3'))
    auto_dispatch = int(env.get('auto_dispatch'))
    strict = int(env.get('strict'))
    threaded = int(env.get('threaded'))
    profile = int(env.get('profile'))
    depends = int(env.get('depends'))
    compiler = env.get('compiler')
    distcc = int(env.get('distcc'))
    ccache = int(env.get('ccache'))
    cxxstd = env.get('cxxstd')
    platform = env.get('platform')
    static = int(env.get('static'))
    mostly_static = int(env.get('mostly_static'))
    num_jobs = env.get('num_jobs')
    osx_min_ver = env.get('osx_min_ver')

    if platform != '': env.Replace(PLATFORM=platform)

    # Select compiler
    compiler_mode = None

    # Prefer Intel compiler
    if compiler == 'default' and os.environ.get('INTEL_LICENSE_FILE', False):
        compiler = 'intel'

    if compiler:
        if compiler == 'gnu':
            Tool('gcc')(env)
            Tool('g++')(env)
            compiler_mode = "gnu"

        elif compiler == 'intel':
            Tool('intelc')(env)
            env['ENV']['INTEL_LICENSE_FILE'] = (os.environ.get(
                "INTEL_LICENSE_FILE", ''))

            if env['PLATFORM'] == 'win32': compiler_mode = 'msvc'
            else: compiler_mode = 'gnu'

            if compiler_mode == 'msvc':
                env.Replace(AR='xilib')

                # Work around double CCFLAGS bug
                env.Replace(CXXFLAGS=['/TP'])

                # Fix INCLUDE
                env.PrependENVPath('INCLUDE', os.environ.get('INCLUDE', ''))

        elif compiler == 'linux-mingw':
            env.Replace(CC='i586-mingw32msvc-gcc')
            env.Replace(CXX='i586-mingw32msvc-g++')
            env.Replace(RANLIB='i586-mingw32msvc-ranlib')
            env.Replace(PROGSUFFIX='.exe')
            compiler_mode = "gnu"

        elif compiler == 'posix':
            Tool('cc')(env)
            Tool('cxx')(env)
            Tool('link')(env)
            Tool('ar')(env)
            Tool('as')(env)
            compiler_mode = "unknown"

        elif compiler in ['hp', 'sgi', 'sun', 'aix']:
            Tool(compiler + 'cc')(env)
            Tool(compiler + 'c++')(env)
            Tool(compiler + 'link')(env)

            if compiler in ['sgi', 'sun']:
                Tool(compiler + 'ar')(env)

            compiler_mode = "unknown"

        elif compiler != 'default':
            Tool(compiler)(env)

    if compiler_mode is None:
        if env['CC'] == 'cl' or env['CC'] == 'icl': compiler_mode = 'msvc'
        elif env['CC'] == 'gcc' or env['CC'] == 'icc': compiler_mode = 'gnu'
        else: compiler_mode = 'unknown'

    env.__setitem__('compiler', compiler)
    env.__setitem__('compiler_mode', compiler_mode)

    if compiler == 'default':
        cc = env['CC']
        if cc == 'cl': compiler = 'msvc'
        elif cc == 'gcc': compiler = 'gnu'
        elif cc == 'icl' or cc == 'icc': compiler = 'intel'

    print "Compiler: " + env['CC'] + ' (%s)' % compiler
    print "Platform: " + env['PLATFORM']
    print "Mode: " + compiler_mode

    # Exceptions
    if compiler_mode == 'msvc':
        env.AppendUnique(CCFLAGS=['/EHa'])  # Asynchronous

    # Disable troublesome warnings
    warnings = []
    if compiler_mode == 'msvc':
        env.AppendUnique(CPPDEFINES=['_CRT_SECURE_NO_WARNINGS'])

        warnings += [4297, 4103]
        if compiler == 'intel': warnings += [1786]

    if compiler == 'intel': warnings += [279]

    if compiler == 'intel':
        warnings = map(str, warnings)
        if compiler_mode == 'msvc':
            env.AppendUnique(CCFLAGS=['/Qdiag-disable:' + ','.join(warnings)])
        else:
            env.AppendUnique(CCFLAGS=['-diag-disable', ','.join(warnings)])

    elif compiler_mode == 'msvc':
        for warning in warnings:
            env.AppendUnique(CCFLAGS=['/wd%d' % warning])

    # Profiler flags
    if profile:
        if compiler_mode == 'gnu':
            env.AppendUnique(CCFLAGS=['-pg'])
            env.AppendUnique(LINKFLAGS=['-pg'])

    # Debug flags
    if compiler_mode == 'msvc':
        env['PDB'] = '${TARGET}.pdb'

    if debug:
        if compiler_mode == 'msvc':
            env.AppendUnique(CCFLAGS=['/W1', '/Zi'])
            env.AppendUnique(LINKFLAGS=['/DEBUG', '/MAP:${TARGET}.map'])

        elif compiler_mode == 'gnu':
            if compiler == 'gnu':
                env.AppendUnique(CCFLAGS=['-ggdb', '-Wall'])
                if conf.check_rdynamic():
                    env.AppendUnique(LINKFLAGS=['-rdynamic'])  # for backtrace
            elif compiler == 'intel':
                env.AppendUnique(CCFLAGS=['-g', '-diag-enable', 'warn'])

            if strict: env.AppendUnique(CCFLAGS=['-Werror'])

        env.AppendUnique(CPPDEFINES=['DEBUG'])

        if not optimize and compiler == 'intel':
            if compiler_mode == 'gnu':
                env.AppendUnique(CCFLAGS=['-mia32'])
            elif compiler_mode == 'msvc':
                env.AppendUnique(CCFLAGS=['/arch:IA32'])

    else:
        if compiler_mode == 'gnu':
            # Don't add debug info and enable dead code removal
            env.AppendUnique(LINKFLAGS=['-Wl,-S', '-Wl,-x'])

        env.AppendUnique(CPPDEFINES=['NDEBUG'])

    # Optimizations
    if optimize:
        if compiler_mode == 'gnu':
            env.AppendUnique(CCFLAGS=['-O3', '-funroll-loops'])
            if compiler != 'intel':
                env.AppendUnique(CCFLAGS=[
                    '-mfpmath=sse', '-ffast-math',
                    '-fno-unsafe-math-optimizations'
                ])
        elif compiler_mode == 'msvc':
            env.AppendUnique(CCFLAGS=['/Ox'])
            if compiler == 'intel' and not globalopt:
                env.AppendUnique(LINKFLAGS=['/Qnoipo'])

        # Whole program optimizations
        if globalopt:
            if compiler == 'intel':
                if compiler_mode == 'gnu':
                    env.AppendUnique(LINKFLAGS=['-ipo'])
                    env.AppendUnique(CCFLAGS=['-ipo'])
                elif compiler_mode == 'msvc':
                    env.AppendUnique(LINKFLAGS=['/Qipo'])
                    env.AppendUnique(CCFLAGS=['/Qipo'])

            elif compiler == 'msvc':
                env.AppendUnique(CCFLAGS=['/GL'])
                env.AppendUnique(LINKFLAGS=['/LTCG'])
                env.AppendUnique(ARFLAGS=['/LTCG'])

        # Instruction set optimizations
        if sse2: opt_base, opt_auto = 'SSE2', 'SSE3,SSSE3,SSE4.1,SSE4.2'
        elif sse3: opt_base, opt_auto = 'SSE3', 'SSSE3,SSE4.1,SSE4.2'
        elif architecture()[0] == '64bit':
            opt_base, opt_auto = 'SSE2', 'SSE3,SSSE3,SSE4.1,SSE4.2'
        else:
            opt_base, opt_auto = 'SSE', 'SSE2,SSE3,SSSE3,SSE4.1,SSE4.2'

        if compiler_mode == 'gnu':
            env.AppendUnique(CCFLAGS=['-m' + opt_base.lower()])

            if compiler == 'intel' and auto_dispatch:
                env.AppendUnique(CCFLAGS=['-ax' + opt_auto])

        elif compiler_mode == 'msvc':
            env.AppendUnique(CCFLAGS=['-arch:' + opt_base])

            if compiler == 'intel' and auto_dispatch:
                env.AppendUnique(CCFLAGS=['/Qax' + opt_auto])

        # Intel threading optimizations
        if compiler == 'intel':
            if compiler_mode == 'msvc':
                env.AppendUnique(CCFLAGS=['/Qopenmp'])
            else:
                env.AppendUnique(CCFLAGS=['-openmp'])

            if compiler_mode == 'msvc': env.PrependUnique(LIBS=['libiomp5mt'])
            else: env.PrependUnique(LIBS=['iomp5'])

    # Pointer disambiguation
    if compiler == 'intel':
        if compiler_mode == 'gnu':
            env.AppendUnique(CCFLAGS=['-restrict'])
        elif compiler_mode == 'msvc':
            env.AppendUnique(CCFLAGS=['/Qrestrict'])

    # Dependency files
    if depends and compiler_mode == 'gnu':
        env.AppendUnique(CCFLAGS=['-MMD -MF ${TARGET}.d'])

    # C mode
    if cstd:
        if compiler_mode == 'gnu':
            env.AppendUnique(CFLAGS=['-std=' + cstd])
        elif compiler_mode == 'msvc':
            env.AppendUnique(CFLAGS=['/Qstd=' + cstd])

    # C++ mode
    if cxxstd:
        if compiler_mode == 'gnu':
            env.AppendUnique(CXXFLAGS=['-std=' + cxxstd])

    # Threads
    if threaded:
        if compiler_mode == 'gnu':
            config.require_lib(conf, 'pthread')

            env.AppendUnique(LINKFLAGS=['-pthread'])
            env.AppendUnique(CPPDEFINES=['_REENTRANT'])

        elif compiler_mode == 'msvc':
            if debug: env.AppendUnique(CCFLAGS=['/MTd'])
            else: env.AppendUnique(CCFLAGS=['/MT'])

    # Link flags
    if compiler_mode == 'msvc' and not optimize:
        env.AppendUnique(LINKFLAGS=['/INCREMENTAL'])

    # static
    if static:
        if compiler_mode == 'gnu' and env['PLATFORM'] != 'darwin':
            env.AppendUnique(LINKFLAGS=['-static'])

    # Num jobs default
    default_num_jobs = 1

    # distcc
    if distcc and compiler == 'gnu':
        default_num_jobs = 2
        env.Replace(CC='distcc ' + env['CC'])
        env.Replace(CXX='distcc ' + env['CXX'])

    # cccache
    if ccache and compiler == 'gnu':
        env.Replace(CC='ccache ' + env['CC'])
        env.Replace(CXX='ccache ' + env['CXX'])

    # Num jobs
    if num_jobs == -1:
        if os.environ.has_key('SCONS_JOBS'):
            num_jobs = int(os.environ.get('SCONS_JOBS', num_jobs))
        else:
            num_jobs = default_num_jobs

    SetOption('num_jobs', num_jobs)
    print "running with -j", GetOption('num_jobs')

    # For darwin
    if env['PLATFORM'] == 'darwin':
        env.AppendUnique(CPPDEFINES=['__APPLE__'])
        if osx_min_ver:
            flag = '-mmacosx-version-min=' + osx_min_ver
            env.AppendUnique(LINKFLAGS=[flag])
            env.AppendUnique(CCFLAGS=[flag])
Example #15
0
def configure(conf, cstd = 'c99'):
    env = conf.env

    conf.AddTests({'check_rdynamic': check_rdynamic})

    if env.GetOption('clean'): return

    # Decider hack.  Works around some SCons bugs.
    env.Decider(decider_hack(env))

    # Get options
    debug = int(env.get('debug'))
    optimize = int(env.get('optimize'))
    if optimize == -1: optimize = not debug
    globalopt = int(env.get('globalopt'))
    sse2 = int(env.get('sse2'))
    sse3 = int(env.get('sse3'))
    auto_dispatch = int(env.get('auto_dispatch'))
    strict = int(env.get('strict'))
    threaded = int(env.get('threaded'))
    profile = int(env.get('profile'))
    depends = int(env.get('depends'))
    compiler = env.get('compiler')
    distcc = int(env.get('distcc'))
    ccache = int(env.get('ccache'))
    cxxstd = env.get('cxxstd')
    platform = env.get('platform')
    static = int(env.get('static'))
    mostly_static = int(env.get('mostly_static'))
    num_jobs = env.get('num_jobs')
    osx_min_ver = env.get('osx_min_ver')

    if platform != '': env.Replace(PLATFORM = platform)

    # Select compiler
    compiler_mode = None

    # Prefer Intel compiler
    if compiler == 'default' and os.environ.get('INTEL_LICENSE_FILE', False):
        compiler = 'intel'

    if compiler:
        if compiler == 'gnu':
            Tool('gcc')(env)
            Tool('g++')(env)
            compiler_mode = "gnu"

        elif compiler == 'intel':
            Tool('intelc')(env)
            env['ENV']['INTEL_LICENSE_FILE'] = (
                os.environ.get("INTEL_LICENSE_FILE", ''))

            if env['PLATFORM'] == 'win32': compiler_mode = 'msvc'
            else: compiler_mode = 'gnu'

            if compiler_mode == 'msvc':
                env.Replace(AR = 'xilib')

                # Work around double CCFLAGS bug
                env.Replace(CXXFLAGS = ['/TP'])

                # Fix INCLUDE
                env.PrependENVPath('INCLUDE', os.environ.get('INCLUDE', ''))

        elif compiler == 'linux-mingw':
            env.Replace(CC = 'i586-mingw32msvc-gcc')
            env.Replace(CXX = 'i586-mingw32msvc-g++')
            env.Replace(RANLIB = 'i586-mingw32msvc-ranlib')
            env.Replace(PROGSUFFIX = '.exe')
            compiler_mode = "gnu"

        elif compiler == 'posix':
            Tool('cc')(env)
            Tool('cxx')(env)
            Tool('link')(env)
            Tool('ar')(env)
            Tool('as')(env)
            compiler_mode = "unknown"

        elif compiler in ['hp', 'sgi', 'sun', 'aix']:
            Tool(compiler + 'cc')(env)
            Tool(compiler + 'c++')(env)
            Tool(compiler + 'link')(env)

            if compiler in ['sgi', 'sun']:
                Tool(compiler + 'ar')(env)

            compiler_mode = "unknown"

        elif compiler != 'default':
            Tool(compiler)(env)


    if compiler_mode is None:
        if env['CC'] == 'cl' or env['CC'] == 'icl': compiler_mode = 'msvc'
        elif env['CC'] == 'gcc' or env['CC'] == 'icc': compiler_mode = 'gnu'
        else: compiler_mode = 'unknown'

    env.__setitem__('compiler', compiler)
    env.__setitem__('compiler_mode', compiler_mode)

    if compiler == 'default':
        cc = env['CC']
        if cc == 'cl': compiler = 'msvc'
        elif cc == 'gcc': compiler = 'gnu'
        elif cc == 'icl' or cc == 'icc': compiler = 'intel'


    print "Compiler: " + env['CC'] + ' (%s)' % compiler
    print "Platform: " + env['PLATFORM']
    print "Mode: " + compiler_mode


    # Exceptions
    if compiler_mode == 'msvc':
        env.AppendUnique(CCFLAGS = ['/EHa']) # Asynchronous


    # Disable troublesome warnings
    warnings = []
    if compiler_mode == 'msvc':
        env.AppendUnique(CPPDEFINES = ['_CRT_SECURE_NO_WARNINGS'])

        warnings += [4297, 4103]
        if compiler == 'intel': warnings += [1786]

    if compiler == 'intel': warnings += [279]

    if compiler == 'intel':
        warnings = map(str, warnings)
        if compiler_mode == 'msvc':
            env.AppendUnique(CCFLAGS = ['/Qdiag-disable:' + ','.join(warnings)])
        else:
            env.AppendUnique(CCFLAGS = ['-diag-disable', ','.join(warnings)])

    elif compiler_mode == 'msvc':
        for warning in warnings: env.AppendUnique(CCFLAGS = ['/wd%d' % warning])


    # Profiler flags
    if profile:
        if compiler_mode == 'gnu':
            env.AppendUnique(CCFLAGS = ['-pg'])
            env.AppendUnique(LINKFLAGS = ['-pg'])


    # Debug flags
    if compiler_mode == 'msvc':
        env['PDB'] = '${TARGET}.pdb'

    if debug:
        if compiler_mode == 'msvc':
            env.AppendUnique(CCFLAGS = ['/W1', '/Zi'])
            env.AppendUnique(LINKFLAGS = ['/DEBUG', '/MAP:${TARGET}.map'])

        elif compiler_mode == 'gnu':
            if compiler == 'gnu':
                env.AppendUnique(CCFLAGS = ['-ggdb', '-Wall'])
                if conf.check_rdynamic():
                    env.AppendUnique(LINKFLAGS = ['-rdynamic']) # for backtrace
            elif compiler == 'intel':
                env.AppendUnique(CCFLAGS = ['-g', '-diag-enable', 'warn'])

            if strict: env.AppendUnique(CCFLAGS = ['-Werror'])

        env.AppendUnique(CPPDEFINES = ['DEBUG'])

        if not optimize and compiler == 'intel':
            if compiler_mode == 'gnu':
                env.AppendUnique(CCFLAGS = ['-mia32'])
            elif compiler_mode == 'msvc':
                env.AppendUnique(CCFLAGS = ['/arch:IA32'])

    else:
        if compiler_mode == 'gnu':
            # Don't add debug info and enable dead code removal
            env.AppendUnique(LINKFLAGS = ['-Wl,-S', '-Wl,-x'])

        env.AppendUnique(CPPDEFINES = ['NDEBUG'])


    # Optimizations
    if optimize:
        if compiler_mode == 'gnu':
            env.AppendUnique(CCFLAGS = ['-O3', '-funroll-loops'])
            if compiler != 'intel':
                env.AppendUnique(CCFLAGS = ['-mfpmath=sse', '-ffast-math',
                                            '-fno-unsafe-math-optimizations'])
        elif compiler_mode == 'msvc':
            env.AppendUnique(CCFLAGS = ['/Ox'])
            if compiler == 'intel' and not globalopt:
                env.AppendUnique(LINKFLAGS = ['/Qnoipo'])

        # Whole program optimizations
        if globalopt:
            if compiler == 'intel':
                if compiler_mode == 'gnu':
                    env.AppendUnique(LINKFLAGS = ['-ipo'])
                    env.AppendUnique(CCFLAGS = ['-ipo'])
                elif compiler_mode == 'msvc':
                    env.AppendUnique(LINKFLAGS = ['/Qipo'])
                    env.AppendUnique(CCFLAGS = ['/Qipo'])

            elif compiler == 'msvc':
                env.AppendUnique(CCFLAGS = ['/GL'])
                env.AppendUnique(LINKFLAGS = ['/LTCG'])
                env.AppendUnique(ARFLAGS = ['/LTCG'])

        # Instruction set optimizations
        if sse2: opt_base, opt_auto = 'SSE2', 'SSE3,SSSE3,SSE4.1,SSE4.2'
        elif sse3: opt_base, opt_auto = 'SSE3', 'SSSE3,SSE4.1,SSE4.2'
        elif architecture()[0] == '64bit':
            opt_base, opt_auto = 'SSE2', 'SSE3,SSSE3,SSE4.1,SSE4.2'
        else: opt_base, opt_auto = 'SSE', 'SSE2,SSE3,SSSE3,SSE4.1,SSE4.2'

        if compiler_mode == 'gnu':
            env.AppendUnique(CCFLAGS = ['-m' + opt_base.lower()])

            if compiler == 'intel' and auto_dispatch:
                env.AppendUnique(CCFLAGS = ['-ax' + opt_auto])

        elif compiler_mode == 'msvc':
            env.AppendUnique(CCFLAGS = ['-arch:' + opt_base])

            if compiler == 'intel' and auto_dispatch:
                env.AppendUnique(CCFLAGS = ['/Qax' + opt_auto])

        # Intel threading optimizations
        if compiler == 'intel':
            if compiler_mode == 'msvc':
                env.AppendUnique(CCFLAGS = ['/Qopenmp'])
            else:
                env.AppendUnique(CCFLAGS = ['-openmp'])

            if compiler_mode == 'msvc': env.PrependUnique(LIBS = ['libiomp5mt'])
            else: env.PrependUnique(LIBS = ['iomp5'])
            

    # Pointer disambiguation
    if compiler == 'intel':
        if compiler_mode == 'gnu':
            env.AppendUnique(CCFLAGS = ['-restrict'])
        elif compiler_mode == 'msvc':
            env.AppendUnique(CCFLAGS = ['/Qrestrict'])


    # Dependency files
    if depends and compiler_mode == 'gnu':
        env.AppendUnique(CCFLAGS = ['-MMD -MF ${TARGET}.d'])


    # C mode
    if cstd:
        if compiler_mode == 'gnu':
            env.AppendUnique(CFLAGS = ['-std=' + cstd])
        elif compiler_mode == 'msvc':
            env.AppendUnique(CFLAGS = ['/Qstd=' + cstd])

    # C++ mode
    if cxxstd:
        if compiler_mode == 'gnu':
            env.AppendUnique(CXXFLAGS = ['-std=' + cxxstd])


    # Threads
    if threaded:
        if compiler_mode == 'gnu':
            config.require_lib(conf, 'pthread')

            env.AppendUnique(LINKFLAGS = ['-pthread'])
            env.AppendUnique(CPPDEFINES = ['_REENTRANT'])

        elif compiler_mode == 'msvc':
            if debug: env.AppendUnique(CCFLAGS = ['/MTd'])
            else: env.AppendUnique(CCFLAGS = ['/MT'])


    # Link flags
    if compiler_mode == 'msvc' and not optimize:
        env.AppendUnique(LINKFLAGS = ['/INCREMENTAL'])

    # static
    if static:
        if compiler_mode == 'gnu' and env['PLATFORM'] != 'darwin':
            env.AppendUnique(LINKFLAGS = ['-static'])


    # Num jobs default
    default_num_jobs = 1

    # distcc
    if distcc and compiler == 'gnu':
        default_num_jobs = 2
        env.Replace(CC = 'distcc ' + env['CC'])
        env.Replace(CXX = 'distcc ' + env['CXX'])

    # cccache
    if ccache and compiler == 'gnu':
        env.Replace(CC = 'ccache ' + env['CC'])
        env.Replace(CXX = 'ccache ' + env['CXX'])

    # Num jobs
    if num_jobs == -1:
        if os.environ.has_key('SCONS_JOBS'):
            num_jobs = int(os.environ.get('SCONS_JOBS', num_jobs))
        else: num_jobs = default_num_jobs

    SetOption('num_jobs', num_jobs)
    print "running with -j", GetOption('num_jobs')


    # For darwin
    if env['PLATFORM'] == 'darwin':
        env.AppendUnique(CPPDEFINES = ['__APPLE__'])
        if osx_min_ver:
            flag = '-mmacosx-version-min=' + osx_min_ver
            env.AppendUnique(LINKFLAGS = [flag])
            env.AppendUnique(CCFLAGS = [flag])