Building Graphviz from source on MacOS

Stephen Cross
4 min readAug 31, 2019
compiling graphviz-2.42.0

For general usage installing GraphViz on MacOS is fairly straightforward. GraphViz is available as a Homebrew package which can be installed as simply as:

$ brew install graphviz

However, at the time of writing, the brewed version of Graphviz 2.40.1_1 has some limitations. Graphviz can be built with several optional capabilities and plugins depending on the build flags and the libraries available on the system at build time. The current Homebrew formula excludes some of these optional capabilities, including PDF support. If you search around for information on enabling PDF support you’ll find answers that suggest using the following Homebrew installation options:

$ brew install graphviz --with-pango --with-cairo

But, since January 23, 2019 this approach no longer works. Install options where removed from Homebrew — see Remove all options from Homebrew/homebrew-core formulae #31510 as to why.

So to get Graphviz installed with any optional extras we now have to resort to building and installing from source.

Building Graphviz from source

The following steps have been tested to build graphviz version 2.42.0 (20190704.1412) on MacOX Mojave 10.14.5

First, if you have previously installed Graphviz using Homebrew, uninstall it

$ brew uninstall graphviz

Now we need to ensure we have all the required tools and library dependencies, these are installed using Homebrew with:

$ brew install autoconf autogen automake
$ brew install cairo pango gts gd librsvg libffi swig freeglut
$ brew install lasi poppler devil gtk
$ brew cask install xquartz

Get the latest Graphviz source code from https://gitlab.com/graphviz and change to the stable branch. This is currently stable_release_2.44.0

$ git clone https://gitlab.com/graphviz/graphviz.git
$ cd graphviz
# find the latest stable version
$ git tag | grep stable | sort | tail -n 1
stable_release_2.44.0
$ git checkout stable_release_2.44.0

Run the build configuration

$ export CXXFLAGS=-std=c++11
$ export PATH="/usr/local/opt/qt/bin:$PATH"
$ export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig:/usr/local/opt/qt/lib/pkgconfig:/opt/X11/lib/pkgconfig"
$ export LDFLAGS="-L/usr/local/opt/libffi/lib"
$ ./autogen.sh --with-quartz

The environment variables are required to pickup some of the libraries that Homebrew installs as “keg-only”.

Running the autogen.sh can take a few minutes, once complete you should see a summary of the enabled component, like this:

graphviz-2.42.0 will be compiled with the following:

options:
cgraph: Yes (always enabled)
digcola: Yes
expat: Yes
fontconfig: Yes
freetype: Yes
glut: Yes
ann: No (no ann.pc found)
gts: Yes
ipsepcola: Yes
ltdl: Yes
ortho: Yes
sfdp: Yes
swig: Yes ( 4.0.1 )
shared: Yes
static: No (disabled by default)
qt: Yes
x: Yes

commands:
dot: Yes (always enabled)
neato: Yes (always enabled)
fdp: Yes (always enabled)
circo: Yes (always enabled)
twopi: Yes (always enabled)
gvpr: Yes (always enabled)
gvmap: Yes (always enabled)
lefty: Yes
smyrna: No (requires: gtk+ gtkglext glade)
gvedit: Yes

A couple of options that are not enable yet are ann and smyrna. We’ll skip these for now.

  • ANN is an Approximate Nearest Neighbor Searching library from the University of Maryland. There’s no pre-built ann library for MacOS so incorporating this dependency needs further investigation.
  • Smyrna is an interactive graph viewer. I’ve not figured out how to successfully build with the required OpenGL dependencies, so we’ll skip it for now.

There are also a number of optional plugins enabled

plugin libraries:
dot_layout: Yes (always enabled)
neato_layout: Yes (always enabled)
core: Yes (always enabled)
devil: Yes
gd: Yes
gdiplus: No (disabled by default - Windows only)
gdk: Yes
gdk_pixbuf: Yes
ghostscript: No (missing Xrender)
glitz: No (disabled by default - incomplete)
gtk: Yes
lasi: Yes
ming: No (disabled by default - incomplete)
pangocairo: Yes
poppler: Yes
quartz: Yes
rsvg: Yes
visio: Yes
webp: Yes
xlib: Yes

Just one plugin left to figure out here for ghostscript. The rest are disabled by default.

There are also bunch of optional language extensions. The extensions that get built will depend on the languages installed on your system. I’m not going to cover the specifics here, if you don’t have a language already installed you probably don’t need the Graphviz extensions.

If you do need to install additional libraries and tools, run the configure script after to pick up any changes.

$ ./configure --with-quartz

Finally, we can now build and install the Graphviz binaries. The compiler will show lots of warnings which can be ignored, and hopefully no errors.

$ make
$ make install

What did we get

After all that, what have we got? The make install will place all of the Graphviz executables in /usr/local/bin, the most commonly used Graphviz command is dot. Lets check the version

$ dot -V
dot - graphviz version 2.42.0 (20190704.1412)

Now to check that we have all the expected plugins, we can use the dot command to generate a graph of the plugins and output it to a PDF.

$ dot -P -Tpdf > plugins.pdf
$ open plugins.pdf
Graphviz PDF output of installed plugins

We’ve actually built a lot more that just the main Graphviz dot executable, I’ll be exploring these more in my next article.

--

--