def get_macros(): """get_macros() -> macros Returns a list of preprocessor macros, such as ``(HAVE_LIBJPEG, 1)``. This function is automatically used by :py:func:`bob.extension.get_bob_libraries` to retrieve the prerpocessor definitions that are required to use the C bindings of this library in dependent classes. You shouldn't normally need to call this function by hand. **Returns:** ``macros`` : [str] The list of preprocessor macros required to use the C bindings of this class. """ # try to use pkg_config first from bob.extension.utils import find_header, uniq_paths from bob.extension import pkgconfig macros = [] for define, header in (('HAVE_LIBJPEG', 'jpeglib.h'), ('HAVE_LIBTIFF', 'tiff.h'), ('HAVE_GIFLIB', 'gif_lib.h')): # locate pkg-config on our own candidates = find_header(header) if candidates: macros.append((define, '1')) for define, name in (("HAVE_LIBPNG", "libpng"),): try: pkg = pkgconfig(name) macros.append((define, '1')) except: pass return macros
def get_include_directories(): """get_include_directories() -> includes Returns a list of include directories for dependent libraries, such as HDF5. This function is automatically used by :py:func:`bob.extension.get_bob_libraries` to retrieve the non-standard include directories that are required to use the C bindings of this library in dependent classes. You shouldn't normally need to call this function by hand. **Returns:** ``includes`` : [str] The list of non-standard include directories required to use the C bindings of this class. For now, only the directory for the HDF5 headers are returned. """ # try to use pkg_config first try: from bob.extension.utils import find_header # locate pkg-config on our own header = 'hdf5.h' candidates = find_header(header) if not candidates: raise RuntimeError( "could not find %s's `%s' - have you installed %s on this " "machine?" % ('hdf5', header, 'hdf5')) return [os.path.dirname(candidates[0])] except RuntimeError: from bob.extension import pkgconfig pkg = pkgconfig('hdf5') return pkg.include_directories()
def get_include_directories(): """get_include_directories() -> includes Returns a list of include directories for dependent libraries, such as libjpeg, libtiff, ... This function is automatically used by :py:func:`bob.extension.get_bob_libraries` to retrieve the non-standard include directories that are required to use the C bindings of this library in dependent classes. You shouldn't normally need to call this function by hand. **Returns:** ``includes`` : [str] The list of non-standard include directories required to use the C bindings of this class. For now, only the directory for the HDF5 headers are returned. """ # try to use pkg_config first from bob.extension.utils import find_header, uniq_paths from bob.extension import pkgconfig import logging logger = logging.getLogger("bob.io.image") directories = [] for name, header in (('libjpeg', 'jpeglib.h'), ('libtiff', 'tiff.h'), ('giflib', 'gif_lib.h')): # locate pkg-config on our own candidates = find_header(header) if not candidates: logger.warn("could not find %s's `%s' - have you installed %s on this machine?" % (name, header, name)) directories.append(os.path.dirname(candidates[0])) for name in ("libpng",): try: pkg = pkgconfig(name) directories.extend(pkg.include_directories()) except: pass return uniq_paths(directories)
def __init__ (self): """ Searches for libhdf5 in stock locations. Allows user to override. If the user sets the environment variable BOB_PREFIX_PATH, that prefixes the standard path locations. """ import os self.name = 'hdf5' # try to locate pkg-config on our own first try: header = 'hdf5.h' candidates = find_header(header) if not candidates: raise RuntimeError("could not find %s's `%s' - have you installed %s on this machine?" % (self.name, header, self.name)) self.include_directories = [os.path.dirname(candidates[0])] directory = os.path.dirname(candidates[0]) version_header = os.path.join(directory, 'H5pubconf.h') self.version = libhdf5_version(version_header) # normalize self.include_directories = [os.path.normpath(i) for i in self.include_directories] # find library prefix = os.path.dirname(os.path.dirname(self.include_directories[0])) module = 'hdf5' candidates = find_library(module, version=self.version, prefixes=[prefix], only_static=False) if not candidates: raise RuntimeError("cannot find required %s binary module `%s' - make sure libhdf5 is installed on `%s'" % (self.name, module, prefix)) # libraries self.libraries = [] name, ext = os.path.splitext(os.path.basename(candidates[0])) if ext in ['.so', '.a', '.dylib', '.dll']: self.libraries.append(name[3:]) #strip 'lib' from the name else: #link against the whole thing self.libraries.append(':' + os.path.basename(candidates[0])) # library path self.library_directories = [os.path.dirname(candidates[0])] except RuntimeError: # now, we try to use pkg-config, which seems to be only available on Debian pkg = pkgconfig('hdf5') self.include_directories = pkg.include_directories() version_header = os.path.join(self.include_directories[0], 'H5pubconf.h') self.version = libhdf5_version(version_header) self.libraries = pkg.libraries() self.library_directories = pkg.library_directories()
def get_include_directories(): """Returns a list of include directories for dependent libraries, such as HDF5.""" from bob.extension import pkgconfig # try to use pkg_config first try: from bob.extension.utils import find_header # locate pkg-config on our own header = 'hdf5.h' candidates = find_header(header) if not candidates: raise RuntimeError("could not find %s's `%s' - have you installed %s on this machine?" % ('hdf5', header, 'hdf5')) return [os.path.dirname(candidates[0])] except RuntimeError: pkg = pkgconfig('hdf5') return pkg.include_directories()
def __init__ (self, only_static=False): """ Searches for netpbm in stock locations. Allows user to override. If the user sets the environment variable BOB_PREFIX_PATH, that prefixes the standard path locations. Parameters: only_static, boolean A flag, that indicates if we intend to link against the static library only. This will trigger our library search to disconsider shared libraries when searching. """ self.name = 'netpbm' header = 'pam.h' candidates = find_header(header, subpaths=[self.name, '']) if not candidates: raise RuntimeError("could not find %s's `%s' - have you installed %s on this machine?" % (self.name, header, self.name)) self.include_directory = os.path.dirname(candidates[0]) found = True # normalize self.include_directory = os.path.normpath(self.include_directory) # find library prefix = os.path.dirname(os.path.dirname(self.include_directory)) module = 'netpbm' candidates = find_library(module, prefixes=[prefix], only_static=only_static) if not candidates: raise RuntimeError("cannot find required %s binary module `%s' - make sure libsvm is installed on `%s'" % (self.name, module, prefix)) # libraries self.libraries = [] name, ext = os.path.splitext(os.path.basename(candidates[0])) if ext in ['.so', '.a', '.dylib', '.dll']: self.libraries.append(name[3:]) #strip 'lib' from the name else: #link against the whole thing self.libraries.append(':' + os.path.basename(candidates[0])) # library path self.library_directory = os.path.dirname(candidates[0])
def get_include_directories(): """Returns a list of include directories for dependent libraries, such as HDF5.""" from bob.extension import pkgconfig # try to use pkg_config first try: from bob.extension.utils import find_header # locate pkg-config on our own header = 'hdf5.h' candidates = find_header(header) if not candidates: raise RuntimeError( "could not find %s's `%s' - have you installed %s on this machine?" % ('hdf5', header, 'hdf5')) return [os.path.dirname(candidates[0])] except RuntimeError: pkg = pkgconfig('hdf5') return pkg.include_directories()
def __init__ (self): """ Searches for libsvm in stock locations. If the user sets the environment variable BOB_PREFIX_PATH, that prefixes the standard path locations. """ candidates = find_header('svm.h', subpaths=['', 'libsvm', 'libsvm-*/libsvm']) if not candidates: raise RuntimeError("could not find libsvm's `svm.h' - have you installed libsvm on this machine?") self.include_directory = os.path.dirname(candidates[0]) self.version = libsvm_version(candidates[0]) # normalize self.include_directory = os.path.normpath(self.include_directory) # find library prefix = os.path.dirname(os.path.dirname(self.include_directory)) module = 'svm' candidates = find_library(module, version=self.version, prefixes=[prefix], only_static=False) if not candidates: raise RuntimeError("cannot find required libsvm binary module `%s' - make sure libsvm is installed on `%s'" % (module, prefix)) # libraries self.libraries = [] name, ext = os.path.splitext(os.path.basename(candidates[0])) if ext in ['.so', '.a', '.dylib', '.dll']: self.libraries.append(name[3:]) #strip 'lib' from the name else: #link against the whole thing self.libraries.append(':' + os.path.basename(candidates[0])) # library path self.library_directory = os.path.dirname(candidates[0])
def __init__ (self, requirement='', only_static=False): """ Searches for libsvm in stock locations. Allows user to override. If the user sets the environment variable BOB_PREFIX_PATH, that prefixes the standard path locations. Parameters: requirement, str A string, indicating a version requirement for libsvm. For example, ``'>= 3.12'``. only_static, boolean A flag, that indicates if we intend to link against the static library only. This will trigger our library search to disconsider shared libraries when searching. """ candidates = find_header('svm.h', subpaths=['', 'libsvm', 'libsvm-*/libsvm']) if not candidates: raise RuntimeError("could not find libsvm's `svm.h' - have you installed libsvm on this machine?") found = False if not requirement: self.include_directory = os.path.dirname(candidates[0]) self.version = libsvm_version(candidates[0]) found = True else: # requirement is 'operator' 'version' operator, required = [k.strip() for k in requirement.split(' ', 1)] # now check for user requirements for candidate in candidates: vv = libsvm_version(candidate) available = LooseVersion(vv) if (operator == '<' and available < required) or \ (operator == '<=' and available <= required) or \ (operator == '>' and available > required) or \ (operator == '>=' and available >= required) or \ (operator == '==' and available == required): self.include_directory = os.path.dirname(candidate) self.version = vv found = True break if not found: raise RuntimeError("could not find the required (%s) version of libsvm on the file system (looked at: %s)" % (requirement, ', '.join(candidates))) # normalize self.include_directory = os.path.normpath(self.include_directory) # find library prefix = os.path.dirname(os.path.dirname(self.include_directory)) module = 'svm' candidates = find_library(module, version=self.version, prefixes=[prefix], only_static=only_static) if not candidates: raise RuntimeError("cannot find required libsvm binary module `%s' - make sure libsvm is installed on `%s'" % (module, prefix)) # libraries self.libraries = [] name, ext = os.path.splitext(os.path.basename(candidates[0])) if ext in ['.so', '.a', '.dylib', '.dll']: self.libraries.append(name[3:]) #strip 'lib' from the name else: #link against the whole thing self.libraries.append(':' + os.path.basename(candidates[0])) # library path self.library_directory = os.path.dirname(candidates[0])
def __init__(self, requirement='', only_static=False): """ Searches for libhdf5 in stock locations. Allows user to override. If the user sets the environment variable BOB_PREFIX_PATH, that prefixes the standard path locations. Parameters: requirement, str A string, indicating a version requirement for this library. For example, ``'>= 8.2'``. only_static, boolean A flag, that indicates if we intend to link against the static library only. This will trigger our library search to disconsider shared libraries when searching. """ import os self.name = 'hdf5' # try to locate pkg-config on our own first try: header = 'hdf5.h' candidates = find_header(header) if not candidates: raise RuntimeError( "could not find %s's `%s' - have you installed %s on this machine?" % (self.name, header, self.name)) found = False if not requirement: self.include_directories = [os.path.dirname(candidates[0])] directory = os.path.dirname(candidates[0]) version_header = os.path.join(directory, 'H5pubconf.h') self.version = libhdf5_version(version_header) found = True else: # requirement is 'operator' 'version' operator, required = [ k.strip() for k in requirement.split(' ', 1) ] # now check for user requirements for candidate in candidates: directory = os.path.dirname(candidate) version_header = os.path.join(directory, 'H5pubconf.h') vv = libhdf5_version(version_header) available = LooseVersion(vv) if (operator == '<' and available < required) or \ (operator == '<=' and available <= required) or \ (operator == '>' and available > required) or \ (operator == '>=' and available >= required) or \ (operator == '==' and available == required): self.include_directories = [os.path.dirname(candidate)] self.version = vv found = True break if not found: raise RuntimeError( "could not find the required (%s) version of %s on the file system (looked at: %s)" % (requirement, self.name, ', '.join(candidates))) # normalize self.include_directories = [ os.path.normpath(i) for i in self.include_directories ] # find library prefix = os.path.dirname( os.path.dirname(self.include_directories[0])) module = 'hdf5' candidates = find_library(module, version=self.version, prefixes=[prefix], only_static=only_static) if not candidates: raise RuntimeError( "cannot find required %s binary module `%s' - make sure libhdf5 is installed on `%s'" % (self.name, module, prefix)) # libraries self.libraries = [] name, ext = os.path.splitext(os.path.basename(candidates[0])) if ext in ['.so', '.a', '.dylib', '.dll']: self.libraries.append(name[3:]) #strip 'lib' from the name else: #link against the whole thing self.libraries.append(':' + os.path.basename(candidates[0])) # library path self.library_directories = [os.path.dirname(candidates[0])] except RuntimeError: # now, we try to use pkg-config, which seems to be only available on Debian pkg = pkgconfig('hdf5') self.include_directories = pkg.include_directories() version_header = os.path.join(self.include_directories[0], 'H5pubconf.h') self.version = libhdf5_version(version_header) self.libraries = pkg.libraries() self.library_directories = pkg.library_directories()
def __init__ (self, requirement='', only_static=False): """ Searches for libhdf5 in stock locations. Allows user to override. If the user sets the environment variable BOB_PREFIX_PATH, that prefixes the standard path locations. Parameters: requirement, str A string, indicating a version requirement for this library. For example, ``'>= 8.2'``. only_static, boolean A flag, that indicates if we intend to link against the static library only. This will trigger our library search to disconsider shared libraries when searching. """ import os self.name = 'hdf5' # try to locate pkg-config on our own first try: header = 'hdf5.h' candidates = find_header(header) if not candidates: raise RuntimeError("could not find %s's `%s' - have you installed %s on this machine?" % (self.name, header, self.name)) found = False if not requirement: self.include_directories = [os.path.dirname(candidates[0])] directory = os.path.dirname(candidates[0]) version_header = os.path.join(directory, 'H5pubconf.h') self.version = libhdf5_version(version_header) found = True else: # requirement is 'operator' 'version' operator, required = [k.strip() for k in requirement.split(' ', 1)] # now check for user requirements for candidate in candidates: directory = os.path.dirname(candidate) version_header = os.path.join(directory, 'H5pubconf.h') vv = libhdf5_version(version_header) available = LooseVersion(vv) if (operator == '<' and available < required) or \ (operator == '<=' and available <= required) or \ (operator == '>' and available > required) or \ (operator == '>=' and available >= required) or \ (operator == '==' and available == required): self.include_directories = [os.path.dirname(candidate)] self.version = vv found = True break if not found: raise RuntimeError("could not find the required (%s) version of %s on the file system (looked at: %s)" % (requirement, self.name, ', '.join(candidates))) # normalize self.include_directories = [os.path.normpath(i) for i in self.include_directories] # find library prefix = os.path.dirname(os.path.dirname(self.include_directories[0])) module = 'hdf5' candidates = find_library(module, version=self.version, prefixes=[prefix], only_static=only_static) if not candidates: raise RuntimeError("cannot find required %s binary module `%s' - make sure libhdf5 is installed on `%s'" % (self.name, module, prefix)) # libraries self.libraries = [] name, ext = os.path.splitext(os.path.basename(candidates[0])) if ext in ['.so', '.a', '.dylib', '.dll']: self.libraries.append(name[3:]) #strip 'lib' from the name else: #link against the whole thing self.libraries.append(':' + os.path.basename(candidates[0])) # library path self.library_directories = [os.path.dirname(candidates[0])] except RuntimeError: # now, we try to use pkg-config, which seems to be only available on Debian pkg = pkgconfig('hdf5') self.include_directories = pkg.include_directories() version_header = os.path.join(self.include_directories[0], 'H5pubconf.h') self.version = libhdf5_version(version_header) self.libraries = pkg.libraries() self.library_directories = pkg.library_directories()
def __init__(self, requirement='', only_static=False): """ Searches for libjpeg in stock locations. Allows user to override. If the user sets the environment variable BOB_PREFIX_PATH, that prefixes the standard path locations. Parameters: requirement, str A string, indicating a version requirement for this library. For example, ``'>= 8.2'``. only_static, boolean A flag, that indicates if we intend to link against the static library only. This will trigger our library search to disconsider shared libraries when searching. """ self.name = 'libjpeg' header = 'jpeglib.h' candidates = find_header(header) if not candidates: raise RuntimeError( "could not find %s's `%s' - have you installed %s on this machine?" % (self.name, header, self.name)) found = False if not requirement: self.include_directory = os.path.dirname(candidates[0]) self.version = libjpeg_version(candidates[0]) # special condition (using libjpeg-turbo instead) if self.version is None: turbo_candidates = find_header('jconfig.h') if turbo_candidates: self.version = libjpeg_turbo_version(turbo_candidates[0]) found = True else: # requirement is 'operator' 'version' operator, required = [k.strip() for k in requirement.split(' ', 1)] # now check for user requirements for candidate in candidates: vv = libjpeg_version(candidate) available = LooseVersion(vv) if (operator == '<' and available < required) or \ (operator == '<=' and available <= required) or \ (operator == '>' and available > required) or \ (operator == '>=' and available >= required) or \ (operator == '==' and available == required): self.include_directory = os.path.dirname(candidate) self.version = vv found = True break if not found: raise RuntimeError( "could not find the required (%s) version of %s on the file system (looked at: %s)" % (requirement, self.name, ', '.join(candidates))) # normalize self.include_directory = os.path.normpath(self.include_directory) # find library prefix = os.path.dirname(os.path.dirname(self.include_directory)) module = 'jpeg' candidates = find_library(module, version=self.version, prefixes=[prefix], only_static=only_static) if not candidates: raise RuntimeError( "cannot find required %s binary module `%s' - make sure `%s' is installed on `%s'" % (self.name, module, self.name, prefix)) # libraries self.libraries = [] name, ext = os.path.splitext(os.path.basename(candidates[0])) if ext in ['.so', '.a', '.dylib', '.dll']: self.libraries.append(name[3:]) #strip 'lib' from the name else: #link against the whole thing self.libraries.append(':' + os.path.basename(candidates[0])) # library path self.library_directory = os.path.dirname(candidates[0])