CMake: use dedicated recipe for documentation generation
authorYegor Yefremov <yegorslists@googlemail.com>
Mon, 11 Sep 2023 08:03:59 +0000 (10:03 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 10 Oct 2023 14:43:33 +0000 (16:43 +0200)
Use PROJECT_SOURCE_DIR and PROJECT_BINARY_DIR to refer to the top
source directory.

CMakeLists.txt
doc/CMakeLists.txt [new file with mode: 0644]
doc/Doxyfile.in
doc/Doxyfile.xml.in
python/CMakeLists.txt

index f36912d..24da84d 100644 (file)
@@ -142,27 +142,7 @@ add_custom_target(dist
     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
 
 if ( DOCUMENTATION )
-  find_package ( Doxygen REQUIRED)
-
-  # Copy doxy.config.in
-  set(top_srcdir ${CMAKE_SOURCE_DIR})
-  configure_file(${CMAKE_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_BINARY_DIR}/Doxyfile )
-  configure_file(${CMAKE_SOURCE_DIR}/doc/Doxyfile.xml.in ${CMAKE_BINARY_DIR}/Doxyfile.xml )
-
-  # Run doxygen
-  add_custom_command(
-    OUTPUT ${CMAKE_BINARY_DIR}/doc/html/index.html
-    COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/doc
-    COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
-    COMMENT "Generating API documentation"
-    DEPENDS ${c_headers};${c_sources};${cpp_sources};${cpp_headers}
-  )
-
-  add_custom_target(
-    docs ALL
-    COMMENT "Documentation target docs"
-    DEPENDS ${CMAKE_BINARY_DIR}/doc/html/index.html
-  )
+  add_subdirectory(doc)
 endif ( DOCUMENTATION )
 
 add_subdirectory(src)
diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt
new file mode 100644 (file)
index 0000000..983301d
--- /dev/null
@@ -0,0 +1,26 @@
+find_package ( Doxygen REQUIRED )
+
+# Copy doxy.config.in
+configure_file(
+  ${PROJECT_SOURCE_DIR}/doc/Doxyfile.in
+  ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
+)
+
+configure_file(
+  ${PROJECT_SOURCE_DIR}/doc/Doxyfile.xml.in
+  ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.xml
+)
+
+# Run doxygen
+add_custom_command(
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/html/index.html
+  COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
+  COMMENT "Generating API documentation"
+  DEPENDS ${c_headers};${c_sources};${cpp_sources};${cpp_headers}
+)
+
+add_custom_target(
+  docs ALL
+  COMMENT "Documentation target docs"
+  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/html/index.html
+)
index d7ddff8..a05fe57 100644 (file)
@@ -58,7 +58,7 @@ PROJECT_LOGO           =
 # entered, it will be relative to the location where doxygen was started. If
 # left blank the current directory will be used.
 
-OUTPUT_DIRECTORY       = doc
+OUTPUT_DIRECTORY       = @CMAKE_CURRENT_BINARY_DIR@
 
 # If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
 # directories (in 2 levels) under the output directory of each output format and
@@ -759,8 +759,8 @@ WARN_LOGFILE           =
 # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
 # Note: If this tag is empty the current directory is searched.
 
-INPUT                  = @top_srcdir@/src \
-                         @top_srcdir@/ftdipp
+INPUT                  = @PROJECT_SOURCE_DIR@/src \
+                         @PROJECT_SOURCE_DIR@/ftdipp
 
 # This tag can be used to specify the character encoding of the source files
 # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
@@ -833,7 +833,7 @@ EXCLUDE_SYMBOLS        =
 # that contain example code fragments that are included (see the \include
 # command).
 
-EXAMPLE_PATH           = @top_srcdir@/examples
+EXAMPLE_PATH           = @PROJECT_SOURCE_DIR@/examples
 
 # If the value of the EXAMPLE_PATH tag contains directories, you can use the
 # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
index 8a32509..ab57478 100644 (file)
@@ -2,7 +2,7 @@
 
 # xml generation only
 # keep settings but shut off all other generation
-@INCLUDE = Doxyfile
+@INCLUDE = doc/Doxyfile
 
 GENERATE_TODOLIST      = NO
 GENERATE_TESTLIST      = NO
index f8ac423..6ab14cd 100644 (file)
@@ -56,24 +56,28 @@ install ( TARGETS ${SWIG_MODULE_ftdi1_REAL_NAME} LIBRARY DESTINATION ${PYTHON_MO
 
 if ( DOCUMENTATION )
   # Run doxygen to only generate the xml
-  add_custom_command ( OUTPUT ${CMAKE_BINARY_DIR}/doc/xml/ftdi_8c.xml
-    COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/doc
-    COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile.xml
-    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+  add_custom_command ( OUTPUT ${PROJECT_BINARY_DIR}/doc/xml/ftdi_8c.xml
+    COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/doc/Doxyfile.xml
+    WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
+    COMMENT "Generating ftdi_8c.xml"
     DEPENDS ${c_headers};${c_sources};${cpp_sources};${cpp_headers}
   )
 
   # generate .i from doxygen .xml
   add_custom_command ( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i
     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py -n
-            ${CMAKE_BINARY_DIR}/doc/xml/ftdi_8c.xml
-            ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i
-    DEPENDS ${CMAKE_BINARY_DIR}/doc/xml/ftdi_8c.xml
+      ${PROJECT_BINARY_DIR}/doc/xml/ftdi_8c.xml
+      ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i
+    COMMENT "Generating ftdi1_doc.i from ftdi_8c.xml"
+    DEPENDS ${PROJECT_BINARY_DIR}/doc/xml/ftdi_8c.xml
+  )
+  add_custom_target ( doc_i
+    COMMENT "Python API bindings documentation"
+    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i
   )
-  add_custom_target ( doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i )
   add_dependencies( ${SWIG_MODULE_ftdi1_REAL_NAME} doc_i )
 
-endif ()
+endif ( DOCUMENTATION )
 
 set ( LIBFTDI_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/${PYTHON_MODULE_PATH} )
 set ( LIBFTDI_PYTHON_MODULE_PATH ${LIBFTDI_PYTHON_MODULE_PATH} PARENT_SCOPE ) # for ftdiconfig.cmake