How to do it

Compared to the previous recipe, we will modify the root CMakeLists.txt file, and will also implement a function (add_sphinx_doc):

  1. After appending the cmake folder to the CMAKE_MODULE_PATH, we include the UseSphinxDoc.cmake custom module, as follows:
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")include(UseSphinxDoc)
  1. The UseSphinxDoc.cmake module defines the add_sphinx_doc function. We call this function with keyword arguments, in order to set up our Sphinx documentation build. The custom documentation target will be called docs:
add_sphinx_doc(  SOURCE_DIR    ${CMAKE_CURRENT_SOURCE_DIR}/docs  BUILD_DIR    ${CMAKE_CURRENT_BINARY_DIR}/_build  CACHE_DIR    ${CMAKE_CURRENT_BINARY_DIR}/_doctrees  HTML_DIR ${CMAKE_CURRENT_BINARY_DIR}/sphinx_html ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.