Parcourir la source

cmake: Add modules docs and man target

- Add kamailio_docs_readme to produce all modules READMEs in source tree at once.
- Add kamailio_docs_man to prduce all modules man page. (if xml exist)
- Switch to add_dependencies when we depend on a target and not file.
Xenofon Karamanos il y a 8 mois
Parent
commit
1197efc315
2 fichiers modifiés avec 50 ajouts et 8 suppressions
  1. 40 8
      cmake/modules-docs.cmake
  2. 10 0
      src/modules/CMakeLists.txt

+ 40 - 8
cmake/modules-docs.cmake

@@ -3,12 +3,18 @@ option(BUILD_DOC "Build documentation" ON)
 # Readme file and man page
 # Readme file and man page
 find_program(XSLTPROC_EXECUTABLE xsltproc QUIET)
 find_program(XSLTPROC_EXECUTABLE xsltproc QUIET)
 find_program(LYNX_EXECUTABLE lynx QUIET)
 find_program(LYNX_EXECUTABLE lynx QUIET)
+find_program(DOCBOOK2X_EXECUTABLE docbook2x-man QUIET)
 
 
 if(BUILD_DOC AND (NOT XSLTPROC_EXECUTABLE OR NOT LYNX_EXECUTABLE))
 if(BUILD_DOC AND (NOT XSLTPROC_EXECUTABLE OR NOT LYNX_EXECUTABLE))
   message(WARNING "xsltproc or lynx not found but required for doc generation.")
   message(WARNING "xsltproc or lynx not found but required for doc generation.")
   set(BUILD_DOC OFF)
   set(BUILD_DOC OFF)
 endif()
 endif()
 
 
+if(BUILD_DOC AND (NOT DOCBOOK2X_EXECUTABLE))
+  message(WARNING "docbook2x-man not found but required for man generation.")
+  set(BUILD_DOC OFF)
+endif()
+
 option(DOCS_XSL_VAIDATION "Docbook document validation" OFF)
 option(DOCS_XSL_VAIDATION "Docbook document validation" OFF)
 option(DOCS_NOCATALOG
 option(DOCS_NOCATALOG
        "ON: Use standard catalog from OS | OFF: Use custom catalog " OFF)
        "ON: Use standard catalog from OS | OFF: Use custom catalog " OFF)
@@ -34,6 +40,7 @@ set(DOCS_OUTPUT_DIR
     CACHE STRING "Path to build HTML docs")
     CACHE STRING "Path to build HTML docs")
 
 
 set(DOCBOOK_DIR ${CMAKE_SOURCE_DIR}/doc/docbook)
 set(DOCBOOK_DIR ${CMAKE_SOURCE_DIR}/doc/docbook)
+set(STYLESHEET_DIR ${CMAKE_SOURCE_DIR}/doc/stylesheets)
 set(DEPS_XSL ${DOCBOOK_DIR}/dep.xsl)
 set(DEPS_XSL ${DOCBOOK_DIR}/dep.xsl)
 set(SINGLE_HTML_XSL ${DOCBOOK_DIR}/html.xsl)
 set(SINGLE_HTML_XSL ${DOCBOOK_DIR}/html.xsl)
 set(CHUNKED_HTML_XSL ${DOCBOOK_DIR}/html.chunked.xsl)
 set(CHUNKED_HTML_XSL ${DOCBOOK_DIR}/html.chunked.xsl)
@@ -82,20 +89,29 @@ function(docs_add_module module_name)
 
 
   # This is essentialy an alias of doc_text target but with extra copy command
   # This is essentialy an alias of doc_text target but with extra copy command
   # to copy the text file to the source tree directory.
   # to copy the text file to the source tree directory.
-  add_custom_target(
-    ${module_name}_readme
-    DEPENDS ${module_name}_doc_text
-    COMMENT "Processing target ${module_name}_readme")
+  add_custom_target(${module_name}_readme
+                    COMMENT "Processing target ${module_name}_readme")
+  add_dependencies(${module_name}_readme ${module_name}_doc_text)
+  add_dependencies(kamailio_docs_readme ${module_name}_readme)
 
 
   add_custom_target(
   add_custom_target(
     ${module_name}_doc_html
     ${module_name}_doc_html
     DEPENDS ${DOCS_OUTPUT_DIR}/${module_name}.html
     DEPENDS ${DOCS_OUTPUT_DIR}/${module_name}.html
     COMMENT "Processing target ${module_name}_doc_html")
     COMMENT "Processing target ${module_name}_doc_html")
 
 
-  add_custom_target(
-    ${module_name}_doc
-    DEPENDS ${module_name}_doc_text ${module_name}_doc_html
-    COMMENT "Processing target ${module_name}_doc")
+  add_custom_target(${module_name}_doc
+                    COMMENT "Processing target ${module_name}_doc")
+  add_dependencies(${module_name}_doc ${module_name}_doc_text
+                   ${module_name}_doc_html)
+
+  # Man docs only if author of module provided xml for man.
+  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}/${module_name}.xml)
+    add_custom_target(
+      ${module_name}_man
+      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}/${module_name}.xml
+      COMMENT "Processing target ${module_name}_man")
+    add_dependencies(kamailio_docs_man ${module_name}_man)
+  endif()
 
 
   # Each version has seperate custon commands for not recompiling all if 1 gets
   # Each version has seperate custon commands for not recompiling all if 1 gets
   # changed.
   # changed.
@@ -144,10 +160,26 @@ function(docs_add_module module_name)
         COMMENT "Generating html documentation for ${module_name}")
         COMMENT "Generating html documentation for ${module_name}")
     endif()
     endif()
 
 
+    add_custom_command(
+      # man version
+      OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${module_name}/${module_name}.7
+      COMMAND ${DOCBOOK2X_EXECUTABLE} -s ${STYLESHEET_DIR}/serdoc2man.xsl
+              ${module_name}.xml
+      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}/doc/${module_name}.xml
+              ${STYLESHEET_DIR}/serdoc2man.xsl
+      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}
+      COMMENT "Processing target ${module_name}_man")
+
     install(
     install(
       FILES ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}/README
       FILES ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}/README
       RENAME README.${module_name}
       RENAME README.${module_name}
       DESTINATION ${CMAKE_INSTALL_DOCDIR}/modules
       DESTINATION ${CMAKE_INSTALL_DOCDIR}/modules
       COMPONENT kamailio_docs)
       COMPONENT kamailio_docs)
+
+    install(
+      FILES ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}/${module_name}.7
+      DESTINATION ${CMAKE_INSTALL_DOCDIR}/modules
+      COMPONENT kamailio_docs
+      OPTIONAL)
   endif()
   endif()
 endfunction()
 endfunction()

+ 10 - 0
src/modules/CMakeLists.txt

@@ -130,6 +130,16 @@ foreach(module_name IN LISTS EXCLUDE_MODULES_LIST)
   endif()
   endif()
 endforeach()
 endforeach()
 
 
+# Define targets before adding the groups and modules, so that we can add
+# dependencies to them.
+add_custom_target(
+  kamailio_docs_readme
+  COMMENT
+    "Generating modules readme. Note: This will overwrite REAMDEs found in source tree"
+)
+
+add_custom_target(kamailio_docs_man COMMENT "Generating man pages")
+
 # Add each group of modules
 # Add each group of modules
 add_module_group("${FINAL_MODULES_LIST}")
 add_module_group("${FINAL_MODULES_LIST}")
 foreach(group IN LISTS FULL_MODULE_GROUP_NAMES)
 foreach(group IN LISTS FULL_MODULE_GROUP_NAMES)