Projects using cppdoc must have a cppdoc.toml configuration file, see CONFIG.md for the available configuration options.
To build documentation for a project:
cppdoc build
To output JSON representing the code base:
cppdoc build -d
It is possible to do so-called cached builds, where the JSON output from a previous build is reuse and only markdown pages are rendered again:
cppdoc build --cached <file>
Cached builds are useful when working on documentation outside of code changes.
More command-line options can be displayed using -h or --help.
Comments are written using /// or ///<, the latter being used for inline documentation, as such:
/// Documentation for 'MyEnum'
enum MyEnum {
A ///< Documentation for 'A'
}It is also possible to use /** and /**< C-style comments:
/**
* Documentation for 'MyEnum'
*/
enum MyEnum {
A /**< Documentation for 'A' */
}Comments content are parsed as cppdoc-flavored markdown, there is no support for javadoc/Doxygen-style comments.
Elements can be hidden by annotating them with #[doc(hidden)]
/// #[doc(hidden)]
struct Hidden {}cppdoc introduces a few extensions to markdown.
- To link documentation objects, one must prefix the link path with
::. For example:
See [MyStruct](::MyStruct)
- Mermaid graphs can be displayed using
mermaidcodeblocks:
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
cppdoc supports running documentation tests akin to rustdoc, these tests are written in cpp and c++ code blocks and help ensure that code examples are up-to-date with API usage.
Documentation code blocks feature special syntax:
- Lines prefixed with
@won't be displayed, but will be added to the source code:
@int a = 1;
int b = a + 2;
Will only display:
int b = a + 2;
But will be compiled fully, that is with int a = 1 included.
- Similarly,
@includeallows for quiet inclusion of a header file:
@include "file.h"
int a = 1;
Will only display:
int a = 1;
Notice that documentation tests don't need a main function, this is because documentation tests run by default in main. To disable this behavior one must set the codeblock language to nomain instead of c++ or cpp.
cppdoc includes a basic test framework for documentation tests, this is useful for testing that examples still run successfully.
The following macros are defined:
ASSERTandASSERT_EQ: test for truth and equality, respectivelyASSERT_FALSEandASSERT_NE: test for falsity and inequality, respectivelyASSERT_GTandASSERT_LT: test for greater than and less than, respectivelyASSERT_GEandASSERT_LE: test for greater than or equal and less than or equal, respectively
Therefore, it is possible to write code like so:
int a = 1;
ASSERT(a == 1);The code above will compile and run successfully, but the following code will fail to run:
int a = 2;
ASSERT(a == 1);cppdoc expects a style.css file to be present at the root of the generated documentation and generates a highlight.css file from the syntax highlighting theme. It is recommended to put the style sheets in a static directory and set the static option in the configuration file.