Embed module dependency graph in Doxygen docs
[alexxy/gromacs.git] / docs / doxygen / CMakeLists.txt
index 1e334a4fa8dfeb02e6d44621e70ec7cf0e1cbbe4..9d439695b3a0c685214d8a92a15cb4004545296d 100644 (file)
@@ -38,7 +38,7 @@ find_package(Doxygen QUIET)
 if (DOXYGEN_FOUND)
     # This logic closely follows that found in FindDoxygen.cmake for dot,
     # except that the PATH variable is not cached.
-    FIND_PROGRAM(DOXYGEN_MSCGEN_EXECUTABLE
+    find_program(DOXYGEN_MSCGEN_EXECUTABLE
         NAMES mscgen
         DOC "Message sequence chart renderer tool (http://www.mcternan.me.uk/mscgen/)")
     if (DOXYGEN_MSCGEN_EXECUTABLE)
@@ -61,79 +61,73 @@ if (PYTHONINTERP_FOUND AND NOT PYTHON_VERSION_STRING VERSION_LESS "2.6")
     set(USE_PYTHON_SCRIPTS ON)
 endif()
 
-add_custom_target(find-installed-headers
+# Create a stamp file whenever cmake is run, as the list of installed files may
+# have changed.
+set(CONFIGURE_STAMP_FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake-stamp.txt)
+file(WRITE ${CONFIGURE_STAMP_FILE} "Stamp for configuration")
+# Note that if you relocate this file, you also need to change gmxtree.py.
+set(INSTALLED_HEADERS_FILE ${CMAKE_CURRENT_BINARY_DIR}/installed-headers.txt)
+add_custom_command(OUTPUT ${INSTALLED_HEADERS_FILE}
     COMMAND ${CMAKE_COMMAND}
         -D SRCDIR=${CMAKE_SOURCE_DIR}
         -D BUILDDIR=${CMAKE_BINARY_DIR}
-        -D OUTFILE=${CMAKE_CURRENT_BINARY_DIR}/installed-headers.txt
+        -D OUTFILE=${INSTALLED_HEADERS_FILE}
         -P ${CMAKE_CURRENT_SOURCE_DIR}/getInstalledHeaders.cmake
+    DEPENDS ${CONFIGURE_STAMP_FILE}
     COMMENT "Generating installed headers list" VERBATIM)
+add_custom_target(find-installed-headers DEPENDS ${INSTALLED_HEADERS_FILE})
 
 ########################################################################
 # Doxygen configuration
 ########################################################################
 if (DOXYGEN_FOUND)
-    FILE(GLOB NB_KERNEL_DIRS
+    file(GLOB NB_KERNEL_DIRS
          ${CMAKE_SOURCE_DIR}/src/gromacs/gmxlib/nonbonded/nb_kernel_*/)
-    LIST(REMOVE_ITEM NB_KERNEL_DIRS
+    list(REMOVE_ITEM NB_KERNEL_DIRS
          ${CMAKE_SOURCE_DIR}/src/gromacs/gmxlib/nonbonded/nb_kernel_c)
-    FOREACH(NB_KERNEL_DIR ${NB_KERNEL_DIRS})
+    foreach (NB_KERNEL_DIR ${NB_KERNEL_DIRS})
         SET(NB_KERNEL_DIRS_TO_IGNORE_IN_DOXYGEN
             "${NB_KERNEL_DIRS_TO_IGNORE_IN_DOXYGEN} \\\n                         ${NB_KERNEL_DIR}")
-    ENDFOREACH(NB_KERNEL_DIR)
+    endforeach()
+    set(DEPGRAPH_DIR ${CMAKE_CURRENT_BINARY_DIR}/depgraphs)
     set(DOXYGEN_SECTIONS "")
-    CONFIGURE_FILE(Doxyfile-common.cmakein Doxyfile-common)
-    CONFIGURE_FILE(Doxyfile-full.cmakein Doxyfile-full)
-    CONFIGURE_FILE(Doxyfile-lib.cmakein Doxyfile-lib)
-    CONFIGURE_FILE(Doxyfile-user.cmakein Doxyfile-user)
-    CONFIGURE_FILE(Doxyfile-xml.cmakein Doxyfile-xml)
-
+    set(DOXYGEN_EXTRA_SETTINGS "")
     if (GMX_COMPACT_DOXYGEN)
-        FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-common
-             "@INCLUDE   = ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile-compact\n")
+        set(DOXYGEN_EXTRA_SETTINGS "@INCLUDE   = ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile-compact")
     endif()
+    configure_file(Doxyfile-common.cmakein Doxyfile-common)
+    configure_file(Doxyfile-full.cmakein Doxyfile-full)
+    configure_file(Doxyfile-lib.cmakein Doxyfile-lib)
+    configure_file(Doxyfile-user.cmakein Doxyfile-user)
+    configure_file(Doxyfile-xml.cmakein Doxyfile-xml)
 
     configure_file(RunDoxygen.cmake.cmakein RunDoxygen.cmake @ONLY)
-    add_custom_target(doc-full
-        ${CMAKE_COMMAND} -DDOCTYPE=full -P RunDoxygen.cmake
-        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
-        COMMENT "Generating full documentation with Doxygen" VERBATIM)
-    add_custom_target(doc-lib
-        ${CMAKE_COMMAND} -DDOCTYPE=lib -P RunDoxygen.cmake
-        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
-        COMMENT "Generating library documentation with Doxygen" VERBATIM)
-    add_custom_target(doc-user
-        ${CMAKE_COMMAND} -DDOCTYPE=user -P RunDoxygen.cmake
-        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
-        COMMENT "Generating public API documentation with Doxygen" VERBATIM)
-    add_custom_target(doc-xml
-        ${CMAKE_COMMAND} -DDOCTYPE=xml -P RunDoxygen.cmake
-        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
-        COMMENT "Extracting Doxygen documentation to XML" VERBATIM)
+    gmx_configure_version_file(Doxyfile-version.cmakein Doxyfile-version
+                               TARGET doxygen-version)
+
+    function (add_doxygen_target TARGET TYPE COMMENT)
+        add_custom_target(${TARGET}
+            # Ensure the directory exists to avoid spurious warnings
+            ${CMAKE_COMMAND} -E make_directory ${DEPGRAPH_DIR}
+            COMMAND ${CMAKE_COMMAND} -DDOCTYPE=${TYPE} -P RunDoxygen.cmake
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+            COMMENT "${COMMENT}" VERBATIM)
+        add_dependencies(${TARGET} doxygen-version)
+    endfunction()
+    # The targets ending with -fast do the same thing as the target without the
+    # suffix, but assume that time-consuming dependencies have already been
+    # built, making it faster and more convenient to test a single part of the
+    # system.
+    add_doxygen_target(doc-full      full "Generating full documentation with Doxygen")
+    add_doxygen_target(doc-full-fast full "Generating full documentation with Doxygen")
+    add_doxygen_target(doc-lib       lib  "Generating library documentation with Doxygen")
+    add_doxygen_target(doc-lib-fast  lib  "Generating library documentation with Doxygen")
+    add_doxygen_target(doc-user      user "Generating public API documentation with Doxygen")
+    add_doxygen_target(doc-xml       xml  "Extracting Doxygen documentation to XML")
     add_custom_target(doc-all)
+    add_custom_target(doc-all-fast)
     add_dependencies(doc-all doc-full doc-lib doc-user)
-
-    if (GMX_GIT_VERSION_INFO)
-        add_custom_target(doxygen-version
-                COMMAND ${CMAKE_COMMAND}
-                    -D GIT_EXECUTABLE="${GIT_EXECUTABLE}"
-                    -D PROJECT_VERSION="${PROJECT_VERSION}"
-                    -D PROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}"
-                    -D VERSION_CMAKEIN="${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile-version.cmakein"
-                    -D VERSION_OUT="${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-version"
-                    -D VERSION_NO_REMOTE_HASH=
-                    -P ${CMAKE_SOURCE_DIR}/cmake/gmxGenerateVersionInfo.cmake
-                WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-                DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile-version.cmakein
-                COMMENT "Generating version information for Doxygen")
-        add_dependencies(doc-full doxygen-version)
-        add_dependencies(doc-lib doxygen-version)
-        add_dependencies(doc-user doxygen-version)
-        add_dependencies(doc-xml doxygen-version)
-    else()
-        set(GMX_PROJECT_VERSION_STR ${PROJECT_VERSION})
-        configure_file(Doxyfile-version.cmakein Doxyfile-version)
-    endif()
+    add_dependencies(doc-all-fast doc-full-fast doc-lib-fast doc-user)
 
     if (USE_PYTHON_SCRIPTS)
         # TODO: Consider whether this is the best name and location for this
@@ -142,37 +136,46 @@ if (DOXYGEN_FOUND)
         set(doc_check_command
             ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxygen-check.py
             -S ${CMAKE_SOURCE_DIR} -B ${CMAKE_BINARY_DIR}
-            --installed ${CMAKE_CURRENT_BINARY_DIR}/installed-headers.txt
             -l ${CMAKE_CURRENT_BINARY_DIR}/doxygen-check.log
-            --ignore ${CMAKE_CURRENT_SOURCE_DIR}/suppressions.txt)
+            --exitcode
+            --ignore ${CMAKE_CURRENT_SOURCE_DIR}/suppressions.txt
+            --ignore-cycles ${CMAKE_CURRENT_SOURCE_DIR}/cycle-suppressions.txt)
         add_custom_target(doc-check COMMAND ${doc_check_command}
             COMMENT "Checking Doxygen documentation" VERBATIM)
         add_dependencies(doc-check doc-xml find-installed-headers)
+        add_custom_target(doc-check-fast COMMAND ${doc_check_command}
+            COMMENT "Checking Doxygen documentation" VERBATIM)
+        add_dependencies(doc-check-fast find-installed-headers)
 
-        set(graphdir ${CMAKE_CURRENT_BINARY_DIR}/depgraphs)
         set(dep_graphs_command_python
             ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/graphbuilder.py
             -S ${CMAKE_SOURCE_DIR} -B ${CMAKE_BINARY_DIR}
-            --installed ${CMAKE_CURRENT_BINARY_DIR}/installed-headers.txt
-            -o ${CMAKE_CURRENT_BINARY_DIR}/depgraphs)
+            --ignore-cycles ${CMAKE_CURRENT_SOURCE_DIR}/cycle-suppressions.txt
+            -o ${DEPGRAPH_DIR})
         set(dep_graphs_command_dot
-            ${CMAKE_COMMAND} -DGRAPHDIR=${graphdir}
+            ${CMAKE_COMMAND} -DGRAPHDIR=${DEPGRAPH_DIR}
             -DDOT_EXECUTABLE=${DOXYGEN_DOT_EXECUTABLE}
             -P ${CMAKE_CURRENT_SOURCE_DIR}/generateGraphs.cmake)
-        add_custom_target(dep-graphs
+        add_custom_target(dep-graphs-dot
             COMMAND ${dep_graphs_command_python}
+            COMMENT "Generating include dependency graphs for dot" VERBATIM)
+        add_custom_target(dep-graphs
             COMMAND ${dep_graphs_command_dot}
-            COMMENT "Generating include dependency graphs" VERBATIM)
-        add_dependencies(dep-graphs doc-xml find-installed-headers)
+            COMMENT "Generating PNG include dependency graphs" VERBATIM)
+        add_dependencies(dep-graphs-dot doc-xml find-installed-headers)
+        add_dependencies(dep-graphs dep-graphs-dot)
+        add_dependencies(doc-full dep-graphs-dot)
+        add_dependencies(doc-lib dep-graphs-dot)
 
-        # These targets are the same as above, but they don't rerun the
-        # dependencies each time, making it faster and more convenient for
-        # testing.
-        add_custom_target(doc-check-fast COMMAND ${doc_check_command}
-            COMMENT "Checking Doxygen documentation" VERBATIM)
-        add_custom_target(dep-graphs-fast
+        add_custom_target(dep-graphs-dot-fast
             COMMAND ${dep_graphs_command_python}
+            COMMENT "Generating include dependency graphs for dot" VERBATIM)
+        add_custom_target(dep-graphs-fast
             COMMAND ${dep_graphs_command_dot}
-            COMMENT "Generating include dependency graphs" VERBATIM)
+            COMMENT "Generating PNG include dependency graphs" VERBATIM)
+        # Finding the installed headers doesn't actually run again if nothing
+        # has changed, so that can be safely added as a dependency.
+        add_dependencies(dep-graphs-dot-fast find-installed-headers)
+        add_dependencies(dep-graphs-fast dep-graphs-dot-fast)
     endif()
 endif()