Author: Luca Boccassi <bluca@debian.org>
Forwarded: https://github.com/rpm-software-management/dnf5/pull/2973
Description: Build documentation without Python bindings
 Sphinx AutoAPI requires the generated Python binding sources, which are not
 available when WITH_PYTHON3 is disabled. Enable AutoAPI and include the
 Python API documentation only when those bindings are built.
--- a/doc/CMakeLists.txt
+++ b/doc/CMakeLists.txt
@@ -18,6 +18,7 @@
         OUTPUT ${PROCESSED_DIR}/${RST_SOURCE}
         COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/atp.py
             --define "WITH_MODULEMD=${WITH_MODULEMD}"
+            --define "WITH_PYTHON3=${WITH_PYTHON3}"
             ${CMAKE_CURRENT_SOURCE_DIR}/${RST_SOURCE} ${PROCESSED_DIR}/${RST_SOURCE}
         COMMENT "Preprocessing ${RST_SOURCE}"
         DEPENDS ${RST_SOURCE} ${CMAKE_CURRENT_SOURCE_DIR}/atp.py
--- a/doc/api/index.rst
+++ b/doc/api/index.rst
@@ -6,7 +6,9 @@
 .. toctree::
     :maxdepth: 2
 
+    @IF WITH_PYTHON3@
     python/python
+    @ENDIF@
     c++/cpp
     changes_dnf5.2
     changes_dnf5.3
--- a/doc/conf.py.in
+++ b/doc/conf.py.in
@@ -39,8 +39,9 @@
 # ones.
 extensions = [
     'breathe',
-    'autoapi.extension',
 ]
+if '@WITH_PYTHON3@' == 'ON':
+    extensions += ['autoapi.extension']
 breathe_projects = {'dnf5': '@CMAKE_CURRENT_BINARY_DIR@/xml/'}
 breathe_default_project = 'dnf5'
 
@@ -72,6 +73,8 @@
 # directories to ignore when looking for source files.
 # This pattern also affects html_static_path and html_extra_path.
 exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
+if '@WITH_PYTHON3@' != 'ON':
+    exclude_patterns += ['api/python/**']
 
 
 # -- Options for HTML output -------------------------------------------------
