From 90f39874bd122ca9e966f32c01e43e922031018e Mon Sep 17 00:00:00 2001
From: Moritz Haase <Moritz.Haase@bmw.de>
Date: Mon, 23 Jun 2025 09:21:07 +0200
Subject: [PATCH] cmake: Allow builds without Doxygen being present with CMake
 4+

With CMake 4+, the initial CMake run fails with

    CMake Error at doc/CMakeLists.txt:18 (ADD_DEPENDENCIES):
      The dependency target "doc-c" of target "doc" does not exist.

in case Doxygen is not installed on the system, since non-existent dependencies
are not ignored anymore (see [0]). Rectify that by making sure that we only add
the dependency in case Doxygen has been found.

[0]: https://cmake.org/cmake/help/latest/policy/CMP0046.html

Upstream-Status: Backport [908e3a4a5909ab107da41c2631a06c6b23617f3c]
Signed-off-by: Moritz Haase <Moritz.Haase@bmw.de>
---
 doc/CMakeLists.txt | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt
index 6b2ef5e0593757c7b977cd5d228b7774b4f45641..6332b91260ff87f16e331071e652bfe0b167f518 100644
--- a/doc/CMakeLists.txt
+++ b/doc/CMakeLists.txt
@@ -1,11 +1,15 @@
 ADD_SUBDIRECTORY (python)

+ADD_CUSTOM_TARGET (doc)
+ADD_DEPENDENCIES (doc doc-python)
+
 find_package(Doxygen)
 if(DOXYGEN_FOUND)
     CONFIGURE_FILE("Doxyfile.in.in" "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.in" @ONLY)
     add_custom_target(doc-c
         ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.in
         COMMENT "Building C API documentation with Doxygen" VERBATIM)
+    ADD_DEPENDENCIES (doc doc-c)
 endif(DOXYGEN_FOUND)

 IF(CREATEREPO_C_INSTALL_MANPAGES)
@@ -13,6 +17,3 @@ IF(CREATEREPO_C_INSTALL_MANPAGES)
             DESTINATION "${CMAKE_INSTALL_MANDIR}/man8"
             COMPONENT bin)
 ENDIF(CREATEREPO_C_INSTALL_MANPAGES)
-
-ADD_CUSTOM_TARGET (doc)
-ADD_DEPENDENCIES (doc doc-python doc-c)
