Exhale C++ API Documentation Generator
repository·master·Indexed 42 days ago
https://github.com/svenevs/exhaleAn automatic C++ API documentation generator that bridges Doxygen and Sphinx. It utilizes Breathe to transform Doxygen's XML output into Sphinx-compatible reStructuredText, enabling the creation of Class, File, and Page hierarchies within Sphinx-based documentation websites.
What's inside Exhale
- Exhale is an automatic C++ library API documentation generator. It integrates Doxygen, Sphinx, and Breathe to revive Doxygen's Class, File, and Page hierarchies as reStructuredText documents within Sphinx projects. This allows you to maintain beautiful Sphinx-generated websites while preserving the structural hierarchies provided by Doxygen, ensuring documentation stays in sync with your code as it is regenerated on the fly.
Understand the Exhale Project Layout
masterFor developers looking to extend or understand the internal structure of Exhale, the project is organized into several functional modules:
exhale.configs: Manages configuration fromconf.pyand provides theapply_sphinx_configurationsbridge to Sphinx.exhale.deploy: Handles Doxygen execution and theexplodeprocess, which transforms Doxygen XML into reStructuredText files.exhale.graph: The core module that represents the documentation structure. It usesExhaleRoot(similar to Doxygen'sindex.xml) to instantiateExhaleNodeobjects representing documented items.exhale.parse: Responsible for parsing file-level documentation from XML and converting it into valid reStructuredText.exhale.utils: Provides helper methods for formatting, error reporting, and configuration serialization (required for Sphinx pickling).
What is Exhale and how does it work?
masterExhale is an automatic C++ library API generation utility that ports Doxygen's hierarchy view (classes and files) into the Sphinx domain.
How it works:
- It parses your existing Doxygen XML documentation.
- It reconstructs the relationship graph (e.g., which file a class belongs to, or its namespace).
- It automatically generates a large number of reStructuredText files. These files act as wrappers for Breathe directives.
- It generates a root library document that links all API documents together. You are expected to include this root document in your top-level Sphinx
toctreedirective.
Key Features:
- Emulates Doxygen's HTML class and file hierarchies.
- Includes
enumin the Class Hierarchy. - Every generated file includes a reStructuredText label, allowing you to link to specific items (like an important class) from other parts of your documentation.
Customize the Root API Document Layout
masterThe main library page (the root document) is composed of several sections. You can customize the titles and content of these sections using keys in the
exhale_argsdictionary within your Sphinxconf.py.Layout Structure:
- Title: Uses
rootFileTitle(unless\mainpageis used in Doxygen). - Description: Uses
afterTitleDescription. - Page Hierarchy: Uses
pageHierarchySubSectionTitle(only if Doxygen\page/\subpagecommands are present). - Class Hierarchy: Automatically included if class-like compounds exist.
- File Hierarchy: Automatically included.
- Hierarchy Description: Uses
afterHierarchyDescription. - API Section Title: Uses
fullApiSubSectionTitle(defaults to "Full API"). - Unabridged API: The full index of all members.
- Body Summary: Uses
afterBodySummaryat the bottom of the page.
Additional Controls:
fullToctreeMaxDepth: Controls the number of bullets shown in the unabridged API'stoctreedirectives.unabridgedOrphanKinds: Use this to exclude specific types from the full API listing.listingExclude: Exclude specific items from listings.
- Title: Uses
How Exhale integrates with Sphinx
masterExhale works as a Sphinx extension that automates the generation of reStructuredText (rst) files from Doxygen XML output. To use Exhale, you must include both
breatheandexhalein your Sphinxextensionslist withinconf.py.Execution Flow
When you run
make html, the following sequence occurs:- Extension Loading: Sphinx loads
breatheandexhale. - Configuration: Exhale hooks into the
builder-initedevent to prepare for configuration. It reads settings from theexhale_argsdictionary in yourconf.py. - Doxygen Execution: If configured, Exhale executes Doxygen to generate XML documentation.
- Explosion (RST Generation): Exhale's
explodefunction parses the Doxygen XML and generates a graph ofExhaleNodeobjects, which are then written out as individual reStructuredText documents. - Sphinx Parsing: Sphinx then picks up these newly generated
.rstfiles from your source directory and processes them into the final documentation website.
- Extension Loading: Sphinx loads
Prerequisites for using Exhale
masterBefore using Exhale, ensure you meet the following requirements:
- Valid Doxygen XML: Exhale relies on your Doxygen XML documentation. If your Doxygen build produces warnings, Exhale may produce false relationships or orphaned documents. Ensure your Doxygen configuration (and preprocessor) is correctly set up to produce clean XML.
- Breathe Extension: Exhale is built on top of the Breathe extension. You must have Breathe configured in your Sphinx
conf.pybefore configuring Exhale.
Compare Exhale with Breathe alternatives
masterExhale is specifically designed to provide Class, File, and Page hierarchies in Sphinx. If you do not need these specific hierarchies, consider these alternatives:
breathe-apidoc: A tool included withbreathethat is similar to the standard Sphinxsphinx-apidoc... autodoxygenindex::directive: A directive provided bybreathethat works well for smaller frameworks where a full hierarchy might be overkill.
Use the Exhale Graph Module to navigate documentation
masterTheexhale.graphmodule provides a graph-based representation of your documentation structure. It is composed of two primary classes:ExhaleRoot, which serves as the entry point for the documentation graph, andExhaleNode, which represents individual elements (such as classes, functions, or modules) within that graph. This module allows you to programmatically traverse and inspect the relationships between different parts of your documented code.Handle file and namespace level documentation in Exhale
masterExhale uses a "best-faith-effort" parser for file and namespace level documentation because Breathe's
ileandamespacedirectives are not directly compatible. While it supports basic block-level elements like listings, it is not a robust parser.If your documentation renders unexpectedly, you can use a verbatim reStructuredText (RST) environment to bypass the mini-parser.
Important Note on Cross-Referencing: When using a verbatim RST environment, Doxygen commands like
\refwill no longer function as links. Instead, you must use Sphinx domain links. For example:- Instead of:
\ref namespace::ClassName - Use:
:class:namespace::ClassName``
- Instead of:
Handle C++ template specialization and metaprogramming
masterExhale supports partial and full template specialization, but with some limitations:
- No Backlinks: Currently, there are no links from specialized types back to their original unspecialized types.
- Build Warnings: All template classes (specialized or not) produce build warnings from Breathe, which may result in slightly unusual layouts.
- Doxygen Preprocessor: For complex metaprogramming, you may need to ensure all necessary macros are defined in Doxygen's
PREDEFINEDsettings.
If Doxygen fails to process specific code, you can use preprocessor symbols that are only defined during the documentation build process.
Use Exhale to execute Doxygen automatically
masterExhale can be configured to execute Doxygen automatically during the documentation build process. This is the preferred method for hosting documentation on platforms like Read the Docs. To enable this, you must set up the associated configuration variables in your Sphinx configuration.
Alternatively, you can execute Doxygen independently, but you must ensure that Doxygen is run before Exhale is triggered in your build pipeline.
Create a custom Intersphinx mapping using sphobjinv
masterBecause the official BeautifulSoup
objects.invmapping is broken, you can manually create and maintain a custom mapping using thesphobjinvtool. This involves converting the binary.invfile to a human-readable.txtformat, adding your desired references using specific syntax, and converting it back to a binary file for Sphinx to use.Workflow
Install the tool:
pip install sphobjinvPrepare the base file: Download the original
objects.invfrom the target documentation and rename it to avoid conflicts.curl -O https://www.crummy.com/software/BeautifulSoup/bs4/doc/objects.inv mv objects.inv bs4_objects.invConvert to plain text: Convert the binary file to a human-readable text file.
sphobjinv convert plain bs4_objects.inv bs4_objects.txtEdit the text file: Add new references to
bs4_objects.txtfollowing the sphobjinv syntax. For example:bs4.BeautifulSoup py:class 1 index.html#beautifulsoup - bs4.BeautifulSoup.get_text py:method 1 index.html#get-text - bs4.element.Tag py:class 1 index.html#tag -Convert back to binary:
sphobjinv convert zlib bs4_objects.txt bs4_objects.invRebuild Sphinx: Clean the build to ensure the doctree index is rebuilt.
make clean html
# 1. Install pip install sphobjinv # 2. Download and rename curl -O https://www.crummy.com/software/BeautifulSoup/bs4/doc/objects.inv mv objects.inv bs4_objects.inv # 3. Convert to text sphobjinv convert plain bs4_objects.inv bs4_objects.txt # 4. (Edit bs4_objects.txt manually) # 5. Convert back to binary sphobjinv convert zlib bs4_objects.txt bs4_objects.inv # 6. Rebuild make clean html