Docbook & CMake for cross platform documentation

3 minute read

Docbook XML is a great technology but it takes some work to get it all setup. This post will hopefully jump start the process for you.

I’ve put together a cmake script (DocbookGen.cmake) that makes it a lot easier to convert the documentation from Docbook markup to one of several common formats: plain html, pdf, and Microsoft html help (chm files), and I put the files in a gist.

What you’ll need:

For *buntu: sudo apt-get install docbook-xsl-ns xsltproc fop cmake

xsltproc (native on Mac and linux, use cygwin installer on Windows)
The official docbook guide (for syntax reference)
hhc Microsoft HTML Help SDK for Windows.

Project structure:


You should save the DocbookGen.cmake module as described in the project structure. You may need to edit paths in the module depending on your installations.


I’ve included a basic docbook file ( with a simple book structure for creating documentation. If you are using the file unaltered you’ll also need to create a cover image for the pdf file.

By using configure_file with you can use variables in cmake to generate the common values that are needed in the documentation as well as the package and software. Docbook doesn’t have the ability to do conditional imports which is an issue because you have to import the default xsl files on each platform and they usually have different paths (especially on Windows). To get around this issue I used CMake’s ability to configure files to specify which path to use based on the platform. You can see this on line 9 in the file below.

Use the code in the CMakeLists.txt file to create the documentation files you need.


Once you’ve got the documentation built you’ll have to “install” it into the package in the CMakeLists.txt file:


Once you’ve got the process down you just need to write your documentation, docbook syntax is verbose, especially if you’re used to writing HTML or markdown.

Leave a Comment