Exemplo n.º 1
0
def checkPython(env):
    # First we check to see if the config file has specified
    # where to find the file. Ideally, this should be automatic
    # but we need to deal with the case where python is not in its INSTALL
    # directory.
    # Use the python scons is running
    if env['pythoncmd'] == sys.executable:
        if env['IS_WINDOWS']:
            python_inc_path=sysconfig.get_python_inc()
            python_lib_path=os.path.join(sysconfig.get_config_var('prefix'), 'libs')
            python_libs=['python%s%s'%(sys.version_info[0], sys.version_info[1])]
            verstring=".".join([str(i) for i in sys.version_info[:3]])
        else:
            (python_lib_path, python_libs,verstring, python_inc_path)=call_python_config()

    # if we want to use a python other than the one scons is running
    # Note: we assume scons is running python 2 in the following.
    else:
        (python_lib_path, python_libs,verstring, python_inc_path)=call_python_config(env['pythoncmd'])
    env['python_version'] = verstring
    ispython3 = (verstring[0] == '3')
    if ispython3:
        env.Append(CPPDEFINES=['ESPYTHON3'])
    env['buildvars']['python_version'] = verstring
    env['buildvars']['python'] = env['pythoncmd']
    # Check for an override from the config file.
    # Ideally, this should be automatic but we need to deal with the case
    # where python is not in its INSTALL directory
    if env['pythonlibpath'] != '':
        python_lib_path = env['pythonlibpath']

    if env['pythonincpath'] != '':
        python_inc_path = env['pythonincpath']

    if env['pythonlibname'] != '':
        python_libs = env['pythonlibname']

    conf = Configure(env.Clone())

    if env['sysheaderopt'] == '':
        conf.env.AppendUnique(CPPPATH = [python_inc_path])
    else:
        conf.env.Append(CCFLAGS = [env['sysheaderopt'], python_inc_path])

    conf.env.AppendUnique(LIBPATH = [python_lib_path])
    conf.env.AppendUnique(LIBS = python_libs)
    # The wrapper script needs to find the libs
    conf.env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], python_lib_path)

    if not conf.CheckCXXHeader('Python.h'):
        print("Cannot find python include files (tried 'Python.h' in directory %s)" % (python_inc_path))
        env.Exit(1)
    if not conf.CheckFunc('Py_Exit', language='c++'):
        print("Cannot find python library method Py_Exit (tried %s in directory %s)" % (python_libs, python_lib_path))
        env.Exit(1)

    return conf.Finish()
Exemplo n.º 2
0
def checkDependencies(env):
    conf = Configure(env)
    checkPkgConfig(env, 'gtkmm-2.4')
    checkPkgConfig(env, 'libxml++-2.6')
    checkPkgConfig(env, 'gtkglext-1.0')
    checkPkgConfig(env, 'libgtksourceviewmm-1.0')
    if not conf.CheckCXXHeader('osg/Node'):
        raise Exception(
            'ERROR: You have to install OSG development package before compiling osgedit'
        )
    return conf.Finish()
Exemplo n.º 3
0
def findLibWithHeader(env, libs, header, paths, lang='c++', try_link=True):
    from SCons.Script.SConscript import Configure
    inc_path = ''
    lib_path = ''
    # 'paths' may be a prefix, so look for lib and include subdirectories
    if type(paths) == str:
        # find the header file first
        for i in 'include', 'include64', 'include32', 'inc':
            inc = os.path.join(paths, i)
            if os.path.isfile(os.path.join(inc, header)):
                inc_path = inc
                break
        if inc_path == '':
            raise RuntimeError('%s not found under %s' % (header, paths))

        # now try to find a lib directory
        for l in 'lib', 'lib64', 'lib32':
            lp = os.path.join(paths, l)
            if os.path.isdir(lp):
                lib_path = lp
                break
        if lib_path == '':
            raise RuntimeError('No lib directory found under %s' % paths)
    else:
        if os.path.isfile(os.path.join(paths[0], header)):
            inc_path = paths[0]
        else:
            raise RuntimeError('%s not found under %s' % (header, paths[0]))
        if os.path.isdir(paths[1]):
            lib_path = paths[1]
        else:
            raise RuntimeError('%s is not a valid path.' % paths[1])

    if try_link:
        # now try the library
        conf = Configure(env.Clone())
        conf.env.AppendUnique(CPPPATH=[inc_path])
        conf.env.AppendUnique(LIBPATH=[lib_path])
        if type(libs) == str: libs = [libs]
        if len(libs) == 0: libs = ['']
        # we can't check for each library by itself since they may depend on
        # each other, so we add all libraries to the link line and check only
        # for one
        conf.env.AppendUnique(LIBS=libs)
        if not conf.CheckLibWithHeader(libs[0], header, lang):
            conf.Finish()
            raise RuntimeError('Unable to link against %s (paths: %s, %s)' %
                               (libs, inc_path, lib_path))

        conf.Finish()
    return inc_path, lib_path
Exemplo n.º 4
0
        def compileTest(self, env):
            env.Append(LIBS=['cairo'])
            conf = Configure(env,
                             conf_dir=self.conf_dir + "/findcairo",
                             log_file=self.conf_dir + "/findcairo/conf.log")

            result = conf.TryLink(
                """
            #include <cairo.h>
            int main()
            {
                const char* version = cairo_version_string();
                return 0;
            }
            """, '.c')
            conf.Finish()
            return result
Exemplo n.º 5
0
def checkNumpy(env):
    if not detectModule(env, 'numpy'):
        print(
            "Cannot import numpy. If it is installed try setting your PYTHONPATH and probably %s"
            % env['LD_LIBRARY_PATH_KEY'])
        env.Exit(1)

    ## check for numpy header (optional)
    conf = Configure(env.Clone())
    numpy_h = False
    if conf.CheckCXXHeader(['Python.h', 'numpy/ndarrayobject.h']):
        numpy_h = True
    else:
        conda_prefix = os.environ.get('CONDA_PREFIX')
        if conda_prefix:
            # make a copy of CPPPATH so it can be restored if header check fails
            cpp_path_old = conf.env.get('CPPPATH', []).copy()
            conf.env.Append(CPPPATH=[
                conda_prefix + '/Lib/site-packages/numpy/core/include'
            ])
            if conf.CheckCXXHeader(['Python.h', 'numpy/ndarrayobject.h']):
                numpy_h = True
            else:
                conf.env['CPPPATH'] = cpp_path_old

    conf.env['numpy_h'] = numpy_h
    if numpy_h:
        conf.env.Append(CPPDEFINES=['ESYS_HAVE_NUMPY_H'])

    return conf.Finish()
Exemplo n.º 6
0
        def compileTest(self, env):
            env.Append(LIBS=['freetype'])
            conf = Configure(env,
                             conf_dir=self.conf_dir + "/findfreetype",
                             log_file=self.conf_dir + "/findfreetype/conf.log")

            result = conf.TryLink(
                """
            #include <ft2build.h>
            #include FT_FREETYPE_H
            int main()
            {
                FT_Library  library;
                FT_Init_FreeType( &library );
                return 0;
            }
            """, '.c')
            conf.Finish()
            return result
Exemplo n.º 7
0
        def compileTest(self, env):
            env.Append(LIB=['graphite2'])
            conf = Configure(env,
                             conf_dir=self.conf_dir + "/findgraphite2",
                             log_file=self.conf_dir +
                             "/findgraphite2/conf.log")

            result = conf.TryLink(
                """
            #include <graphite2/Font.h>
            int main()
            {
                int nMajor, nMinor, nBugFix;
                gr_engine_version(&nMajor, &nMinor, &nBugFix);
                return 0;
            }
            """, '.c')

            conf.Finish()
            return result
Exemplo n.º 8
0
        def compileTest(self, env):
            env.Append(LIBS=['glib-2.0'])
            conf = Configure(env,
                             conf_dir=self.conf_dir + "/findglib2",
                             log_file=self.conf_dir + "/findglib2/conf.log")

            result = conf.TryLink(
                """
            #include <glib.h>
            int main()
            {
                const gchar* check = glib_check_version (
                    GLIB_MAJOR_VERSION,
                    GLIB_MINOR_VERSION,
                    GLIB_MICRO_VERSION);
             
                return (int)check;
            }
            """, '.c')
            conf.Finish()
            return result
Exemplo n.º 9
0
        def compileTest(self, env):
            env.Append(LIB=['icuuc', 'icudata'])
            conf = Configure(env,
                             conf_dir=self.conf_dir + "/findicu",
                             log_file=self.conf_dir + "/findicu/conf.log")

            result = conf.TryLink(
                """
            #include <unicode/ucnv.h>
            int main()
            {
                UErrorCode status = U_ZERO_ERROR;
                UConverter *defConv;
                defConv = u_getDefaultConverter(&status);
                if (U_FAILURE(status)) {
                    return 1;
                }
                return 0;
            }
            """, '.c')

            conf.Finish()
            return result
Exemplo n.º 10
0
def checkNumpy(env):
    if not detectModule(env, 'numpy'):
        print("Cannot import numpy. If it is installed try setting your PYTHONPATH and probably %s"%env['LD_LIBRARY_PATH_KEY'])
        env.Exit(1)

    ## check for numpy header (optional)
    conf = Configure(env.Clone())
    if conf.CheckCXXHeader(['Python.h','numpy/ndarrayobject.h']):
        conf.env.Append(CPPDEFINES = ['ESYS_HAVE_NUMPY_H'])
        conf.env['numpy_h']=True
    else:
        conf.env['numpy_h']=False

    return conf.Finish()
Exemplo n.º 11
0
def checkCompiler(env):
    conf = Configure(env.Clone(), custom_tests = {'CheckComplexAcos': CheckComplexAcos})
    if 'CheckCXX' in dir(conf): # exists since scons 1.1.0
        if not conf.CheckCXX():
            print("Cannot run C++ compiler '%s' (check config.log)" % (env['CXX']))
            env.Exit(1)
    else:
        if not conf.CheckFunc('printf', language='c++'):
            print("Cannot run C++ compiler '%s' (check config.log)" % (env['CXX']))
            env.Exit(1)

    conf.env['buildvars']['cxx']=conf.env['CXX']

    if conf.CheckFunc('gethostname', language='c++'):
        conf.env.Append(CPPDEFINES = ['HAVE_GETHOSTNAME'])

    if conf.CheckCXXHeader('byteswap.h'):
        checkhdr="""#include <byteswap.h>
#define SCbswap32() {int x=0;bswap_32(x);}"""
        if conf.CheckFunc('SCbswap32', header=checkhdr, language='c++'):
            conf.env.Append(CPPDEFINES = ['HAVE_BYTESWAP_H'])
    if conf.CheckCXXHeader('sys/endian.h'):
        conf.env.Append(CPPDEFINES = ['HAVE_SYS_ENDIAN_H'])
    if conf.CheckCXXHeader('libkern/OSByteOrder.h'):
        conf.env.Append(CPPDEFINES = ['HAVE_OSBYTEORDER_H'])

    if not conf.CheckComplexAcos():
        conf.env.Append(CPPDEFINES = ['ESYS_USE_BOOST_ACOS'])
    
    return conf.Finish()
Exemplo n.º 12
0
def checkOptionalLibraries(env):
    ######## netCDF
    netcdf_inc_path=''
    netcdf_lib_path=''
    if env['netcdf']:
        if env['netcdf']==4:
            env.Append(CPPDEFINES = ['NETCDF4'])
            netcdf_inc_path,netcdf_lib_path=findLibWithHeader(env, env['netcdf_libs'], 'ncVar.h', env['netcdf_prefix'], lang='c++')
        else:
            netcdf_inc_path,netcdf_lib_path=findLibWithHeader(env, env['netcdf_libs'], 'netcdfcpp.h', env['netcdf_prefix'], lang='c++')
        env.AppendUnique(CPPPATH = [netcdf_inc_path])
        env.AppendUnique(LIBPATH = [netcdf_lib_path])
        env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], netcdf_lib_path)
        env.Append(CPPDEFINES = ['ESYS_HAVE_NETCDF'])
        env['buildvars']['netcdf_inc_path']=netcdf_inc_path
        env['buildvars']['netcdf_lib_path']=netcdf_lib_path
    env['buildvars']['netcdf']=int(env['netcdf'])

    ######## PAPI
    papi_inc_path=''
    papi_lib_path=''
    if env['papi']:
        papi_inc_path,papi_lib_path=findLibWithHeader(env, env['papi_libs'], 'papi.h', env['papi_prefix'], lang='c++')
        env.AppendUnique(CPPPATH = [papi_inc_path])
        env.AppendUnique(LIBPATH = [papi_lib_path])
        env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], papi_lib_path)
        env.Append(CPPDEFINES = ['ESYS_HAVE_PAPI'])
        env['buildvars']['papi_inc_path']=papi_inc_path
        env['buildvars']['papi_lib_path']=papi_lib_path
    env['buildvars']['papi']=int(env['papi'])

    ######## MKL
    mkl_inc_path=''
    mkl_lib_path=''
    if env['mkl']:
        mkl_inc_path,mkl_lib_path=findLibWithHeader(env, env['mkl_libs'], 'mkl_pardiso.h', env['mkl_prefix'], lang='c++')
        env.AppendUnique(CPPPATH = [mkl_inc_path])
        env.AppendUnique(LIBPATH = [mkl_lib_path])
        env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], mkl_lib_path)
        env.Append(CPPDEFINES = ['ESYS_HAVE_MKL'])
        env['buildvars']['mkl_inc_path']=mkl_inc_path
        env['buildvars']['mkl_lib_path']=mkl_lib_path
    env['buildvars']['mkl']=int(env['mkl'])

    ######## UMFPACK
    umfpack_inc_path=''
    umfpack_lib_path=''
    if env['umfpack']:
        umfpack_inc_path,umfpack_lib_path=findLibWithHeader(env, env['umfpack_libs'], 'umfpack.h', env['umfpack_prefix'], lang='c++')
        env.AppendUnique(CPPPATH = [umfpack_inc_path])
        env.AppendUnique(LIBPATH = [umfpack_lib_path])
        env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], umfpack_lib_path)
        env.Append(CPPDEFINES = ['ESYS_HAVE_UMFPACK'])
        env['buildvars']['umfpack_inc_path']=umfpack_inc_path
        env['buildvars']['umfpack_lib_path']=umfpack_lib_path
    env['buildvars']['umfpack']=int(env['umfpack'])

    ######## LAPACK
    lapack_inc_path=''
    lapack_lib_path=''
    flavour = 'none'
    env['uselapack'] = False
    if env['lapack'] != 0:
        # not explicitly disabled so run the checks
        if env['longindices']:
            # you want longindices + lapack? sorry.
            if env['lapack'] == 1:
                print("LAPACK requires index type = int. Set longindices to False or disable LAPACK.")
                env.Exit(1)
        else:
            if env['mkl']:
                # we detected MKL so try the MKL header+libs
                flavour = 'mkl'
                header = 'mkl_lapack.h'
                prefix = env['mkl_prefix']
                if len(env['lapack_libs']) == 0:
                    libs = env['mkl_libs']
                else:
                    libs = env['lapack_libs']
            else:
                # try for clapack
                flavour = 'clapack'
                header = 'clapack.h'
                prefix = env['lapack_prefix']
                if len(env['lapack_libs']) == 0:
                    libs = ['lapack_atlas']
                else:
                    libs = env['lapack_libs']

            try:
                lapack_inc_path,lapack_lib_path=findLibWithHeader(env, libs, header, prefix, lang='c++')
                env['lapack_libs'] = libs
                env['uselapack'] = True
                env.AppendUnique(CPPPATH = [lapack_inc_path])
                env.AppendUnique(LIBPATH = [lapack_lib_path])
                env.Append(CPPDEFINES = ['ESYS_HAVE_LAPACK'])
                if flavour == 'mkl':
                    env.AppendUnique(CPPDEFINES = ['ESYS_MKL_LAPACK'])
                env['buildvars']['lapack_inc_path']=lapack_inc_path
                env['buildvars']['lapack_lib_path']=lapack_lib_path
            except:
                if env['lapack'] == 1:
                    raise
                # lapack was set to auto-detect so not a fatal error
                flavour = 'none'

    env['lapack'] = flavour
    env['buildvars']['lapack'] = flavour

    ######## Silo
    silo_inc_path=''
    silo_lib_path=''
    if env['silo']:
        silo_inc_path,silo_lib_path=findLibWithHeader(env, env['silo_libs'], 'silo.h', env['silo_prefix'], lang='c++')
        env.AppendUnique(CPPPATH = [silo_inc_path])
        env.AppendUnique(LIBPATH = [silo_lib_path])
        env.Append(CPPDEFINES = ['ESYS_HAVE_SILO'])
        env['buildvars']['silo_inc_path']=silo_inc_path
        env['buildvars']['silo_lib_path']=silo_lib_path
    env['buildvars']['silo']=int(env['silo'])

    ######## VisIt
    visit_inc_path=''
    visit_lib_path=''
    if env['visit']:
        visit_inc_path,visit_lib_path=findLibWithHeader(env, env['visit_libs'], 'VisItControlInterface_V2.h', env['visit_prefix'], lang='c++')
        env.AppendUnique(CPPPATH = [visit_inc_path])
        env.AppendUnique(LIBPATH = [visit_lib_path])
        env['buildvars']['visit_inc_path']=visit_inc_path
        env['buildvars']['visit_lib_path']=visit_lib_path
    env['buildvars']['visit']=int(env['visit'])

    ######## MPI
    if env['mpi']=='no':
        env['mpi']='none'

    env['usempi'] = env['mpi']!='none'
    mpi_inc_path=''
    mpi_lib_path=''
    if env['usempi']:
        mpi_inc_path,mpi_lib_path=findLibWithHeader(env, env['mpi_libs'], 'mpi.h', env['mpi_prefix'], lang='c++')
        env.AppendUnique(CPPPATH = [mpi_inc_path])
        env.AppendUnique(LIBPATH = [mpi_lib_path])
        env.AppendUnique(LIBS = env['mpi_libs'])
        env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], mpi_lib_path)
        env.Append(CPPDEFINES = ['ESYS_MPI', 'MPI_NO_CPPBIND', 'MPICH_IGNORE_CXX_SEEK'])
        # NetCDF 4.1 defines MPI_Comm et al. if MPI_INCLUDED is not defined!
        # On the other hand MPT and OpenMPI don't define the latter so we have
        # to do that here
        if env['netcdf'] and env['mpi'] in ['MPT','OPENMPI']:
            env.Append(CPPDEFINES = ['MPI_INCLUDED'])

        if env['mpi'] == 'OPENMPI':
            # try to get version for correct launcher arguments
            try:
                p = Popen(['orterun', '-V'], stdout=PIPE, stderr=PIPE)
                o,e = p.communicate()
                try:
                    ver = e.split('\n')[0].split()[-1]
                except IndexError:
                    ver = o.split('\n')[0].split()[-1]
                if len(ver) > 0:
                    env['orte_version'] = ver
            except OSError:
                pass

        env['buildvars']['mpi_inc_path']=mpi_inc_path
        env['buildvars']['mpi_lib_path']=mpi_lib_path
    env['buildvars']['mpi']=env['mpi']

    ######## BOOMERAMG
    if env['mpi'] == 'none': env['boomeramg'] = False
    boomeramg_inc_path=''
    boomeramg_lib_path=''
    if env['boomeramg']:
        boomeramg_inc_path,boomeramg_lib_path=findLibWithHeader(env, env['boomeramg_libs'], 'HYPRE.h', env['boomeramg_prefix'], lang='c++')
        env.AppendUnique(CPPPATH = [boomeramg_inc_path])
        env.AppendUnique(LIBPATH = [boomeramg_lib_path])
        env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], boomeramg_lib_path)
        env.Append(CPPDEFINES = ['ESYS_HAVE_BOOMERAMG'])
        env['buildvars']['boomeramg_inc_path']=boomeramg_inc_path
        env['buildvars']['boomeramg_lib_path']=boomeramg_lib_path
    env['buildvars']['boomeramg']=int(env['boomeramg'])

    ######## ParMETIS
    if not env['usempi']: env['parmetis'] = False
    parmetis_inc_path=''
    parmetis_lib_path=''
    if env['parmetis']:
        parmetis_inc_path,parmetis_lib_path=findLibWithHeader(env, env['parmetis_libs'], 'parmetis.h', env['parmetis_prefix'], lang='c++')
        env.AppendUnique(CPPPATH = [parmetis_inc_path])
        env.AppendUnique(LIBPATH = [parmetis_lib_path])
        env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], parmetis_lib_path)

        # Try to extract the parmetis version from parmetis.h
        header=open(os.path.join(parmetis_inc_path, 'parmetis.h')).readlines()
        major,minor,sub = None,None,None
        for line in header:
            ver=re.match(r'#define PARMETIS_MAJOR_VERSION\s*(\d+)',line)
            if ver:
                major = int(ver.group(1))
                continue
            ver=re.match(r'#define PARMETIS_MINOR_VERSION\s*(\d+)',line)
            if ver:
                minor = int(ver.group(1))
                continue
            ver=re.match(r'#define PARMETIS_SUBMINOR_VERSION\s*(\d+)',line)
            if ver:
                sub = int(ver.group(1))
                continue
        if major is not None:
            env['parmetis_version'] = "%d.%d.%d"%(major,minor,0 if sub is None else sub)
            if env['longindices']:
                # ParMETIS version 3.x does not support 64-bit indices
                if major < 4:
                    print("Sorry, cannot use ParMETIS version < 4.0 with 64-bit index types. Set longindices to False or disable ParMETIS.")
                    env.Exit(1)
                else:
                    # check if ParMETIS was built with 64-bit indices
                    conf = Configure(env.Clone())
                    idxsize=conf.CheckTypeSize('idx_t', '#include <parmetis.h>', 'C++')
                    if idxsize != 8:
                        print("Sorry, ParMETIS was not compiled with 64-bit indices. Set longindices to False or disable/rebuild ParMETIS.")
                        env.Exit(1)
        else:
            env['parmetis_version'] = "unknown"

        env.Append(CPPDEFINES = ['ESYS_HAVE_PARMETIS'])
        env['buildvars']['parmetis_inc_path']=parmetis_inc_path
        env['buildvars']['parmetis_lib_path']=parmetis_lib_path
    env['buildvars']['parmetis']=int(env['parmetis'])

    ######## gmsh (for tests)
    env['gmsh'] = False
    if env['IS_WINDOWS']:
        try:
            p=Popen(['gmsh', '-info'], stderr=PIPE)
            _,e=p.communicate()
            if e.split().count("MPI"):
                env['gmsh']='m'
            else:
                env['gmsh']='s'
        except OSError:
            pass
    else:
        which = Popen(['which', 'gmsh'], stdout=PIPE)
        path,_ = which.communicate()
        if which.wait() == 0:
            cmd = ['ldd', path[:-1]]
            if env['IS_OSX']:
                cmd = ['otool','-L', path[:-1]]
            try:
                p=Popen(cmd, stdout=PIPE)
                gmshlibs,_ = p.communicate()
                env.Append(CPPDEFINES=['ESYS_HAVE_GMSH'])
                if p.returncode == 0 and 'libmpi' in gmshlibs:
                    env['gmsh'] = 'm'
                    env.Append(CPPDEFINES=['ESYS_GMSH_MPI'])
                else:
                    env['gmsh'] = 's'
            except OSError:
                pass
    
    ######## boost::iostreams
    if env['compressed_files']:
        try:
            boost_inc_path, boost_lib_path = findLibWithHeader(env, env['compression_libs'], 'boost/iostreams/filter/gzip.hpp', env['boost_prefix'], lang='c++')
            env.Append(CPPDEFINES = ['ESYS_HAVE_BOOST_IO'])
        except RuntimeError as e:
            env['compressed_files'] = False
    env['buildvars']['compressed_files']=int(env['compressed_files'])

    ######## Trilinos
    env = checkForTrilinos(env)
    return env
Exemplo n.º 13
0
def checkForTrilinos(env):
    trilinos_inc_path = ''
    trilinos_lib_path = ''
    if env['trilinos']:
        havelibs = (len(env['trilinos_libs']) > 0)
        trilinos_inc_path, trilinos_lib_path = findLibWithHeader(
            env,
            env['trilinos_libs'],
            'Amesos2.hpp',
            env['trilinos_prefix'],
            lang='c++',
            try_link=havelibs)
        env.AppendUnique(CPPPATH=[trilinos_inc_path])
        env.AppendUnique(LIBPATH=[trilinos_lib_path])
        env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], trilinos_lib_path)
        env['buildvars']['trilinos_inc_path'] = trilinos_inc_path
        env['buildvars']['trilinos_lib_path'] = trilinos_lib_path
        conf = Configure(env.Clone())

        dependencies=['Amesos2.hpp','Amesos2_Solver_decl.hpp','BelosSolverFactory.hpp','BelosSolverManager.hpp',\
        'BelosTFQMRIter.hpp','BelosTFQMRSolMgr.hpp','BelosTpetraAdapter.hpp','BelosTypes.hpp',\
        'Ifpack2_Factory.hpp','Kokkos_DefaultNode.hpp',\
        'MatrixMarket_Tpetra.hpp','MueLu_CreateTpetraPreconditioner.hpp',\
        'Teuchos_DefaultComm.hpp','Teuchos_ParameterList.hpp',\
        'Tpetra_CrsGraph.hpp','Tpetra_CrsMatrix.hpp', 'Tpetra_RowMatrix.hpp',\
        'Tpetra_Vector.hpp','Trilinos_version.h']

        print("Looking for the Trilinos headers...")
        for check in dependencies:
            print("Checking for %s... %s" % (check, "yes" if os.path.isfile(
                os.path.join(trilinos_inc_path, check)) else "no"))
            if not os.path.isfile(os.path.join(trilinos_inc_path, check)):
                print(
                    "Could not find a Trilinos header file (tried looking in directory %s)"
                    % (trilinos_inc_path))
                env.Exit(1)

        if os.path.isfile(
                os.path.join(trilinos_inc_path, 'Tpetra_DefaultPlatform.hpp')):
            print("Checking for %s... %s" %
                  ('Tpetra_DefaultPlatform.hpp', "yes" if os.path.isfile(
                      os.path.join(trilinos_inc_path,
                                   'Tpetra_DefaultPlatform.hpp')) else "no"))
            env.Append(CPPDEFINES=['ESYS_HAVE_TPETRA_DP'])

        if os.path.isfile(
                os.path.join(trilinos_inc_path, 'Tpetra_BlockCrsMatrix.hpp')):
            print("Checking for %s... %s" %
                  ('Tpetra_BlockCrsMatrix.hpp', "yes" if os.path.isfile(
                      os.path.join(trilinos_inc_path,
                                   'Tpetra_DefaultPlatform.hpp')) else "no"))
        elif os.path.isfile(
                os.path.join(trilinos_inc_path,
                             'Tpetra_Experimental_BlockCrsMatrix.hpp')):
            print("Checking for %s... %s" %
                  ('Tpetra_Experimental_BlockCrsMatrix.hpp',
                   "yes" if os.path.isfile(
                       os.path.join(trilinos_inc_path,
                                    'Tpetra_DefaultPlatform.hpp')) else "no"))
            env.Append(CPPDEFINES=['ESYS_HAVE_TPETRA_EXPERIMENTAL_BLOCKCRS'])
        else:
            raise RuntimeError(
                'Could not locate the Trilinos Block CRS Matrix header')

        if os.path.isfile(
                os.path.join(trilinos_inc_path,
                             'Tpetra_BlockCrsMatrix_Helpers.hpp')):
            print(
                "Checking for %s... %s" %
                ('Tpetra_BlockCrsMatrix_Helpers.hpp', "yes" if os.path.isfile(
                    os.path.join(trilinos_inc_path,
                                 'Tpetra_DefaultPlatform.hpp')) else "no"))
        elif os.path.isfile(
                os.path.join(
                    trilinos_inc_path,
                    'Tpetra_Experimental_BlockCrsMatrix_Helpers.hpp')):
            print("Checking for %s... %s" %
                  ('Tpetra_Experimental_BlockCrsMatrix_Helpers.hpp',
                   "yes" if os.path.isfile(
                       os.path.join(trilinos_inc_path,
                                    'Tpetra_DefaultPlatform.hpp')) else "no"))
            env.Append(CPPDEFINES=['ESYS_HAVE_TPETRA_EXPERIMENTAL_BLOCKCRSH'])
        else:
            raise RuntimeError(
                'Could not locate the Trilinos Block CRS Matrix Helpers header'
            )

        if os.path.isfile(
                os.path.join(trilinos_inc_path, 'Tpetra_BlockVector.hpp')):
            print("Checking for %s... %s" %
                  ('Tpetra_BlockVector.hpp', "yes" if os.path.isfile(
                      os.path.join(trilinos_inc_path,
                                   'Tpetra_DefaultPlatform.hpp')) else "no"))
        elif os.path.isfile(
                os.path.join(trilinos_inc_path,
                             'Tpetra_Experimental_BlockVector.hpp')):
            print("Checking for %s... %s" %
                  ('Tpetra_Experimental_BlockVector.hpp',
                   "yes" if os.path.isfile(
                       os.path.join(trilinos_inc_path,
                                    'Tpetra_DefaultPlatform.hpp')) else "no"))
            env.Append(CPPDEFINES=['ESYS_HAVE_TPETRA_EXPERIMENTAL_BLOCKV'])
        else:
            raise RuntimeError(
                'Could not locate the Trilinos BlockVector header')

        # Try to extract the trilinos version from Trilinos_version.h
        versionh = open(os.path.join(trilinos_inc_path, 'Trilinos_version.h'))
        trilinos_version = 'unknown'
        env['trilinos_version'] = 'unknown'
        for line in versionh:
            ver = re.match(r'#define TRILINOS_MAJOR_MINOR_VERSION (\d+)', line)
            if ver:
                trilinos_version = ver.group(1)
                trilinos_version = int(trilinos_version)
                major = int(str(trilinos_version)[:2])
                minor = int(str(trilinos_version)[2:4])
                tmp = int(str(trilinos_version)[4:6])
                env['trilinos_version'] = str(major) + "." + str(
                    minor) + "." + str(tmp)

        if not havelibs:
            packages = [
                'Tpetra', 'Kokkos', 'Belos', 'Amesos2', 'Ifpack2', 'MueLu'
            ]
            libs = []
            for pk in packages:
                # find out what libraries to link with...
                makefile = os.path.join(trilinos_inc_path,
                                        'Makefile.export.%s' % pk)
                try:
                    for l in open(makefile, 'r').readlines():
                        if l.startswith(
                                "%s_LIBRARIES" % pk
                        ):  # or l.startswith("Trilinos_TPL_LIBRARIES"):
                            lst = l.split('=')[1].strip().split()
                            lst = [e.replace('-l', '', 1) for e in lst]
                            libs += lst
                        elif l.startswith("%s_TPL_INCLUDE_DIRS" % pk):
                            lst = l.split('=')[1].strip().split()
                            lst = [e.replace('-I', '', 1) for e in lst]
                            env.AppendUnique(CPPPATH=lst)

                except Exception as e:
                    raise RuntimeError(
                        'Error reading Trilinos export Makefile\n%s' % (e))
            env['trilinos_libs'] = libs

        env.Append(CPPDEFINES=['ESYS_HAVE_TRILINOS'])
        # env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], trilinos_lib_path)
        # env['buildvars']['trilinos_inc_path']=trilinos_inc_path
        # env['buildvars']['trilinos_lib_path']=trilinos_lib_path
    env['buildvars']['trilinos'] = int(env['trilinos'])
    return env
Exemplo n.º 14
0
def checkPython(env):
    # First we check to see if the config file has specified
    # where to find the file. Ideally, this should be automatic
    # but we need to deal with the case where python is not in its INSTALL
    # directory.
    # Use the python scons is running
    if env['pythoncmd'] == sys.executable:
        if env['IS_WINDOWS']:
            python_inc_path = sysconfig.get_python_inc()
            python_lib_path = os.path.join(sysconfig.get_config_var('prefix'),
                                           'libs')
            python_libs = [
                'python%s%s' % (sys.version_info[0], sys.version_info[1])
            ]
            verstring = ".".join([str(i) for i in sys.version_info[:3]])
        else:
            (python_lib_path, python_libs, verstring,
             python_inc_path) = call_python_config(env['pythoncmd'])

    # if we want to use a python other than the one scons is running
    # Note: we assume scons is running python 2 in the following.
    else:
        if env['IS_WINDOWS']:
            cmd = "import os, sys\n"
            cmd += "from distutils import sysconfig\n"
            cmd += "print(sysconfig.get_python_inc())\n"
            cmd += "print(os.path.join(sysconfig.get_config_var('prefix'), 'libs'))\n"
            cmd += "print('python%s%s'%(sys.version_info[0], sys.version_info[1]))\n"
            cmd += "print('.'.join([str(i) for i in sys.version_info[:3]]))"
            pout = subprocess.Popen([env['pythoncmd'], '-c', cmd],
                                    stdout=subprocess.PIPE).stdout.read()
            if isinstance(pout, bytes):
                pout = pout.decode(sys.stdout.encoding)
            lines = pout.split('\n')
            python_inc_path = lines[0].strip()
            python_lib_path = lines[1].strip()
            python_libs = [lines[2].strip()]
            verstring = lines[3].strip()
        else:
            (python_lib_path, python_libs, verstring,
             python_inc_path) = call_python_config(env['pythoncmd'])

    if sys.version_info[0] == 3:
        if isinstance(verstring, str) is False:
            verstring = str(verstring, 'utf-8')
    else:
        if isinstance(verstring, basestring) is False:
            verstring = str(verstring, 'utf-8')

    env['python_version'] = verstring
    try:
        ispython3 = (verstring[0] == '3')
    except:
        ispython3 = sys.version_info[0] == 3
    if ispython3:
        env.Append(CPPDEFINES=['ESPYTHON3'])
    env['buildvars']['python_version'] = verstring
    env['buildvars']['python'] = env['pythoncmd']
    # Check for an override from the config file.
    # Ideally, this should be automatic but we need to deal with the case
    # where python is not in its INSTALL directory
    if env['pythonlibpath'] != '':
        python_lib_path = env['pythonlibpath']

    if env['pythonincpath'] != '':
        python_inc_path = env['pythonincpath']

    if env['pythonlibname'] != '':
        python_libs = env['pythonlibname']

    conf = Configure(env.Clone())

    if env['sysheaderopt'] == '':
        conf.env.AppendUnique(CPPPATH=[python_inc_path])
    else:
        conf.env.Append(CCFLAGS=[env['sysheaderopt'], python_inc_path])

    conf.env.AppendUnique(LIBPATH=[python_lib_path])
    conf.env.AppendUnique(LIBS=python_libs)
    # The wrapper script needs to find the libs
    conf.env.PrependENVPath(env['LD_LIBRARY_PATH_KEY'], python_lib_path)

    if not conf.CheckCXXHeader('Python.h'):
        print(
            "Cannot find python include files (tried 'Python.h' in directory %s)"
            % (python_inc_path))
        env.Exit(1)
    if not conf.CheckFunc('Py_Exit', language='c++'):
        print(
            "Cannot find python library method Py_Exit (tried %s in directory %s)"
            % (python_libs, python_lib_path))
        env.Exit(1)

    return conf.Finish()