Graphviz:build - chunhualiao/public-docs GitHub Wiki
default build
cmake .. \
-DENABLE_PLUGIN_SUPPORT=ON \
-DBISON_EXECUTABLE=/opt/homebrew/bin/bison \
-DWITH_ANN=OFF \
-DCMAKE_INSTALL_PREFIX=$(pwd)/../local-install \
-DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang \
-DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++ \
-DCMAKE_CXX_FLAGS="-stdlib=libc++"
Turn on test suite
cmake .. \
-DENABLE_PLUGIN_SUPPORT=ON \
-DBISON_EXECUTABLE=/opt/homebrew/bin/bison \
-DWITH_ANN=OFF \
-DCMAKE_INSTALL_PREFIX=/path/to/local-install \
-Dwith_cxx_api=ON \
-Dwith_cxx_tests=ON \
-DCMAKE_CXX_STANDARD=20 \
-DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang \
-DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++ \
-DRAPIDXML_INCLUDE_DIR=$(pwd)/rapidxml \
-DSVGPP_INCLUDE_DIR=$(pwd)/svgpp \
-DCMAKE_CXX_FLAGS="-stdlib=libc++"
Appendix: Building and Running GraphViz Dot on macOS
A.1 Problems Encountered When Building GraphViz from Source
During the process of building GraphViz's dot
program from source on a Mac (Apple Silicon, macOS), several issues were encountered:
- Missing Output Formats: After building, running
dot
would fail with errors likeFormat: "png" not recognized. No formats found. Perhaps "dot -c" needs to be run (with installer's privileges) to register the plugins?
- Plugins Not Found: The required plugin shared libraries (
libgvplugin_*.dylib
) were not found by the binary, even though they were built. - CMake/Bison Version: The build process required Bison ≥ 3.0, but macOS ships with an older version. CMake would fail unless the correct Bison was installed and explicitly specified.
- ANN Library: The build system attempted to find the ANN (Approximate Nearest Neighbors) library, which is not available via Homebrew. This can be disabled with
-DWITH_ANN=OFF
. - Avoiding System Path Pollution: To avoid installing into
/usr/local
, a custom install prefix was used.
A.2 Solutions and Workarounds
-
Install Required Dependencies:
brew install pkg-config cairo pango libpng gd bison catch2
-
Link Homebrew Bison:
brew link bison --force --overwrite
-
Configure and Build with CMake:
rm -rf build mkdir build cd build cmake .. \ -DENABLE_PLUGIN_SUPPORT=ON \ -DBISON_EXECUTABLE=/opt/homebrew/bin/bison \ -DWITH_ANN=OFF \ -DCMAKE_INSTALL_PREFIX=/path/to/local-install make -j$(sysctl -n hw.ncpu) make install
-
Set Environment Variables When Running Locally:
The
dot
binary and plugins are not in system paths, so you must set:export GV_PLUGIN_PATH=/path/to/local-install/lib/graphviz export DYLD_LIBRARY_PATH=/path/to/local-install/lib/graphviz
-
Run the Local Dot Binary:
$GV_PLUGIN_PATH/dot input.dot -o output.png
Or, for benchmarking:
GV_PLUGIN_PATH=/path/to/local-install/lib/graphviz \ DYLD_LIBRARY_PATH=/path/to/local-install/lib/graphviz \ /path/to/local-install/bin/dot input.dot -o output.png
-
Script Integration:
When using scripts (e.g.,benchmark_fixed_nodes.sh
), ensure environment variables are set before the command, not aftertime
or other wrappers.
A.3 Key Lessons for macOS Builds
- Always use the Homebrew version of Bison and specify its path to CMake.
- Disable ANN if not needed.
- Use a custom install prefix to avoid polluting system directories.
- Set
GV_PLUGIN_PATH
andDYLD_LIBRARY_PATH
to the plugin directory when running locally. - If you see "No formats found" or plugin errors, check that the environment variables are set and that you are using the installed binary, not the build directory binary.
- When benchmarking, ensure the environment is set up in the script or shell.
Enabling and Running the Test Suite
To build and run the C++ test suite with CMake:
-
Enable tests during configuration:
cmake .. -Dwith_cxx_tests=ON
-
Build the tests:
make
-
Run the tests:
ctest
If you see No tests were found!!!
, make sure you configured with -Dwith_cxx_tests=ON
when running CMake.