How to use the pkgconfig.exists function in pkgconfig

To help you get started, we’ve selected a few pkgconfig examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github matze / pkgconfig / test_pkgconfig.py View on Github external
def test_exists():
    assert pkgconfig.exists(PACKAGE_NAME)
    assert pkgconfig.exists('fake-openssl')
github omni-us / pagexml / py-pagexml / setup.py View on Github external
def pagexml_Extension(magick):
    import pkgconfig
    libs = ['opencv','libxml-2.0','libxslt','gdal']
    if magick:
        libs += ['Magick++']
    compile_args = ['-std=c++11']
    link_args = []
    for lib in libs:
        if not pkgconfig.exists(lib):
            raise FileNotFoundError('pkgconfig did not find '+lib)
        compile_args += pkgconfig.cflags(lib).split()
        link_args += pkgconfig.libs(lib).split()
    #compile_args += pkgconfig.cflags('opencv').split()
    #cvre = re.compile('^-L|^-lopencv_core|^-lopencv_imgproc|^-lopencv_imgcodecs|^-lopencv_highgui')
    #link_args += [x for x in pkgconfig.libs('opencv').split() if cvre.match(x)]
    cvinc = pkgconfig.cflags('opencv').split()[0].rsplit('/opencv',1)[0]
    defimage = '__PAGEXML_IMG_MAGICK__' if magick else '__PAGEXML_IMG_CV__'
    pageimage = 'Magick::Image' if magick else 'cv::Mat'
    define_macros = [('__PAGEXML_OGR__',''),(defimage,'')] + ( [('__PAGEXML_MAGICK__','')] if magick else [] )
    swig_opts = ['-D__PAGEXML_OGR__','-D'+defimage,'-DPageImage='+pageimage] + ( ['-D__PAGEXML_MAGICK__'] if magick else [] )
    print('pagexml_Extension configured with '+defimage)
    return Extension('_pagexml',
                     define_macros = define_macros + [('SWIG_PYTHON_SILENT_MEMLEAK','')],
                     extra_compile_args = compile_args,
                     extra_link_args = link_args,
github omni-us / pagexml / py-textfeat / setup.py View on Github external
def textfeat_Extension(magick=False):
    import pkgconfig
    libs = ['opencv','libxml-2.0','Magick++']
    compile_args = ['-std=c++11']
    link_args = []
    for lib in libs:
        if not pkgconfig.exists(lib):
            raise FileNotFoundError('pkgconfig did not find '+lib)
        compile_args += pkgconfig.cflags(lib).split()
        link_args += pkgconfig.libs(lib).split()
    #compile_args += pkgconfig.cflags('opencv').split()
    #cvre = re.compile('^-L|^-lopencv_core|^-lopencv_imgproc|^-lopencv_imgcodecs|^-lopencv_flann')
    #link_args += [x for x in pkgconfig.libs('opencv').split() if cvre.match(x)]
    cvinc = pkgconfig.cflags('opencv').split()[0].rsplit('/opencv',1)[0]
    defimage = '__PAGEXML_IMG_MAGICK__' if magick else '__PAGEXML_IMG_CV__'
    pageimage = 'Magick::Image' if magick else 'cv::Mat'
    define_macros = [(defimage,''),('__PAGEXML_MAGICK__','')]
    swig_opts = ['-D'+defimage,'-DPageImage='+pageimage,'-D__PAGEXML_MAGICK__']
    print('textfeat_Extension configured with '+defimage)
    return Extension('_textfeat',
                     define_macros = define_macros + [('SWIG_PYTHON_SILENT_MEMLEAK','')],
                     extra_compile_args = compile_args,
                     extra_link_args = link_args,
github limbo018 / DREAMPlace / dreamplace / ops / draw_place / src / setup.py View on Github external
from torch.utils.cpp_extension import BuildExtension, CppExtension, CUDAExtension

import os 
import sys
import pkgconfig

boost_dir = os.environ['BOOST_DIR']
limbo_dir = os.environ['LIMBO_DIR']
utility_dir = os.environ['UTILITY_DIR']
ops_dir = os.environ['OPS_DIR']

include_dirs = [os.path.join(os.path.abspath(boost_dir), 'include'), os.path.join(os.path.abspath(limbo_dir), 'include'), os.path.abspath(ops_dir)]
lib_dirs = [os.path.join(os.path.abspath(boost_dir), 'lib'), os.path.join(os.path.abspath(limbo_dir), 'lib'), utility_dir]
libs = ['gdsparser', 'boost_iostreams', 'z', 'utility'] 

if pkgconfig.exists('cairo'):
    print("found cairo and enable")
    include_dirs.append(pkgconfig.cflags('cairo')[2:])
    libs.append(pkgconfig.libs('cairo')[2:])
    cairo_compile_args = '-DDRAWPLACE=1'
else:
    print("not found cairo and disable")
    cairo_compile_args = '-DDRAWPLACE=0'

tokens = str(torch.__version__).split('.')
torch_major_version = "-DTORCH_MAJOR_VERSION=%d" % (int(tokens[0]))
torch_minor_version = "-DTORCH_MINOR_VERSION=%d" % (int(tokens[1]))

setup(
        name='draw_place',
        ext_modules=[
            CppExtension('draw_place_cpp',
github libvips / pyvips / pyvips / pyvips_build.py View on Github external
import pkgconfig

# we must have the vips package to be able to do anything
if not pkgconfig.exists('vips'): 
    raise Exception('unable to find pkg-config package "vips"')
if pkgconfig.installed('vips', '< 8.2'):
    raise Exception('pkg-config "vips" is too old -- need libvips 8.2 or later')

from cffi import FFI

ffibuilder = FFI()

# this is very hacky ... cffi in API mode won't let us cast function pointers,
# so we can't pass vips_free() as a vipsCallbackFn, which we need to be able to
# do when we set a blob
# 
# to fix this, we rename vips_free during the vips header load as
# real_vips_free, then declare a fake type ourselves that decl.py then hooks up
# to
github aherlihy / Monary / setup.py View on Github external
# Use pkg-config to find location of libbson and libmongoc.
try:
    import pkgconfig
except ImportError:
    # Set to default locations for libmongoc and libbson.
    warnings.warn(("WARNING: the python package pkgconfig is not installed. "
                   "If you have pkg-config installed on your system, please "
                   "install the python's pkgconfig, e.g. \"pip install "
                   "pkgconfig\". Will use libmongoc=%s and libbson=%s instead."
                   % (mongoc_src, bson_src)))

else:
    try:
        # Use pkgconfig to find location of libmongoc or libbson.
        if pkgconfig.exists("libmongoc-1.0"):
            pkgcfg = pkgconfig.parse("libmongoc-1.0")
            settings['include_dirs'] = list(pkgcfg['include_dirs'])
            settings['library_dirs'] = list(pkgcfg['library_dirs'])
            settings['libraries'] = list(pkgcfg['libraries'])
            settings['define_macros'] = list(pkgcfg['define_macros'])
        else:
            warnings.warn(("WARNING: unable to find libmongoc-1.0 with "
                           "pkgconfig. Please check that PKG_CONFIG_PATH is "
                           "set to a path that can find the .pc files for "
                           "libbson and libmongoc. Will use libmongoc=%s and "
                           "libbson=%s instead." % (mongoc_src, bson_src)))
    except EnvironmentError:
        warnings.warn(("WARNING: the system tool pkg-config is not installed. "
                      "Will use libmongoc=%s and libbson=%s instead."
                       % (mongoc_src, bson_src)))
github h5py / h5py / setup_build.py View on Github external
This is the point at which custom directories, MPI options, etc.
        enter the build process.
        """
        import numpy
        import pkgconfig

        settings = COMPILER_SETTINGS.copy()

        # Ensure that if a custom HDF5 location is specified, prevent
        # pkg-config and fallback locations from appearing in the settings
        if config.hdf5 is not None:
            settings['include_dirs'].insert(0, op.join(config.hdf5, 'include'))
            settings['library_dirs'].insert(0, op.join(config.hdf5, 'lib'))
        else:
            try:
                if pkgconfig.exists('hdf5'):
                    pkgcfg = pkgconfig.parse("hdf5")
                    settings['include_dirs'].extend(pkgcfg['include_dirs'])
                    settings['library_dirs'].extend(pkgcfg['library_dirs'])
                    settings['define_macros'].extend(pkgcfg['define_macros'])
            except EnvironmentError:
                pass
            settings['include_dirs'].extend(FALLBACK_PATHS['include_dirs'])
            settings['library_dirs'].extend(FALLBACK_PATHS['library_dirs'])

        try:
            numpy_includes = numpy.get_include()
        except AttributeError:
            # if numpy is not installed get the headers from the .egg directory
            import numpy.core
            numpy_includes = os.path.join(os.path.dirname(numpy.core.__file__), 'include')
github h5py / h5py / setup_configure.py View on Github external
import sys
    import os.path as op
    import re
    import ctypes
    from ctypes import byref

    import pkgconfig
    
    if sys.platform.startswith('darwin'):
        regexp = re.compile(r'^libhdf5.dylib')
    else:
        regexp = re.compile(r'^libhdf5.so')
        
    libdirs = ['/usr/local/lib', '/opt/local/lib']
    try:
        if pkgconfig.exists("hdf5"):
            libdirs.extend(pkgconfig.parse("hdf5")['library_dirs'])
    except EnvironmentError:
        pass
    if hdf5_dir is not None:
        libdirs.insert(0, op.join(hdf5_dir, 'lib'))

    path = None
    for d in libdirs:
        try:
            candidates = [x for x in os.listdir(d) if regexp.match(x)]
        except Exception:
            continue   # Skip invalid entries

        if len(candidates) != 0:
            candidates.sort(key=lambda x: len(x))   # Prefer libfoo.so to libfoo.so.X.Y.Z
            path = op.abspath(op.join(d, candidates[0]))