Skip to content

Commit

Permalink
Allow linking against a system qhull as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
anntzer committed Oct 29, 2019
1 parent 5d6f889 commit a4356e8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
27 changes: 15 additions & 12 deletions INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ Dependencies
Matplotlib requires the following dependencies:

* `Python <https://www.python.org/downloads/>`_ (>= 3.6)
* `FreeType <https://www.freetype.org/>`_ (>= 2.3)
* `NumPy <http://www.numpy.org>`_ (>= 1.11)
* `setuptools <https://setuptools.readthedocs.io/en/latest/>`_
* `cycler <http://matplotlib.org/cycler/>`_ (>= 0.10.0)
Expand Down Expand Up @@ -154,24 +153,27 @@ etc., you can install the following:
* `LaTeX <https://miktex.org/>`_ and `GhostScript (>=9.0)
<https://ghostscript.com/download/>`_ : for rendering text with LaTeX.

FreeType
--------
FreeType and Qhull
------------------

Matplotlib depends on FreeType, a font rendering library. By default,
Matplotlib downloads and builds its own copy of FreeType.
Matplotlib depends on `FreeType <https://www.freetype.org/>`_ (>= 2.3), a
font rendering library, and on `Qhull <http://www.qhull.org/>`_ (>= 2015.2),
a library for computing triangulations. By default, Matplotlib downloads and
builds its own copy of FreeType, and uses its own copy of Qhull.

To force Matplotlib to use a copy of FreeType already installed in your system,
create a :file:`setup.cfg` file with the following contents:
To force Matplotlib to use a copy of FreeType or Qhull already installed in
your system, create a :file:`setup.cfg` file with the following contents:

.. code-block:: cfg
[libs]
system_freetype = true
system_qhull = true
before running ``python -m pip install .``.

In this case, you need to install the FreeType library and headers. This can
be achieved using a package manager:
In this case, you need to install the FreeType and Qhull library and headers.
This can be achieved using a package manager, e.g. for FreeType:

.. code-block:: sh
Expand All @@ -181,6 +183,8 @@ be achieved using a package manager:
brew install freetype # macOS with Homebrew
conda install freetype # conda, any OS
(adapt accordingly for Qhull).

On Linux and macOS, it is also recommended to install pkg-config_, a helper
tool for locating FreeType:

Expand All @@ -197,7 +201,7 @@ tool for locating FreeType:
.. _pkg-config: https://www.freedesktop.org/wiki/Software/pkg-config/

If not using pkg-config (in particular on Windows), you may need to set the
include path (to the FreeType headers) and link path (to the FreeType library)
include path (to the library headers) and link path (to the libraries)
explicitly, if they are not in standard locations. This can be done using
standard environment variables -- on Linux and OSX:

Expand All @@ -215,10 +219,9 @@ and on Windows:
.. note::

The following libraries are shipped with Matplotlib:
Matplotlib always uses its own copies of the following libraries:

- ``Agg``: the Anti-Grain Geometry C++ rendering engine;
- ``qhull``: to compute Delaunay triangulation;
- ``ttconv``: a TrueType font utility.

Building on Windows
Expand Down
7 changes: 4 additions & 3 deletions setup.cfg.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
[egg_info]

[libs]
# By default, Matplotlib downloads and builds its own copy of FreeType. You
# may set the following variable to True to instead link against a system
# FreeType.
# By default, Matplotlib downloads and builds its own copy of FreeType, and
# builds its own copy of Qhull. You may set the following to True to instead
# link against a system FreeType/Qhull.
#system_freetype = False
#system_qhull = False

[packages]
# There are a number of data subpackages from Matplotlib that are
Expand Down
36 changes: 16 additions & 20 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,17 @@ def write_cache(local_fn, data):


# matplotlib build options, which can be altered using setup.cfg
options = {
'backend': None,
}


setup_cfg = os.environ.get('MPLSETUPCFG', 'setup.cfg')
config = configparser.ConfigParser()
if os.path.exists(setup_cfg):
config = configparser.ConfigParser()
config.read(setup_cfg)
options['backend'] = config.get('rc_options', 'backend', fallback=None)
options['system_freetype'] = config.getboolean('libs', 'system_freetype',
fallback=False)
else:
config = None
options = {
'backend': config.get('rc_options', 'backend', fallback=None),
'system_freetype': config.getboolean('libs', 'system_freetype',
fallback=False),
'system_qhull': config.getboolean('libs', 'system_qhull',
fallback=False),
}


if '-q' in sys.argv or '--quiet' in sys.argv:
Expand Down Expand Up @@ -318,8 +315,7 @@ def get_config(cls):
insensitively defined as 0, false, no, off for False).
"""
conf = cls.default_config
if (config is not None
and config.has_option(cls.config_category, cls.name)):
if config.has_option(cls.config_category, cls.name):
try:
conf = config.getboolean(cls.config_category, cls.name)
except ValueError:
Expand Down Expand Up @@ -614,13 +610,13 @@ class Qhull(SetupPackage):
name = "qhull"

def add_flags(self, ext):
# Qhull doesn't distribute pkg-config info, so we have no way of
# knowing whether a system install is recent enough. Thus, always use
# the vendored version.
ext.include_dirs.insert(0, 'extern')
ext.sources.extend(sorted(glob.glob('extern/libqhull/*.c')))
if sysconfig.get_config_var('LIBM') == '-lm':
ext.libraries.extend('m')
if options.get('system_qhull'):
ext.libraries.append('qhull')
else:
ext.include_dirs.insert(0, 'extern')
ext.sources.extend(sorted(glob.glob('extern/libqhull/*.c')))
if sysconfig.get_config_var('LIBM') == '-lm':
ext.libraries.extend('m')


class TTConv(SetupPackage):
Expand Down

0 comments on commit a4356e8

Please sign in to comment.