From c04d53d32513a48187aa51efc9e99e9a140a2689 Mon Sep 17 00:00:00 2001
From: Tom Rondeau <trondeau@vt.edu>
Date: Sun, 27 Nov 2011 20:27:35 -0500
Subject: docs: added doxygen and swig docs building tools into howto (cmake
 version only).

---
 .../cmake/Modules/GrSwig.cmake                     | 75 ++++++++++++++++++++++
 1 file changed, 75 insertions(+)

(limited to 'gr-howto-write-a-block-cmake/cmake/Modules')

diff --git a/gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake b/gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake
index 51d9203dd6..47e18085bc 100644
--- a/gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake
+++ b/gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake
@@ -24,6 +24,71 @@ set(__INCLUDED_GR_SWIG_CMAKE TRUE)
 
 include(GrPython)
 
+########################################################################
+# Builds a swig documentation file to be generated into python docstrings
+# Usage: GR_SWIG_MAKE_DOCS(output_file input_path input_path....)
+#
+# Set the following variable to specify extra dependent targets:
+#   - GR_SWIG_DOCS_SOURCE_DEPS
+#   - GR_SWIG_DOCS_TARGET_DEPS
+########################################################################
+function(GR_SWIG_MAKE_DOCS output_file)
+    find_package(Doxygen)
+    if(DOXYGEN_FOUND)
+
+        #setup the input files variable list, quote formated
+        set(input_files)
+        unset(INPUT_PATHS)
+        foreach(input_path ${ARGN})
+            if (IS_DIRECTORY ${input_path}) #when input path is a directory
+                file(GLOB input_path_h_files ${input_path}/*.h)
+            else() #otherwise its just a file, no glob
+                set(input_path_h_files ${input_path})
+            endif()
+            list(APPEND input_files ${input_path_h_files})
+            set(INPUT_PATHS "${INPUT_PATHS} \"${input_path}\"")
+        endforeach(input_path)
+
+        #determine the output directory
+        get_filename_component(name ${output_file} NAME_WE)
+        get_filename_component(OUTPUT_DIRECTORY ${output_file} PATH)
+        set(OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY}/${name}_swig_docs)
+        make_directory(${OUTPUT_DIRECTORY})
+
+        #generate the Doxyfile used by doxygen
+        configure_file(
+            ${CMAKE_SOURCE_DIR}/docs/doxygen/Doxyfile.swig_doc.in
+            ${OUTPUT_DIRECTORY}/Doxyfile
+        @ONLY)
+
+        #Create a dummy custom command that depends on other targets
+        include(GrMiscUtils)
+        GR_GEN_TARGET_DEPS(_${name}_tag tag_deps ${GR_SWIG_DOCS_TARGET_DEPS})
+
+        #call doxygen on the Doxyfile + input headers
+        add_custom_command(
+            OUTPUT ${OUTPUT_DIRECTORY}/xml/index.xml
+            DEPENDS ${input_files} ${GR_SWIG_DOCS_SOURCE_DEPS} ${tag_deps}
+            COMMAND ${DOXYGEN_EXECUTABLE} ${OUTPUT_DIRECTORY}/Doxyfile
+            COMMENT "Generating doxygen xml for ${name} docs"
+        )
+
+        #call the swig_doc script on the xml files
+        add_custom_command(
+            OUTPUT ${output_file}
+            DEPENDS ${input_files} ${OUTPUT_DIRECTORY}/xml/index.xml
+            COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+                ${CMAKE_SOURCE_DIR}/docs/doxygen/swig_doc.py
+                ${OUTPUT_DIRECTORY}/xml
+                ${output_file}
+            WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/docs/doxygen
+        )
+
+    else(DOXYGEN_FOUND)
+        file(WRITE ${output_file} "\n") #no doxygen -> empty file
+    endif(DOXYGEN_FOUND)
+endfunction(GR_SWIG_MAKE_DOCS)
+
 ########################################################################
 # Build a swig target for the common gnuradio use case. Usage:
 # GR_SWIG_MAKE(target ifile ifile ifile...)
@@ -34,10 +99,20 @@ include(GrPython)
 #   - GR_SWIG_LIBRARIES
 #   - GR_SWIG_SOURCE_DEPS
 #   - GR_SWIG_TARGET_DEPS
+#   - GR_SWIG_DOC_FILE
+#   - GR_SWIG_DOC_DIRS
 ########################################################################
 macro(GR_SWIG_MAKE name)
     set(ifiles ${ARGN})
 
+    #do swig doc generation if specified
+    if (GR_SWIG_DOC_FILE)
+        set(GR_SWIG_DOCS_SOURCE_DEPS ${GR_SWIG_SOURCE_DEPS})
+        set(GR_SWIG_DOCS_TAREGT_DEPS ${GR_SWIG_TARGET_DEPS})
+        GR_SWIG_MAKE_DOCS(${GR_SWIG_DOC_FILE} ${GR_SWIG_DOC_DIRS})
+        list(APPEND GR_SWIG_SOURCE_DEPS ${GR_SWIG_DOC_FILE})
+    endif()
+
     #append additional include directories
     find_package(PythonLibs)
     list(APPEND GR_SWIG_INCLUDE_DIRS ${PYTHON_INCLUDE_PATH}) #deprecated name (now dirs)
-- 
cgit v1.2.3