def test_libs(): flags = pkgconfig.libs(PACKAGE_NAME) for flag in flags.split(' '): assert flag in ('-L/usr/lib_gtk_foo', '-lgtk-3') with pytest.raises(pkgconfig.PackageNotFoundError): pkgconfig.libs('doesnotexist')
def get_libs(package): libs = pkgconfig.libs(package) if not libs: raise RuntimeError('Unable to find pkgconfig libs' ' for {}'.format(package)) libs = libs.replace('-l', '').split(' ') return libs
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, swig_opts=swig_opts + [cvinc, '-I./opencv-swig/lib', '-modern', '-keyword', '-w511', '-c++'], sources=['pagexml/PageXML.i', 'pagexml/PageXML.cc'])
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, swig_opts=swig_opts + [cvinc, '-modern', '-keyword', '-c++'], sources=[ 'textfeat/TextFeatExtractor.i', 'textfeat/TextFeatExtractor.cc', 'textfeat/intimg.cc', 'textfeat/mem.cc' ])
def get_blas_config() -> PackageInfo: """ Find CBLAS-compatible BLAS :return: blas related package information """ blaspkgcfg = { 'include_dirs': [], 'library_dirs': [], 'libraries': [], 'define_macros': [], 'extra_compile_args': [], 'extra_link_args': [] } # Check environment variables if 'BLAS_CFLAGS' in os.environ: blaspkgcfg['extra_compile_args'].extend( shlex.split(os.environ['BLAS_CFLAGS'])) if 'BLAS_LIBS' in os.environ: blaspkgcfg['extra_link_args'].extend( shlex.split(os.environ['BLAS_LIBS'])) if 'BLAS_CFLAGS' in os.environ or 'BLAS_LIBS' in os.environ: # If options have been provided by the user, we don't try to detect # anything by ourselves return blaspkgcfg # Try environment modules # MKL if 'MKLROOT' in os.environ: if 'MKL_INC' in os.environ: blaspkgcfg['extra_compile_args'].extend( shlex.split(os.environ['MKL_INC'])) if 'MKL_LIB' in os.environ: blaspkgcfg['extra_link_args'].extend( shlex.split(os.environ['MKL_LIB'])) blaspkgcfg['define_macros'].append(('AMICI_BLAS_MKL', None), ) return blaspkgcfg # Try pkgconfig if pkgconfig: for blas_name in ['cblas', 'openblas']: if pkgconfig.exists(blas_name): blaspkgcfg = pkgconfig.parse(blas_name) blaspkgcfg['extra_compile_args'] = [ pkgconfig.cflags(blas_name) ] blaspkgcfg['extra_link_args'] = [pkgconfig.libs(blas_name)] return blaspkgcfg # If none of the previous worked, fall back to libcblas in default paths blaspkgcfg['libraries'] = ['cblas'] return blaspkgcfg
def pkg_libs(pkg_name): libs = [] for dir in pkgconfig.libs(pkg_name).split(" "): if dir[:2] == "-l": libs.append(dir[2:]) else: libs.append(dir) return libs
def __init__(self): found_paskages = self._find_in_tree(root=os.path.dirname(cv2.__file__)) if found_paskages: PKG_CONFIG_PATH = found_paskages[0][1] self._pkg_config_name = found_paskages[0][0] os.environ['PKG_CONFIG_PATH'] = PKG_CONFIG_PATH self._pkg_config_path = PKG_CONFIG_PATH self._cflags = pkgconfig.cflags(self._pkg_config_name) self._libs = pkgconfig.libs(self._pkg_config_name)
def get_ldflags(): """ Get link flags. Returns: str[]: List of link flags. """ libdirs = [os.path.join(vp.computecpp_prefix, "lib")] libs = ["ComputeCpp", "pthread"] return (pkgconfig.libs("opencv").split() + ["-L" + x for x in libdirs] + ["-l" + x for x in libs])
def getBlasConfig(): """ Find CBLAS-compatible BLAS Arguments: Returns: Raises: """ blaspkgcfg = {'include_dirs': [], 'library_dirs': [], 'libraries': [], 'define_macros': [], 'extra_compile_args': [], 'extra_link_args': [] } if platform.system() in ['Linux', 'Darwin']: blaspkgcfg['libraries'] = ['cblas'] if pkgconfig: if pkgconfig.exists('cblas'): blaspkgcfg = pkgconfig.parse('cblas') blaspkgcfg['extra_compile_args'] = [pkgconfig.cflags('cblas')] blaspkgcfg['extra_link_args'] = [pkgconfig.libs('cblas')] if 'BLAS_CFLAGS' in os.environ: blaspkgcfg['extra_compile_args'].extend( shlex.split(os.environ['BLAS_CFLAGS']) ) if 'BLAS_LIBS' in os.environ: blaspkgcfg['extra_link_args'].extend( shlex.split(os.environ['BLAS_LIBS']) ) return blaspkgcfg
def check_gromacs_dirs(): ''' Check for GROMACS directories and flags ''' import pkgconfig # If gromacs not in pkgconfig, return from here if not pkgconfig.exists('libgromacs'): return out = dict() cppflags_t = pkgconfig.re.split('\s+', pkgconfig.cflags('libgromacs')) out['cppflags'] = [] out['ldflags'] = [] out['include'] = [] out['lib_dirs'] = [] out['libs'] = [] # Extract include directory and CXXFLAGS for flags in cppflags_t: if '-I' in flags: out['include'].append(flags[2:]) else: out['cppflags'].append(flags) # Extract lib directory and LDFLAGS ldflags_t = pkgconfig.re.split('\s+', pkgconfig.libs('libgromacs')) for flags in ldflags_t: if '-L' in flags: out['lib_dirs'].append(flags[2:]) elif '-l' in flags: out['libs'].append(flags[2:]) else: out['ldflags'].append(flags) if '-fopenmp' not in out['ldflags']: out['ldflags'].append('-fopenmp') return out
darknet_dir = input("$DARKNET_HOME:") else: darknet_dir = os.environ["DARKNET_HOME"] include_paths = [ np.get_include(), os.path.join(darknet_dir, "include"), os.path.join(darknet_dir, "src") ] libraries = ["darknet", "m", "pthread"] library_paths = [darknet_dir] extra_compiler_flags = [ pkgconfig.cflags("opencv"), pkgconfig.cflags("python3") ] extra_linker_flags = [pkgconfig.libs("opencv"), pkgconfig.libs("python3")] ext_modules = [ Extension("pydarknet", ["pydarknet.pyx", "pydarknet.pxd", "bridge.cpp"], include_dirs=include_paths, language="c++", libraries=libraries, library_dirs=library_paths, extra_link_args=extra_linker_flags, extra_compile_args=extra_compiler_flags), ] setup(name='PyDarknet', cmdclass={'build_ext': build_ext}, ext_modules=ext_modules)
def cython_aliases(): """ Return the aliases for compiling Cython code. These aliases are macros which can occur in ``# distutils`` headers. EXAMPLES:: sage: from sage.env import cython_aliases sage: cython_aliases() {...} sage: sorted(cython_aliases().keys()) ['ARB_LIBRARY', 'CBLAS_CFLAGS', ..., 'ZLIB_LIBRARIES'] """ import pkgconfig aliases = {} for lib in ['fflas-ffpack', 'givaro', 'gsl', 'linbox', 'Singular', 'libpng', 'gdlib', 'm4ri', 'zlib', 'cblas', 'lapack']: var = lib.upper().replace("-", "") + "_" if lib == 'cblas': lib = get_cblas_pc_module_name() if lib == 'zlib': aliases[var + "CFLAGS"] = "" try: pc = pkgconfig.parse('zlib') libs = pkgconfig.libs(lib) except pkgconfig.PackageNotFoundError: from collections import defaultdict pc = defaultdict(list, {'libraries': ['z']}) libs = "-lz" else: aliases[var + "CFLAGS"] = pkgconfig.cflags(lib).split() pc = pkgconfig.parse(lib) libs = pkgconfig.libs(lib) # It may seem that INCDIR is redundant because the -I options are also # passed in CFLAGS. However, "extra_compile_args" are put at the end # of the compiler command line. "include_dirs" go to the front; the # include search order matters. aliases[var + "INCDIR"] = pc['include_dirs'] aliases[var + "LIBDIR"] = pc['library_dirs'] aliases[var + "LIBEXTRA"] = list(filter(lambda s: not s.startswith(('-l','-L')), libs.split())) aliases[var + "LIBRARIES"] = pc['libraries'] # uname-specific flags UNAME = os.uname() def uname_specific(name, value, alternative): if name in UNAME[0]: return value else: return alternative aliases["LINUX_NOEXECSTACK"] = uname_specific("Linux", ["-Wl,-z,noexecstack"], []) aliases["CYGWIN_SQLITE3_LIBS"] = uname_specific("CYGWIN", ["sqlite3"], []) # LinBox needs special care because it actually requires C++11 with # GNU extensions: -std=c++11 does not work, you need -std=gnu++11 # (this is true at least with GCC 7.2.0). # # Further, note that LinBox does not add any C++11 flag in its .pc # file (possibly because of confusion between CFLAGS and CXXFLAGS?). # This is not a problem in practice since LinBox depends on # fflas-ffpack and fflas-ffpack does add such a C++11 flag. aliases["LINBOX_CFLAGS"].append("-std=gnu++11") aliases["ARB_LIBRARY"] = ARB_LIBRARY # TODO: Remove Cygwin hack by installing a suitable cblas.pc if os.path.exists('/usr/lib/libblas.dll.a'): aliases["CBLAS_LIBS"] = ['gslcblas'] try: aliases["M4RI_CFLAGS"].remove("-pedantic") except ValueError: pass # Determine ecl-specific compiler arguments using the ecl-config script ecl_cflags = subprocess.run([ECL_CONFIG, "--cflags"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stdout.split() aliases["ECL_CFLAGS"] = list(filter(lambda s: not s.startswith('-I'), ecl_cflags)) aliases["ECL_INCDIR"] = list(map(lambda s: s[2:], filter(lambda s: s.startswith('-I'), ecl_cflags))) ecl_libs = subprocess.run([ECL_CONFIG, "--libs"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stdout.split() aliases["ECL_LIBDIR"] = list(map(lambda s: s[2:], filter(lambda s: s.startswith('-L'), ecl_libs))) aliases["ECL_LIBRARIES"] = list(map(lambda s: s[2:], filter(lambda s: s.startswith('-l'), ecl_libs))) aliases["ECL_LIBEXTRA"] = list(filter(lambda s: not s.startswith(('-l','-L')), ecl_libs)) # NTL aliases["NTL_CFLAGS"] = ['-std=c++11'] aliases["NTL_INCDIR"] = [NTL_INCDIR] if NTL_INCDIR else [] aliases["NTL_LIBDIR"] = [NTL_LIBDIR] if NTL_LIBDIR else [] aliases["NTL_LIBRARIES"] = ['ntl'] aliases["NTL_LIBEXTRA"] = [] return aliases
] elif sys.version[0]=='2': libraries = [ 'python{}'.format(sys.version[0:3]),'boost_python', 'LeptonWeighter', ] else: raise Exception("Python version {} not supported".format(sys.version[0])) library_dirs = [ '../lib/', env_prefix+'/lib/', env_prefix+'/lib64/', cvmfs_env_root + "/lib/", cvmfs_env_root + "/lib64/", ] files = ['lepton_weighter_pybi.cpp'] setup(name = 'LeptonWeighter', author = "Carlos A. Arguelles", ext_modules = [ Extension('LeptonWeighter',files, library_dirs=library_dirs, libraries=libraries, include_dirs=include_dirs, extra_compile_args=['-O3','-fPIC','-std=c++11',pkgconfig.cflags('squids'),pkgconfig.cflags('nusquids')], extra_link_args=[pkgconfig.libs('squids'),pkgconfig.libs('nusquids')], depends=[]), ] )
def test_libs(): flags = pkgconfig.libs(PACKAGE_NAME) for flag in flags.split(' '): nt.assert_true(flag in ('-L/usr/lib_gtk_foo', '-lgtk-3'))
if on_rtd: extensions = [] cmdclasses = {} setup_requires = [] install_requires = [] tests_require = [] else: from Cython.Build import cythonize from Cython.Distutils import build_ext import numpy import numpy.distutils try: import pkgconfig libs = ['blas', 'lapack', 'lapacke'] extra_link_args = [pkgconfig.libs(lib) for lib in libs] include_dirs = (numpy.distutils.misc_util.get_numpy_include_dirs() + [pkgconfig.cflags(lib) for lib in libs]) except: extra_link_args = None include_dirs = None if extra_link_args is None or len(''.join(extra_link_args)) == 0: if sys.platform == 'darwin': print("Platform Detection: Mac OS X. Link to openblas...") extra_link_args = ['-L/usr/local/opt/openblas/lib -lopenblas'] include_dirs = ( numpy.distutils.misc_util.get_numpy_include_dirs() + ['/usr/local/opt/openblas/include']) else: # assume linux otherwise, unless we support Windows in the future...
def cython_aliases(): """ Return the aliases for compiling Cython code. These aliases are macros which can occur in ``# distutils`` headers. EXAMPLES:: sage: from sage.env import cython_aliases sage: cython_aliases() {...} sage: sorted(cython_aliases().keys()) ['ARB_LIBRARY', 'FFLASFFPACK_CFLAGS', 'FFLASFFPACK_INCDIR', 'FFLASFFPACK_LIBDIR', 'FFLASFFPACK_LIBEXTRA', 'FFLASFFPACK_LIBRARIES', 'GIVARO_CFLAGS', 'GIVARO_INCDIR', 'GIVARO_LIBDIR', 'GIVARO_LIBEXTRA', 'GIVARO_LIBRARIES', 'GSL_CFLAGS', 'GSL_INCDIR', 'GSL_LIBDIR', 'GSL_LIBEXTRA', 'GSL_LIBRARIES', 'LINBOX_CFLAGS', 'LINBOX_INCDIR', 'LINBOX_LIBDIR', 'LINBOX_LIBEXTRA', 'LINBOX_LIBRARIES', 'SINGULAR_CFLAGS', 'SINGULAR_INCDIR', 'SINGULAR_LIBDIR', 'SINGULAR_LIBEXTRA', 'SINGULAR_LIBRARIES'] """ import pkgconfig aliases = {} for lib in ['fflas-ffpack', 'givaro', 'gsl', 'linbox', 'Singular']: var = lib.upper().replace("-", "") + "_" aliases[var + "CFLAGS"] = pkgconfig.cflags(lib).split() pc = pkgconfig.parse(lib) # INCDIR should be redundant because the -I options are also # passed in CFLAGS aliases[var + "INCDIR"] = pc['include_dirs'] aliases[var + "LIBDIR"] = pc['library_dirs'] aliases[var + "LIBEXTRA"] = list( filter(lambda s: not s.startswith(('-l', '-L')), pkgconfig.libs(lib).split())) aliases[var + "LIBRARIES"] = pc['libraries'] # LinBox needs special care because it actually requires C++11 with # GNU extensions: -std=c++11 does not work, you need -std=gnu++11 # (this is true at least with GCC 7.2.0). # # Further, note that LinBox does not add any C++11 flag in its .pc # file (possibly because of confusion between CFLAGS and CXXFLAGS?). # This is not a problem in practice since LinBox depends on # fflas-ffpack and fflas-ffpack does add such a C++11 flag. aliases["LINBOX_CFLAGS"].append("-std=gnu++11") aliases["ARB_LIBRARY"] = ARB_LIBRARY return aliases
import distutils.sysconfig import os import sys # Use the bundeled pkgconfig here = os.path.dirname(os.path.realpath(__file__)) sys.path.insert(0, here) import pkgconfig cfg_vars = distutils.sysconfig.get_config_vars() for key, value in cfg_vars.items(): if type(value) == str: cfg_vars[key] = value.replace("-Wstrict-prototypes", "") extra_link_args = pkgconfig.libs('gsl').split() extra_compile_args = pkgconfig.cflags('gsl').split() extra_compile_args.append('-m64') extension_mod = Extension( "_gappa", [ "_gappa.cc", "../src/Radiation.C", "../src/Particles.C", "../src/Utils.C", "../src/Astro.C", "../src/2D_interp/interp2d.C", "../src/2D_interp/interp2d_spline.C", "../src/2D_interp/bilinear.C", "../src/2D_interp/bicubic.C" ], extra_compile_args=extra_compile_args, extra_link_args=extra_link_args, include_dirs=['../include'],
libraries = ['gwenhywfar', 'aqbanking'] depCompilationArgs = [ '-Wunused-variable', '-Wunused-function', '-DPACKAGE_VERSION="' + PACKAGE_VERSION + '"' ] depLibraryDirs = [] # check for aqbanking dependency if not pkgconfig.exists('aqbanking'): sys.stderr.write( 'Need aqbanking development package installed for compilation.' + os.linesep) sys.exit(1) else: for library in libraries: depCompilationArgs += pkgconfig.cflags(library).split(' ') depCompilationArgs += pkgconfig.libs(library).split(' ') libPath = pkgconfig.variables(library)['libdir'] if libPath not in depLibraryDirs: depLibraryDirs.append(libPath) # furthermore remember the c++ gui! if StrictVersion( pkgconfig.modversion('aqbanking').replace('beta', '').replace( 'alpha', '')) >= StrictVersion('5.8.1'): depCompilationArgs.append('-DSUPPORT_APPREGISTRATION') depCompilationArgs += [ '-DFINTS_REGISTRATION_KEY="8DEDB89E7B0F7DAE207CB948C"' ] sys.stderr.write('FinTS App registration enabled' + os.linesep) else: sys.stderr.write('FinTS App registration disabled' + os.linesep)
from distutils.core import setup, Extension from Cython.Build import cythonize from Cython.Distutils import build_ext import numpy import sys import os import glob import pkgconfig zense_cflags = pkgconfig.cflags('libpicozense') zense_libs = pkgconfig.libs('libpicozense') opencv_cflags = pkgconfig.cflags('opencv').split() cvlibs_string = pkgconfig.libs('opencv') cvinclude = [str('{}'.format(elem.split('-I')[-1])) for elem in opencv_cflags] lib_dirs = [] cvlibs = list() cvlibs_pkgcfg_list = cvlibs_string.split() for elem in cvlibs_pkgcfg_list: # like u'-L/usr/local/lib' if elem.startswith("-L"): lib_dirs.append(str('{}'.format(elem.split('-L')[-1]))) # like u'-lopencv_stitching' elif elem.startswith("-l"): _cvlib = 'opencv_{}'.format(elem.split('-lopencv_')[-1]) cvlibs.append(_cvlib) else: pass setup(
def test_libs_static(): flags = pkgconfig.libs('fake-python', static=True) flags = flags.split(' ') assert '-lpthread' in flags assert '-ldl' in flags assert '-lutil' in flags
#!/usr/bin/env python3 #-*- encoding: utf-8 -*- from distutils.core import setup, Extension import pkgconfig rdp_cflags = pkgconfig.cflags('rdp') rdp_libs = pkgconfig.libs('rdp') rdp_libs = rdp_libs.replace("-lrdp", "") rdp_libs = rdp_libs.replace("-L", "") rdp_libs = rdp_libs.strip() rdp_libs = rdp_libs + "/librdp.a" extra_compile_args = [rdp_cflags] extra_link_args = ['-Wl,--whole-archive', rdp_libs, '-Wl,--no-whole-archive'] wrapper = Extension('rdp.wrapper', ['rdp/wrapper.c'], extra_compile_args=extra_compile_args, extra_link_args=extra_link_args) packages = ['rdp'] print("PACKAGES = ", packages) setup(name='rdp', version='1.0', packages=packages, ext_modules=[wrapper])
from setuptools import setup, Extension import pkgconfig import os opencv_names = ['opencv', 'opencv3', 'opencv4', 'opencv2'] opencv = None for name in opencv_names: if not opencv and pkgconfig.exists(name): opencv = name if not opencv: raise RuntimeError('Opencv not found') opencv_cflags = pkgconfig.cflags(opencv) opencv_ldflags = pkgconfig.libs(opencv) include_dirs = [x[2:] for x in opencv_cflags.split(' ') if x.startswith('-I')] include_dirs.append('/usr/include/CCfits') include_dirs.append('/usr/local/include/CCfits') library_dirs = set(['/usr/lib']) libraries = ['CCfits'] cflags = [x for x in opencv_cflags.split(' ') if not x.startswith('-I')] def parse_lib(lib): global library_dirs if lib.startswith('-l'): return lib[2:]
'lz4libs/xxhash.c', ]) if not py3c_found: include_dirs.append('py3c') compiler = ccompiler.get_default_compiler() extra_link_args = [] extra_compile_args = [] if compiler == 'msvc': extra_compile_args = ['/Ot', '/Wall'] elif compiler in ('unix', 'mingw32'): if liblz4_found and liblz4_pkgconfig: extra_link_args.append(pkgconfig.libs('liblz4')) if pkgconfig.cflags('liblz4'): extra_compile_args.append(pkgconfig.cflags('liblz4')) else: extra_compile_args = ['-O3', '-Wall', '-Wundef'] else: print('Unrecognized compiler: {0}'.format(compiler)) sys.exit(1) lz4version = Extension( 'lz4._version', lz4version_sources, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args, libraries=libraries, include_dirs=include_dirs,
from setuptools import setup, Extension from setuptools.command.install import install import os import ConfigParser try: import pkgconfig cflags = pkgconfig.cflags('xmlsec1').replace('\\', '') if not cflags: raise libs = pkgconfig.libs('xmlsec1') except Exception: import traceback print '-' * 100 traceback.print_exc() print '-' * 100 import platform cflags = ("-DXMLSEC_CRYPTO=\"openssl\" -D__XMLSEC_FUNCTION__=__FUNCTION__" " -DXMLSEC_NO_GOST=1 -DXMLSEC_NO_XKMS=1" " -DXMLSEC_NO_CRYPTO_DYNAMIC_LOADING=1 -DXMLSEC_OPENSSL_100=1" " -DXMLSEC_CRYPTO_OPENSSL=1" " -I/usr/include/libxml2 -I/usr/include/xmlsec1") if platform.uname()[4] == 'x86_64': cflags = "-DXMLSEC_NO_SIZE_T " + cflags libs = "-lxmlsec1-openssl -lxmlsec1 -lssl -lcrypto -lxslt -lxml2" config = ConfigParser.ConfigParser() config.read('setup.cfg') locale_dir = config.get("compile_catalog", "directory") domain = config.get("compile_catalog", "domain")
from distutils.core import setup, Extension from Cython.Build import cythonize from Cython.Distutils import build_ext import numpy import sys import os import glob import pkgconfig zense_cflags = pkgconfig.cflags('libpicozense') zense_libs = pkgconfig.libs('libpicozense') cvlib_folder = os.path.join(sys.prefix, 'local', 'lib') lib_dirs = [cvlib_folder] cvlibs = list() for file in glob.glob(os.path.join(cvlib_folder, 'libopencv_*')): cvlibs.append(file.split('.')[0]) cvlibs = list(set(cvlibs)) cvlibs = [ 'opencv_{}'.format(lib.split(os.path.sep)[-1].split('libopencv_')[-1]) for lib in cvlibs ] setup( name="zense_pywrapper", ext_modules=cythonize([ Extension( "zense_pywrapper", sources=["zense_pywrapper.pyx", "pico_zense_manager.cpp"], extra_compile_args=[
from Cython.Distutils.extension import Extension import pkgconfig import numpy as np from Cython.Distutils import build_ext import logging import os logging.basicConfig(level=logging.INFO) USE_CV = True if "OPENCV" in os.environ and int(os.environ["OPENCV"]) == 0: logging.info("Compiling without OpenCV") USE_CV = False if USE_CV & (pkgconfig.libs("opencv") == '' or pkgconfig.cflags("opencv") == ''): logging.warning("OpenCV is not configured. Compiling without OpenCV!") USE_CV = False if not "DARKNET_HOME" in os.environ: darknet_dir = input("$DARKNET_HOME:") else: darknet_dir = os.environ["DARKNET_HOME"] include_paths = [ np.get_include(), os.path.join(darknet_dir, "include"), os.path.join(darknet_dir, "src") ] libraries = ["darknet", "m", "pthread"]
from Cython.Build import cythonize from Cython.Distutils import build_ext from setuptools import setup, Extension import numpy import sys import os import glob import pkgconfig opencv_cflags = pkgconfig.cflags('opencv').split() cvlibs_string = pkgconfig.libs('opencv') cvinclude = [str('{}'.format(elem.split('-I')[-1])) for elem in opencv_cflags] lib_dirs = [] cvlibs = list() cvlibs_pkgcfg_list = cvlibs_string.split() for elem in cvlibs_pkgcfg_list: # like u'-L/usr/local/lib' if elem.startswith("-L"): lib_dirs.append(str('{}'.format(elem.split('-L')[-1]))) # like u'-lopencv_stitching' elif elem.startswith("-l"): _cvlib = 'opencv_{}'.format(elem.split('-lopencv_')[-1]) cvlibs.append(_cvlib) else: pass sources = [ "april_detector_pywrapper.pyx", "src/example/april_detector_manager.cpp" ] + glob.glob("src/*.cc")
from distutils.core import setup, Extension import pkgconfig GSL_CFLAGS = pkgconfig.cflags('gsl') GSL_LIBS = pkgconfig.libs('gsl') if(GSL_CFLAGS): COMPILEARGS=['-std=c++11', GSL_CFLAGS] else: COMPILEARGS=['-std=c++11'] extension_mod = Extension("_gamerapy", ["_gamerapy.cc", "../src/Radiation.C","../src/Particles.C","../src/Utils.C","../src/Astro.C"], extra_compile_args=COMPILEARGS, libraries=['gsl'], include_dirs=['../include'], ) setup(name = "gamerapy", ext_modules=[extension_mod])
from os import path from codecs import open import pkgconfig here = path.abspath(path.dirname(__file__)) ## Getting openbabel setting openbabel = None for ob in ['openbabel', 'openbabel-2.0']: if pkgconfig.exists(ob): openbabel = ob if openbabel is None: raise LookupError("openbabel package not found") pkgconfig.libs(openbabel) openbabel_inc_dir = pkgconfig.cflags(openbabel)[2:] openbabel_lib_dir = pkgconfig.re.split('\s+', pkgconfig.libs(openbabel))[0][2:] class get_pybind_include(object): """Helper class to determine the pybind11 include path The purpose of this class is to postpone importing pybind11 until it is actually installed, so that the ``get_include()`` method can be invoked. """ def __init__(self, user=False): self.user = user def __str__(self): import pybind11
from distutils.core import setup, Extension import os import sys # Use the bundeled pkgconfig here = os.path.dirname(os.path.realpath(__file__)) sys.path.insert(0, here) import pkgconfig extra_link_args = pkgconfig.libs('gsl').split() extra_compile_args = pkgconfig.cflags('gsl').split() extra_compile_args.append('-std=c++11') extension_mod = Extension( "_gappa", ["_gappa.cc", "../src/Radiation.C", "../src/Particles.C", "../src/Utils.C", "../src/Astro.C"], extra_compile_args=extra_compile_args, extra_link_args=extra_link_args, include_dirs=['../include'], ) setup( name="gappa", ext_modules=[extension_mod], )
fname, ext = os.path.splitext(el) if ext == suffix: yield fname, el if __name__ == '__main__': check_pkgconfig(['dbus-1']) p = argparse.ArgumentParser() p.add_argument('--clang', action='store_true', default=False) clang = p.parse_args().clang ninja_vars = OrderedDict( cxx=find_executable('clang++' if clang else 'c++'), cxxflags='-std=c++1z -Wall -Wextra -g -D_GNU_SOURCE', dbus_cflags=pkgconfig.cflags('dbus-1'), dbus_libs=pkgconfig.libs('dbus-1'), ninja=find_executable('ninja')) with open('build.ninja', 'w') as bf, open('.gitignore', 'w') as gign: bf.write('# Created by configure.py\n# DO NOT EDIT\n\n') n = ninja.ninja_syntax.Writer(bf) for key, val in ninja_vars.items(): n.variable(key, val) n.newline() n.rule('link', '$cxx $cxxflags -o $out $in', 'CXXLD $out') n.rule('link-dbus', '$cxx $cxxflags $dbus_cflags -o $out $in $dbus_libs', 'CXXLD $out') n.newline()
def cython_aliases(required_modules=None, optional_modules=None): """ Return the aliases for compiling Cython code. These aliases are macros which can occur in ``# distutils`` headers. INPUT: - ``required_modules`` -- (default: taken from ``default_required_modules``) iterable of ``str`` values. - ``optional_modules`` -- (default: taken from ``default_optional_modules``) iterable of ``str`` values. EXAMPLES:: sage: from sage.env import cython_aliases sage: cython_aliases() {...} sage: sorted(cython_aliases().keys()) ['ARB_LIBRARY', 'CBLAS_CFLAGS', ..., 'ZLIB_LIBRARIES'] sage: cython_aliases(required_modules=('module-that-is-assumed-to-not-exist')) Traceback (most recent call last): ... PackageNotFoundError: ... sage: cython_aliases(required_modules=(), optional_modules=('module-that-is-assumed-to-not-exist')) {...} TESTS: We can use ``cython.parallel`` regardless of whether OpenMP is supported. This will run in parallel, if OpenMP is supported:: sage: cython(''' ....: #distutils: extra_compile_args = OPENMP_CFLAGS ....: #distutils: extra_link_args = OPENMP_CFLAGS ....: from cython.parallel import prange ....: ....: cdef int i ....: cdef int n = 30 ....: cdef int sum = 0 ....: ....: for i in prange(n, num_threads=4, nogil=True): ....: sum += i ....: ....: print(sum) ....: ''') 435 """ import pkgconfig import itertools if required_modules is None: required_modules = default_required_modules if optional_modules is None: optional_modules = default_optional_modules aliases = {} for lib, required in itertools.chain( ((lib, True) for lib in required_modules), ((lib, False) for lib in optional_modules)): var = lib.upper().replace("-", "") + "_" if lib == 'cblas': lib = get_cblas_pc_module_name() if lib == 'zlib': aliases[var + "CFLAGS"] = "" try: pc = pkgconfig.parse('zlib') libs = pkgconfig.libs(lib) except pkgconfig.PackageNotFoundError: from collections import defaultdict pc = defaultdict(list, {'libraries': ['z']}) libs = "-lz" else: try: aliases[var + "CFLAGS"] = pkgconfig.cflags(lib).split() pc = pkgconfig.parse(lib) libs = pkgconfig.libs(lib) except pkgconfig.PackageNotFoundError: if required: raise else: continue # It may seem that INCDIR is redundant because the -I options are also # passed in CFLAGS. However, "extra_compile_args" are put at the end # of the compiler command line. "include_dirs" go to the front; the # include search order matters. aliases[var + "INCDIR"] = pc['include_dirs'] aliases[var + "LIBDIR"] = pc['library_dirs'] aliases[var + "LIBEXTRA"] = list( filter(lambda s: not s.startswith(('-l', '-L')), libs.split())) aliases[var + "LIBRARIES"] = pc['libraries'] # uname-specific flags UNAME = os.uname() def uname_specific(name, value, alternative): if name in UNAME[0]: return value else: return alternative aliases["LINUX_NOEXECSTACK"] = uname_specific("Linux", ["-Wl,-z,noexecstack"], []) aliases["CYGWIN_SQLITE3_LIBS"] = uname_specific("CYGWIN", ["sqlite3"], []) # LinBox needs special care because it actually requires C++11 with # GNU extensions: -std=c++11 does not work, you need -std=gnu++11 # (this is true at least with GCC 7.2.0). # # Further, note that LinBox does not add any C++11 flag in its .pc # file (possibly because of confusion between CFLAGS and CXXFLAGS?). # This is not a problem in practice since LinBox depends on # fflas-ffpack and fflas-ffpack does add such a C++11 flag. if "LINBOX_CFLAGS" in aliases: aliases["LINBOX_CFLAGS"].append("-std=gnu++11") aliases["ARB_LIBRARY"] = ARB_LIBRARY # TODO: Remove Cygwin hack by installing a suitable cblas.pc if os.path.exists('/usr/lib/libblas.dll.a'): aliases["CBLAS_LIBS"] = ['gslcblas'] try: aliases["M4RI_CFLAGS"].remove("-pedantic") except (ValueError, KeyError): pass # Determine ecl-specific compiler arguments using the ecl-config script ecl_cflags = subprocess.run([ECL_CONFIG, "--cflags"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stdout.split() aliases["ECL_CFLAGS"] = list( filter(lambda s: not s.startswith('-I'), ecl_cflags)) aliases["ECL_INCDIR"] = list( map(lambda s: s[2:], filter(lambda s: s.startswith('-I'), ecl_cflags))) ecl_libs = subprocess.run([ECL_CONFIG, "--libs"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stdout.split() aliases["ECL_LIBDIR"] = list( map(lambda s: s[2:], filter(lambda s: s.startswith('-L'), ecl_libs))) aliases["ECL_LIBRARIES"] = list( map(lambda s: s[2:], filter(lambda s: s.startswith('-l'), ecl_libs))) aliases["ECL_LIBEXTRA"] = list( filter(lambda s: not s.startswith(('-l', '-L')), ecl_libs)) # NTL aliases["NTL_CFLAGS"] = ['-std=c++11'] aliases["NTL_INCDIR"] = [NTL_INCDIR] if NTL_INCDIR else [] aliases["NTL_LIBDIR"] = [NTL_LIBDIR] if NTL_LIBDIR else [] aliases["NTL_LIBRARIES"] = ['ntl'] aliases["NTL_LIBEXTRA"] = [] # OpenMP aliases["OPENMP_CFLAGS"] = OPENMP_CFLAGS.split() aliases["OPENMP_CXXFLAGS"] = OPENMP_CXXFLAGS.split() return aliases
def link_target_pkgconfig(self, pkg, target, pc): self.log.info('PMContext.link_target_pkgconfig()', pkg=pkg.name, target=target.name, pc=pc) if not pkgconfig.exists(pc): self.log.failure('unable to find a pkg-config', pc=pc) target.flags += (' ' + pkgconfig.libs(pc) + ' ' + pkgconfig.cflags(pc))