Example #1
0
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
Example #2
0
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()
Example #3
0
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)
Example #4
0
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()
Example #5
0
  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()
Example #6
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()
Example #7
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()
Example #8
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()
Example #9
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()
Example #10
0
import os
package_dir = os.path.dirname(os.path.realpath(__file__))
target_dir = os.path.join(package_dir, 'bob', 'io', 'video')

packages = [
  'boost',
  'libavformat >= 52.31.0',
  'libavcodec >= 52.20.0',
  'libavutil >= 49.15.0',
  'libswscale >= 0.7.1'
  ]

define_macros = [('__STDC_CONSTANT_MACROS', None)]

# Checks if we have avformat_alloc_output_context2 defined in libavformat
libavformat_pkg = pkgconfig('libavformat >= 52.31.0')
import ctypes
lib = find_library(
    name=libavformat_pkg.libraries()[0],
    version=libavformat_pkg.version,
    prefixes=libavformat_pkg.library_directories()
    )
if lib:
  try:
    dll = ctypes.CDLL(lib[0])
    if hasattr(dll, 'avformat_alloc_output_context2'):
      define_macros.append(('HAVE_AVFORMAT_ALLOC_OUTPUT_CONTEXT2', None))
  except OSError:
    pass #ignore it

setup(