示例#1
0
def CheckOpenCL(ctx,
                write_config_h=False,
                add_to_compiler_env=False,
                min_version=None,
                max_version=None):
    ctx.Message('Checking for OpenCL Library... ')
    confprefix = getAutoconfPrefix(ctx.env)

    platform = ctx.env['PLATFORM']

    if min_version is not None:
        min_version = Version(min_version)
    if max_version is not None:
        max_version = Version(max_version)

    savedVars = ctx.env.SaveVars('LIBS FRAMEWORKS CPPPATH')

    ret = 0
    ctx.env.Append(LIBS=['OpenCL'])
    ret, outputStr = ctx.TryRun("""
   #include <CL/cl.h>

   int main(int argc, char** argv)
   {
   cl_uint numEntries=2;
   cl_platform_id platforms[2];
   cl_uint numPlatforms;

   clGetPlatformIDs(numEntries,
              (cl_platform_id*) platforms,
              &numPlatforms);

   printf("%d", CL_VERSION_1_0);
   return 0;
   }
   """,
                                extension='.c')

    ctx.env.RestoreVars(savedVars)

    # define
    # if ret:
    #   key = confprefix + 'HAVE_OPENCL'

    ctx.Result(ret)
    return ret
示例#2
0
def CheckOgre(ctx,
              write_config_h=False,
              add_to_compiler_env=False,
              min_version=None,
              max_version=None):
    ctx.Message('Checking for Ogre Library... ')
    confprefix = getAutoconfPrefix(ctx.env)

    platform = ctx.env['PLATFORM']

    if min_version is not None:
        min_version = Version(min_version)
    if max_version is not None:
        max_version = Version(max_version)

    savedVars = ctx.env.SaveVars('LIBS FRAMEWORKS CPPPATH')

    ctx.env.Replace(OGRE_INCLUDES=[])

    ret = 0

    if platform == 'win32':
        # on windows, Ogre include path should be in $PATH
        if ctx.env.IsMSVC_Debug():
            # debug version of library ends with '_d'
            ogreLibName = 'OgreMain_d'
        else:
            ogreLibName = 'OgreMain'
        ctx.env.Append(LIBS=[ogreLibName])
        ret, outputStr = ctx.TryRun("""
            #include <Ogre.h>
            #include <iostream>

            Ogre::Root* makeRoot() { return new Ogre::Root(""); }

            int main(int argc, char** argv)
            {
                std::cout<<OGRE_VERSION_MAJOR<<"."
                         <<OGRE_VERSION_MINOR<<"."
                         <<OGRE_VERSION_PATCH
                         <<std::endl;
                return 0;
            }
            """,
                                    extension='.cpp')

        if ret:
            ogreVersion = Version(outputStr)
            ctx.Message('version %s ' % ogreVersion)

            if ogreVersion.compatible(min_version, max_version):
                ogrePackage = ctx.env.DeclarePackage(
                    'ogre',
                    LIBS=[ogreLibName],
                    OGRE_VERSION=ogreVersion,
                    trigger_libs=['Ogre', 'OgreMain', 'ogre'])
            else:
                ctx.Message('is not within required [%s, %s] version range ' % \
                            (min_version, max_version))
                ret = 0

        ctx.env.RestoreVars(savedVars)

    else:

        # on linux, search in some common locations
        for includeDir in ('', '/usr/include/OGRE', '/usr/local/include/OGRE'):
            ctx.env.Append(LIBS=['OgreMain'])
            ctx.env.Append(CPPPATH=[includeDir])
            ret, outputStr = ctx.TryRun("""
                #include <Ogre.h>

                Ogre::Root* makeRoot() { return new Ogre::Root(""); }

                int main(int argc, char** argv)
                {
                    std::cout<<OGRE_VERSION_MAJOR<<"."
                             <<OGRE_VERSION_MINOR<<"."
                             <<OGRE_VERSION_PATCH
                             <<std::endl;
                    return 0;
                }
                """,
                                        extension='.cpp')

            ctx.env.RestoreVars(savedVars)

            if ret:
                ogreVersion = Version(outputStr)
                ctx.Message('version %s ' % ogreVersion)
                if ogreVersion.compatible(min_version, max_version):
                    ogrePackage = ctx.env.DeclarePackage(
                        'ogre',
                        CPPPATH=[includeDir],
                        LIBS=['OgreMain'],
                        OGRE_VERSION=ogreVersion,
                        trigger_libs=['Ogre', 'OgreMain', 'ogre'])
                    ctx.env.Replace(OGRE_INCLUDES=[includeDir])
                else:
                    ctx.Message(
                        'is not within required [%s, %s] version range ' % \
                        (min_version, max_version))
                    ret = 0
                break

    key = confprefix + 'HAVE_OGRE'
    if not (write_config_h and AddConfigKey(ctx, key, ret)):
        # no config file is specified or it is disabled, use compiler options
        if ret and add_to_compiler_env:
            ctx.env.Append(CPPDEFINES=[key])

    ctx.Result(ret)
    return ret
示例#3
0
def CheckAssimp(ctx,
                write_config_h=False,
                add_to_compiler_env=False,
                min_version=None,
                max_version=None):
    ctx.Message('Checking for Assimp library... ')
    confprefix = getAutoconfPrefix(ctx.env)

    compiler = ctx.env['compiler']
    platform = ctx.env['PLATFORM']
    isWin32 = (platform == 'win32')

    if min_version is not None:
        min_version = Version(min_version)
    if max_version is not None:
        max_version = Version(max_version)

    savedVars = ctx.env.SaveVars('LIBS FRAMEWORKS CCFLAGS')

    assimpLIBS = ['assimp']
    assimpCCFLAGS = []

    ctx.env.Append(LIBS=assimpLIBS)
    ctx.env.Append(CCFLAGS=assimpCCFLAGS)

    ret, outputStr = ctx.TryRun("""
#include "assimp.h"
#include "aiVersion.h"
#include <stdio.h>  
int main(int argc, char **argv) {
  printf("%i.%i.%i\\n", aiGetVersionMajor(), aiGetVersionMinor(), aiGetVersionRevision());
  return 0;
}
""",
                                extension='.c')

    if ret:
        assimpVersion = Version(outputStr.strip())
        ctx.Message('version %s ' % assimpVersion)

        if assimpVersion.compatible(min_version, max_version):
            ctx.env.DeclarePackage('assimp',
                                   LIBS=assimpLIBS,
                                   ASSIMP_VERSION=assimpVersion,
                                   CCFLAGS=assimpCCFLAGS,
                                   trigger_libs=['assimp'],
                                   trigger_frameworks=['assimp'])
        else:
            ctx.Message('is not within required [%s, %s] version range ' % \
                        (min_version, max_version))

            ret = 0

    ctx.env.RestoreVars(savedVars)

    key = confprefix + 'HAVE_ASSIMP'
    if not (write_config_h and AddConfigKey(ctx, key, ret)):
        # no config file is specified or it is disabled, use compiler options
        if ret and add_to_compiler_env:
            ctx.env.Append(CPPDEFINES=[key])

    ctx.Result(ret)
    return ret
示例#4
0
def CheckOpenImageIO(ctx, write_config_h=False, add_to_compiler_env=False,
                     min_version=None, max_version=None):
    ctx.Message('Checking for OpenImageIO... ')
    confprefix = getAutoconfPrefix(ctx.env)

    platform = ctx.env['PLATFORM']
    savedVars = ctx.env.SaveVars('LIBS FRAMEWORKS')

    lib = 'OpenImageIO'

    ctx.env.Append(LIBS = [lib])
    ctx.env.RequirePackage('dl')

    ret, outputStr = ctx.TryRun("""
    #include <OpenImageIO/imageio.h>
    #include <cstdio>

    int main(int argc, char** argv)
    {
      printf("%i\\n", OPENIMAGEIO_VERSION);
      return 0;
    }
    """, extension='.cpp')

    if ret:
        v = int(outputStr)
        vmajor = int(v / 10000)
        tmp = (v % 10000)
        vminor = int(tmp / 100)
        vpatch = tmp % 100

        libVersion = Version(vmajor, vminor, vpatch)

        if not libVersion.compatible(min_version, max_version):
            ctx.Message(
                'version %s is not within required [%s, %s] version range '\
                % (libVersion, min_version, max_version))
            ret = 0
        else:
            ret = ctx.TryLink("""
            #include <OpenImageIO/imageio.h>
            using namespace OpenImageIO;
            int main(int argc, char **argv) {
              const char *filename = "test.png";
              const float pixels[] = {0,1,0,1,0,0};
              ImageOutput *out = ImageOutput::create (filename);
              ImageSpec spec(sizeof(pixels)/sizeof(float), 1, 1, TypeDesc::FLOAT);
              out->open(filename, spec);
              out->write_image(TypeDesc::FLOAT, pixels);
              out->close();
              delete out;
              return 0;
            }
            """, extension='.cpp')

    ctx.env.RestoreVars(savedVars)

    if ret:
        ctx.Message('version %s ' % libVersion)
        ctx.env.Replace(LIBOPENIMAGEIO=[lib])
        vars = {'LIBS' : [lib],
                'LIBOPENIMAGEIO_VERSION' : libVersion}
        ctx.env.DeclarePackage('openimageio',
                               LIBS=[lib],
                               vars=vars,
                               dependencies=['dl'],
                               trigger_libs=['OpenImageIO', 'openimageio'])


    key = confprefix+'HAVE_LIBOPENIMAGEIO'
    if not (write_config_h and AddConfigKey(ctx, key, ret)):
        # no config file is specified or it is disabled, use compiler options
        if ret and add_to_compiler_env:
            ctx.env.Append(CPPDEFINES=[key])

    ctx.Result(ret)
    return ret
示例#5
0
def CheckOptix(ctx,
               write_config_h=False,
               add_to_compiler_env=False,
               min_version=None,
               max_version=None):
    ctx.Message('Checking for Optix Library... ')
    confprefix = getAutoconfPrefix(ctx.env)
    key = confprefix + 'HAVE_OPTIX'

    platform = ctx.env['PLATFORM']
    archInfo = getArchInfo(ctx.env)

    # If CUDA is not available Optix cannot be used
    if not ctx.env.GetPackage('cuda'):
        ctx.Message('No CUDA detected, call CheckCUDA first')
        if write_config_h:
            AddConfigKey(ctx, key, 0)
        ctx.Result(0)
        return 0

    isWin32 = platform == 'win32'
    isX64 = archInfo.getArchID() == ARCH_X86_64

    if min_version is not None:
        min_version = Version(min_version)
    if max_version is not None:
        max_version = Version(max_version)

    # RequirePackage('cuda') will add all libraries needed for linking with
    # CUDA and return dictionary of all modified variables with original
    # values.
    savedVars = ctx.env.RequirePackage('cuda')

    # detect common locations
    commonLocations = [None]  # default location
    paths = ctx.env.Glob(
        os.path.join(os.path.expanduser('~'), 'NVIDIA-OptiX-SDK*'))
    for p in paths:
        if os.path.exists(p.Dir('include').File('optix.h').abspath):
            commonLocations.append(p)

    ret = 0

    for location in commonLocations:

        ctx.env.RestoreVars(savedVars)

        ctx.env.RequirePackage('cuda')

        ctx.env.Append(LIBS=['optix'])
        vars = {'LIBS': ['optix']}

        if location is not None:
            includeDir = str(location.Dir('include'))
            ctx.env.Append(CPPPATH=[includeDir])
            vars['CPPPATH'] = [includeDir]
            if isX64:
                lib64Dir = str(location.Dir('lib64'))
                ctx.env.Append(LIBPATH=[lib64Dir])
                vars['LIBPATH'] = [lib64Dir]
            else:
                libDir = str(location.Dir('lib'))
                ctx.env.Append(LIBPATH=[libDir])
                vars['LIBPATH'] = [libDir]

        ret, outputStr = ctx.TryRun("""
        #include <stdio.h>
        #include <optix.h>

        int main(int argc, char** argv)
        {
          printf("%i\\n", OPTIX_VERSION);
          return 0;
        }
        """,
                                    extension='.c')

        if ret:
            v = int(outputStr)
            vmajor = int(v / 1000)
            vminor = (v % 1000) / 10
            vmicro = v % 10

            libVersion = Version(vmajor, vminor, vmicro)

            if not libVersion.compatible(min_version, max_version):
                ctx.Message('version %s is not within required [%s, %s] version range ' % \
                            (libVersion, min_version, max_version))
                ret = 0
                continue

            ctx.Message('version %s ' % libVersion)

            # check for optixu/optixpp
            ret = ctx.TryLink("""
            #include <optixu/optixu_matrix.h>

            int main(int argc, char** argv)
            {
              optix::Matrix3x3 matrix;
              return 0;
            }
            """,
                              extension='.cpp')

            if not ret:
                ctx.Message('could not link with optixu library')
                ret = 0
                continue

            ctx.env.RestoreVars(savedVars)

            vars['OPTIX_VERSION'] = libVersion
            libPackage = ctx.env.DeclarePackage(
                'optix',
                vars=vars,
                dependencies=['cuda'],
                trigger_libs=['optix', 'Optix'])
            break

    if not (write_config_h and AddConfigKey(ctx, key, ret)):
        # no config file is specified or it is disabled, use compiler options
        if ret and add_to_compiler_env:
            ctx.env.Append(CPPDEFINES=[key])

    ctx.Result(ret)
    return ret
示例#6
0
def CheckLLVM(ctx,
              write_config_h=True,
              add_to_cppdefines=False,
              llvm_tools_required=True,
              use_clang_if_available=False,
              min_version=None,
              max_version=None):
    ctx.Message('Checking for LLVM library... ')
    confprefix = getAutoconfPrefix(ctx.env)
    platform = ctx.env['PLATFORM']

    if platform == 'win32':
        savedVars = ctx.env.SaveVars('LIBS FRAMEWORKS')

        llvmlibs = [
            'LLVMJIT.lib', 'LLVMCodeGen.lib', 'LLVMCore.lib',
            'LLVMSupport.lib', 'LLVMTarget.lib', 'LLVMInterpreter.lib',
            'LLVMExecutionEngine.lib', 'LLVMX86CodeGen.lib',
            'LLVMSelectionDAG.lib', 'LLVMAnalysis.lib', 'LLVMScalarOpts.lib',
            'LLVMTransformUtils.lib', 'LLVMipa.lib', 'LLVMAsmPrinter.lib',
            'LLVMBitReader.lib', 'LLVMBitWriter.lib',
            'LLVMInstrumentation.lib', 'LLVMipo.lib', 'LLVMLinker.lib',
            'LLVMX86AsmPrinter.lib', 'LLVMAsmParser.lib', 'LLVMArchive.lib',
            'LLVMX86Info.lib', 'LLVMInstCombine.lib', 'Shell32.lib',
            'Advapi32.lib', 'LLVMX86Utils.lib', 'LLVMMC.lib'
        ]
        #llvmlibs = ['LLVMSystem']

        ctx.env.Append(LIBS=llvmlibs)
        ret = ctx.TryLink("""
            #include <llvm/Config/llvm-config.h>
            #if (LLVM_VERSION_MAJOR >= 3 && LLVM_VERSION_MINOR >= 3)
            #include <llvm/IR/Module.h>
            #include <llvm/IR/LLVMContext.h>
            #else
            #include <llvm/Module.h>
            #include <llvm/LLVMContext.h>
            #endif

            int main(int argc, char **argv)
            {
                llvm::Module *module = new llvm::Module("test", llvm::getGlobalContext());
                return 0;
            }
            """,
                          extension='.cpp')

        ctx.env.RestoreVars(savedVars)

        if ret:
            ctx.env.DeclarePackage('llvm',
                                   trigger_libs=['LLVM'],
                                   trigger_frameworks=['LLVM'],
                                   LLVM_VERSION=None,
                                   LLVM_VERSION_SUFFIX=None,
                                   LIBS=llvmlibs)
            ctx.env.Replace(LIBLLVM=llvmlibs)

    else:
        ret, output = ctx.TryAction('llvm-config --version')
        if ret:

            vars = ctx.env.ParseFlags(
                '!llvm-config --cflags --libs && llvm-config --ldflags')

            # filter out -fomit-frame-pointer and -O3
            vars['CCFLAGS'] = [k for k in vars['CCFLAGS']              \
                               if k not in ('-fomit-frame-pointer',    \
                                            '-O', '-O1', '-O2', '-O3')]

            # Save cxxflags configuration
            vars['LLVM_CONFIG_CXXFLAGS'] = ctx.env.ParseFlags(
                '!llvm-config --cxxflags')

            ctx.env.DeclarePackage('llvm',
                                   vars=vars,
                                   trigger_libs=['LLVM'],
                                   trigger_frameworks=['LLVM'],
                                   LLVM_VERSION=None,
                                   LLVM_VERSION_SUFFIX=None)

            ctx.env.Append(CPPPATH=vars.get('CPPPATH'))
            ctx.env.Append(LIBPATH=vars.get('LIBPATH'))
            ctx.env.Replace(LIBLLVM=vars.get('LIBS'))

    # check availability of the internal debug flag
    if ret:
        savedVars = ctx.env.RequirePackage('llvm')

        hasDebugFlag = ctx.TryLink("""
            #undef NDEBUG
            #include <llvm/Support/Debug.h>

            int main(int argc, char **argv)
            {
                llvm::DebugFlag = true;
                return 0;
            }
            """,
                                   extension='.cpp')

        ctx.env.RestoreVars(savedVars)
        ctx.env.Replace(LLVM_HAS_DEBUGFLAG=hasDebugFlag)
    else:
        ctx.env.Replace(LLVM_HAS_DEBUGFLAG=0)

    # try to get version
    if ret:
        savedVars = ctx.env.RequirePackage('llvm')

        ret1, outputStr = ctx.TryRun("""
            #include <llvm/Config/config.h>
            #include <cstdio>

            int main(int argc, char **argv)
            {
                printf("%s\\n", PACKAGE_VERSION);
                return 0;
            }
            """,
                                     extension='.cpp')

        ctx.env.RestoreVars(savedVars)

        LLVM_PACKAGE_VERSION = outputStr.strip()
    else:
        LLVM_PACKAGE_VERSION = None

    ctx.env.Replace(LLVM_PACKAGE_VERSION=LLVM_PACKAGE_VERSION)

    # Split llvm package version into numeric part and suffix
    LLVM_VERSION = None
    LLVM_VERSION_SUFFIX = None
    if LLVM_PACKAGE_VERSION is not None:
        ctx.Message('version %s ' % LLVM_PACKAGE_VERSION)
        m = re.search(r'([0-9]+(?:\.(?:[0-9]+))*)(.*)', LLVM_PACKAGE_VERSION)
        if m:
            LLVM_VERSION = Version(m.group(1))
            LLVM_VERSION_SUFFIX = m.group(2)

    if ret and (min_version is not None or max_version is not None):
        if LLVM_VERSION:
            if not LLVM_VERSION.compatible(min_version, max_version):
                ctx.Message(
                    'version %s is not within required [%s, %s] version range '\
                        % (LLVM_VERSION, min_version, max_version))
                ret = False
        else:
            ctx.Message(
                'could not detect LLVM version, required version is [%s, %s]'\
                    % (min_version, max_version))
            ctx.env.RemovePackage('llvm')
            ret = False

    if ret and LLVM_PACKAGE_VERSION:
        llvmpkg = ctx.env.GetPackage('llvm')

        # try shared library variant
        savedVars = ctx.env.SaveVars(
            'LIBS FRAMEWORKS CCFLAGS CFLAGS CPPDEFINES')

        llvmlibs = ['LLVM-' + LLVM_PACKAGE_VERSION]
        vars = {}
        for k in ('CCFLAGS', 'CFLAGS', 'CPPDEFINES'):
            if (k in llvmpkg.vars):
                value = llvmpkg.vars[k]
                vars[k] = value
        llvmpkg.vars['LLVM_VERSION'] = LLVM_VERSION
        llvmpkg.vars['LLVM_VERSION_SUFFIX'] = LLVM_VERSION_SUFFIX
        ctx.env.Append(LIBS=llvmlibs)
        ctx.env.Append(**vars)
        dyn_ret = ctx.TryLink("""
            #include <llvm/Config/llvm-config.h>
            #if (LLVM_VERSION_MAJOR >= 3 && LLVM_VERSION_MINOR >= 3)
            #include <llvm/IR/Module.h>
            #include <llvm/IR/LLVMContext.h>
            #else
            #include <llvm/Module.h>
            #include <llvm/LLVMContext.h>
            #endif

            int main(int argc, char **argv)
            {
                llvm::Module *module = new llvm::Module("test", llvm::getGlobalContext());
                return 0;
            }
            """,
                              extension='.cpp')

        ctx.env.RestoreVars(savedVars)

        if platform == 'win32':
            if LLVM_VERSION >= Version(3, 0):
                libs = [
                    'LLVMMCDisassembler.lib', 'LLVMX86Desc.lib',
                    'LLVMX86AsmParser.lib', 'LLVMMCParser.lib'
                ]
                llvmpkg.vars['LIBS'].extend(libs)
            if LLVM_VERSION >= Version(3, 1):
                libs = [
                    'LLVMMCJIT.lib', 'LLVMRuntimeDyld.lib', 'LLVMObject.lib',
                    'LLVMVectorize.lib'
                ]
                llvmpkg.vars['LIBS'].extend(libs)
            if LLVM_VERSION >= Version(3, 3):
                libs = [
                    'LLVMIRReader.lib', 'LLVMObjCARCOpts.lib',
                    'LLVMXCoreAsmPrinter.lib', 'LLVMXCoreCodeGen.lib',
                    'LLVMXCoreDesc.lib', 'LLVMXCoreDisassembler.lib',
                    'LLVMXCoreInfo.lib', 'LLVMSystemZAsmParser.lib',
                    'LLVMSystemZAsmPrinter.lib', 'LLVMSystemZCodeGen.lib',
                    'LLVMSystemZDesc.lib', 'LLVMSystemZInfo.lib',
                    'LLVMSparcCodeGen.lib', 'LLVMSparcDesc.lib',
                    'LLVMSparcInfo.lib', 'LLVMPowerPCAsmParser.lib',
                    'LLVMPowerPCAsmPrinter.lib', 'LLVMPowerPCCodeGen.lib',
                    'LLVMPowerPCDesc.lib', 'LLVMPowerPCInfo.lib',
                    'LLVMNVPTXAsmPrinter.lib', 'LLVMNVPTXCodeGen.lib',
                    'LLVMNVPTXDesc.lib', 'LLVMNVPTXInfo.lib',
                    'LLVMMSP430AsmPrinter.lib', 'LLVMMSP430CodeGen.lib',
                    'LLVMMSP430Desc.lib', 'LLVMMSP430Info.lib',
                    'LLVMMBlazeAsmParser.lib', 'LLVMMBlazeAsmPrinter.lib',
                    'LLVMMBlazeCodeGen.lib', 'LLVMMBlazeDesc.lib',
                    'LLVMMBlazeDisassembler.lib', 'LLVMMBlazeInfo.lib',
                    'LLVMMipsAsmParser.lib', 'LLVMMipsAsmPrinter.lib',
                    'LLVMMipsCodeGen.lib', 'LLVMMipsDesc.lib',
                    'LLVMMipsDisassembler.lib', 'LLVMMipsInfo.lib',
                    'LLVMHexagonAsmPrinter.lib', 'LLVMHexagonCodeGen.lib',
                    'LLVMHexagonDesc.lib', 'LLVMHexagonInfo.lib',
                    'LLVMCppBackendCodeGen.lib', 'LLVMCppBackendInfo.lib',
                    'LLVMARMAsmParser.lib', 'LLVMARMAsmPrinter.lib',
                    'LLVMARMCodeGen.lib', 'LLVMARMDesc.lib',
                    'LLVMARMDisassembler.lib', 'LLVMARMInfo.lib',
                    'LLVMAArch64AsmParser.lib', 'LLVMAArch64AsmPrinter.lib',
                    'LLVMAArch64CodeGen.lib', 'LLVMAArch64Desc.lib',
                    'LLVMAArch64Disassembler.lib', 'LLVMAArch64Info.lib',
                    'LLVMAArch64Utils.lib'
                ]
                llvmpkg.vars['LIBS'].extend(libs)

        if dyn_ret:
            ctx.env.DeclarePackage('llvm_shared',
                                   vars=vars,
                                   trigger_libs=['LLVM_shared'],
                                   trigger_frameworks=['LLVM_shared'],
                                   LIBS=llvmlibs)
            ctx.env.Replace(LIBLLVM_SHARED=llvmlibs)

    # Try to setup LLVM tools
    if ret:
        if exists(ctx.env):
            have_clang = ctx.env.Detect('clang') and ctx.env.Detect('clang++')
            have_llvm_gcc = ctx.env.Detect('llvm-gcc') and ctx.env.Detect(
                'llvm-g++')

            generate(ctx.env, use_clang=have_clang and use_clang_if_available)

            ctx.env.Replace(HAVE_LLVMTOOLS=1)
            if have_clang:
                ctx.env.Replace(HAVE_CLANG_COMPILER=1)
            else:
                ctx.env.Replace(HAVE_CLANG_COMPILER=0)
            if have_llvm_gcc:
                ctx.env.Replace(HAVE_LLVM_GCC_COMPILER=1)
            else:
                ctx.env.Replace(HAVE_LLVM_GCC_COMPILER=0)
        else:
            ctx.Message(
                'LLVM tools (llvm-gcc, llvm-g++, clang, clang++, llvm-link, opt) not found'
            )
            if llvm_tools_required:
                ret = False
            ctx.env.Replace(HAVE_LLVMTOOLS=0)

    key = confprefix + 'HAVE_LIBLLVM'
    if not (write_config_h and AddConfigKey(ctx, key, ret)):
        # no config file is specified or it is disabled, use compiler options
        if ret and add_to_cppdefines:
            ctx.env.Append(CPPDEFINES=[key])

    ctx.Result(ret)
    return ret
示例#7
0
def CheckTBB(ctx,
             write_config_h=False,
             add_to_compiler_env=False,
             min_version=None,
             max_version=None):
    ctx.Message('Checking for TBB Library... ')
    confprefix = getAutoconfPrefix(ctx.env)

    platform = ctx.env['PLATFORM']

    if min_version is not None:
        min_version = Version(min_version)
    if max_version is not None:
        max_version = Version(max_version)

    savedVars = ctx.env.SaveVars('LIBS FRAMEWORKS CPPPATH')

    ret = 0

    if platform == 'win32':
        # on windows, TBB include path should be in $PATH
        if ctx.env.IsMSVC_Debug():
            # debug version of library ends with '_debug'
            tbbLibName = 'tbb_debug'
        else:
            tbbLibName = 'tbb'
        ctx.env.Append(LIBS=[tbbLibName])
        ret, outputStr = ctx.TryRun("""
            #include <tbb/tbb_stddef.h>
            #include <tbb/task_scheduler_init.h>
            #include <iostream>

            void test() { tbb::task_scheduler_init init; }

            int main(int argc, char** argv)
            {
            #if defined(TBB_VERSION_MAJOR) && defined(TBB_VERSION_MINOR) && defined(TBB_INTERFACE_VERSION)
                std::cout<<TBB_VERSION_MAJOR<<"."
                         <<TBB_VERSION_MINOR<<"."
                         <<TBB_INTERFACE_VERSION
                         <<std::endl;
            #else
                // Version is not defined, we assume 2.0
                std::cout<<"2.0"<<std::endl;
            #endif
                return 0;
            }
            """,
                                    extension='.cpp')

        if ret:
            tbbVersion = Version(outputStr)
            ctx.Message('version %s ' % tbbVersion)

            if tbbVersion.compatible(min_version, max_version):
                tbbPackage = ctx.env.DeclarePackage(
                    'tbb',
                    LIBS=[tbbLibName],
                    TBB_VERSION=tbbVersion,
                    trigger_libs=['tbb', 'TBB'])
            else:
                ctx.Message('is not within required [%s, %s] version range ' % \
                            (min_version, max_version))
                ret = 0

        ctx.env.RestoreVars(savedVars)

    else:

        # on linux, search in some common locations
        for includeDir in ('', ):
            ctx.env.Append(LIBS=['tbb'])
            ctx.env.Append(CPPPATH=[includeDir])
            ret, outputStr = ctx.TryRun("""
                #include <tbb/tbb_stddef.h>
                #include <tbb/task_scheduler_init.h>
                #include <iostream>

                void test() { tbb::task_scheduler_init init; }

                int main(int argc, char** argv)
                {
                #if defined(TBB_VERSION_MAJOR) && defined(TBB_VERSION_MINOR) && defined(TBB_INTERFACE_VERSION)
                    std::cout<<TBB_VERSION_MAJOR<<"."
                             <<TBB_VERSION_MINOR<<"."
                             <<TBB_INTERFACE_VERSION
                             <<std::endl;
                #else
                    // Version is not defined, we assume 2.0
                    std::cout<<"2.0"<<std::endl;
                #endif
                    return 0;
                }
            """,
                                        extension='.cpp')

            ctx.env.RestoreVars(savedVars)

            if ret:
                tbbVersion = Version(outputStr)
                ctx.Message('version %s ' % tbbVersion)
                if tbbVersion.compatible(min_version, max_version):
                    tbbPackage = ctx.env.DeclarePackage(
                        'tbb',
                        CPPPATH=[includeDir],
                        LIBS=['tbb'],
                        TBB_VERSION=tbbVersion,
                        trigger_libs=['tbb', 'TBB'])
                else:
                    ctx.Message(
                        'is not within required [%s, %s] version range ' % \
                        (min_version, max_version))
                    ret = 0
                break

    key = confprefix + 'HAVE_TBB'
    if not (write_config_h and AddConfigKey(ctx, key, ret)):
        # no config file is specified or it is disabled, use compiler options
        if ret and add_to_compiler_env:
            ctx.env.Append(CPPDEFINES=[key])

    ctx.Result(ret)
    return ret
示例#8
0
def CheckCUDA(ctx,
              write_config_h=False,
              add_to_compiler_env=False,
              min_version=None,
              max_version=None):
    ctx.Message('Checking for CUDA Library... ')
    confprefix = getAutoconfPrefix(ctx.env)

    platform = ctx.env['PLATFORM']
    archInfo = getArchInfo(ctx.env)

    isWin32 = platform == 'win32'
    isX64 = archInfo.getArchID() == ARCH_X86_64

    if min_version is not None:
        min_version = Version(min_version)
    if max_version is not None:
        max_version = Version(max_version)

    savedVars = ctx.env.SaveVars('LIBS FRAMEWORKS CPPPATH')

    # detect common locations
    commonLocations = [None]  # default location
    paths = []

    if not isWin32:
        # default search path on *ix
        paths.append(ctx.env.Dir('/usr/local/cuda'))

    for p in paths:
        if os.path.exists(p.Dir('include').File('cuda.h').abspath):
            commonLocations.append(p)

    ret = 0

    for location in commonLocations:

        ctx.env.RestoreVars(savedVars)

        ctx.env.Append(LIBS=['cuda'])
        vars = {'LIBS': ['cuda']}

        if location is not None:
            includeDir = str(location.Dir('include'))
            ctx.env.Append(CPPPATH=[includeDir])
            vars['CPPPATH'] = [includeDir]

            if isX64:
                lib64Dir = str(location.Dir('lib64'))
                ctx.env.Append(LIBPATH=[lib64Dir])
                vars['LIBPATH'] = [lib64Dir]
            else:
                libDir = str(location.Dir('lib'))
                ctx.env.Append(LIBPATH=[libDir])
                vars['LIBPATH'] = [libDir]

        ret, outputStr = ctx.TryRun("""
        #include <stdio.h>
        #include <cuda.h>

        int main(int argc, char** argv)
        {
          printf("%i\\n", CUDA_VERSION);
          return 0;
        }
        """,
                                    extension='.c')

        if ret:
            v = int(outputStr)
            vmajor = int(v / 1000)
            vminor = (v % 1000) / 10

            libVersion = Version(vmajor, vminor)

            if not libVersion.compatible(min_version, max_version):
                ctx.Message(
                    'version %s is not within required [%s, %s] version range '\
                    % (libVersion, min_version, max_version))
                ret = 0
                continue

            # check for CUDA SDK
            ret = ctx.TryLink("""
            #include <vector_functions.h>

            int main(int argc, char** argv)
            {
              return 0;
            }
            """,
                              extension='.cpp')

            if not ret:
                ret = 0
                continue

            ctx.env.RestoreVars(savedVars)

            ctx.Message('version %s ' % libVersion)

            vars['CUDA_VERSION'] = libVersion
            libPackage = ctx.env.DeclarePackage('cuda',
                                                vars=vars,
                                                trigger_libs=['cuda', 'CUDA'])
            break

    ctx.env.RestoreVars(savedVars)

    key = confprefix + 'HAVE_CUDA'
    if not (write_config_h and AddConfigKey(ctx, key, ret)):
        # no config file is specified or it is disabled, use compiler options
        if ret and add_to_compiler_env:
            ctx.env.Append(CPPDEFINES=[key])

    ctx.Result(ret)
    return ret