Improve stability of parallel documentation build
[alexxy/gromacs.git] / docs / doxygen / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
8 #
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
13 #
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23 #
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
31 #
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
34
35 include(gmxCustomCommandUtilities)
36 include(gmxOptionUtilities)
37
38 find_package(Doxygen QUIET)
39 if (DOXYGEN_FOUND)
40     # This logic closely follows that found in FindDoxygen.cmake for dot,
41     # except that the PATH variable is not cached.
42     find_program(DOXYGEN_MSCGEN_EXECUTABLE
43         NAMES mscgen
44         DOC "Message sequence chart renderer tool (http://www.mcternan.me.uk/mscgen/)")
45     if (DOXYGEN_MSCGEN_EXECUTABLE)
46         set(DOXYGEN_MSCGEN_FOUND TRUE)
47         get_filename_component(DOXYGEN_MSCGEN_PATH "${DOXYGEN_MSCGEN_EXECUTABLE}" PATH)
48     endif()
49     mark_as_advanced(DOXYGEN_MSCGEN_EXECUTABLE)
50 endif()
51
52 gmx_dependent_option(
53     GMX_COMPACT_DOXYGEN
54     "Skip parts of Doxygen documentation (in particular, many graphs) to save disk space and time"
55     OFF
56     DOXYGEN_FOUND)
57 mark_as_advanced(GMX_COMPACT_DOXYGEN)
58
59 set(USE_PYTHON_SCRIPTS OFF)
60 if (PYTHONINTERP_FOUND AND NOT PYTHON_VERSION_STRING VERSION_LESS "2.6")
61     set(USE_PYTHON_SCRIPTS ON)
62 endif()
63
64 # Note that if you relocate this file, you also need to change gmxtree.py.
65 # TODO: Try to find a solution where this would be hard-coded here, completely
66 # separate from the logic that generates it.
67 set(INSTALLED_HEADERS_FILE ${PROJECT_BINARY_DIR}/src/gromacs/installed-headers.txt)
68
69 ########################################################################
70 # Doxygen configuration
71 #
72 if (DOXYGEN_FOUND)
73     # Generate Doxygen input configuration files
74     file(GLOB NB_KERNEL_DIRS
75          ${CMAKE_SOURCE_DIR}/src/gromacs/gmxlib/nonbonded/nb_kernel_*/)
76     list(REMOVE_ITEM NB_KERNEL_DIRS
77          ${CMAKE_SOURCE_DIR}/src/gromacs/gmxlib/nonbonded/nb_kernel_c)
78     foreach (dir ${NB_KERNEL_DIRS})
79         SET(NB_KERNEL_DIRS_TO_IGNORE_IN_DOXYGEN
80             "${NB_KERNEL_DIRS_TO_IGNORE_IN_DOXYGEN} \\\n                         ${dir}")
81     endforeach()
82     set(DEPGRAPH_DIR ${CMAKE_CURRENT_BINARY_DIR}/depgraphs)
83     set(DOXYGEN_SECTIONS "")
84     set(DOXYGEN_EXTRA_SETTINGS "")
85     if (GMX_COMPACT_DOXYGEN)
86         set(DOXYGEN_EXTRA_SETTINGS "@INCLUDE   = ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile-compact")
87     endif()
88     set(DOXYGENLIST "html-full;html-lib;html-user;xml")
89     foreach(_target ${DOXYGENLIST})
90         set(_targetdir ${HTML_OUTPUT_DIR}/doxygen/${_target})
91         if (NOT EXISTS ${_targetdir})
92             file(MAKE_DIRECTORY ${_targetdir})
93         endif()
94     endforeach()
95     set(DOXYGENLIST "common;dev;full;lib;user;xml")
96     foreach(_target ${DOXYGENLIST})
97         configure_file(Doxyfile-${_target}.cmakein Doxyfile-${_target})
98     endforeach()
99
100     configure_file(RunDoxygen.cmake.cmakein RunDoxygen.cmake @ONLY)
101     gmx_configure_version_file(Doxyfile-version.cmakein Doxyfile-version
102                                TARGET doxygen-version)
103
104     # Add a stamp that gets updated whenever a source file that contributes to
105     # Doxygen is updated.  All Doxygen targets can then depend on this stamp,
106     # instead of each specifying this massive set of dependencies.
107     # TODO: The set of files that affects Doxygen is not exactly the same as
108     # that which affects the dependency graphs, and neither is captured
109     # perfectly with this set, but this can be improved if it becomes a real
110     # issue (the differences are mainly in the generated group kernel files,
111     # but there are some minor other differences as well).
112     if (SOURCE_IS_GIT_REPOSITORY AND GIT_FOUND)
113         gmx_get_files_with_gitattribute(doxygen_sources gmx-doxygen)
114         # Add also common configuration files that influence the generation.
115         set(doxygen_deps
116             ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-common
117             ${CMAKE_CURRENT_BINARY_DIR}/RunDoxygen.cmake)
118         if (GMX_COMPACT_DOXYGEN)
119             list(APPEND doxygen_deps ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile-compact)
120         endif()
121         gmx_add_custom_output_target(doxygen-source-timestamp
122             OUTPUT STAMP
123             DEPENDS_FILE_LIST doxygen_sources
124             DEPENDS ${doxygen_deps}
125             COMMENT "Updating Doxygen source timestamp")
126     else()
127         # If there is no git, we just update the stamp every time, and the
128         # builds are triggered every time.  This should be rare enough, but
129         # this case still needs to be supported for the Jenkins job that builds
130         # the documentation for a release from the release tarball.
131         gmx_add_custom_output_target(doxygen-source-timestamp
132             RUN_ALWAYS OUTPUT STAMP
133             COMMENT "Updating Doxygen source timestamp")
134     endif()
135
136     # Helper function to create a Doxygen build target
137     function (add_doxygen_target TARGET TYPE COMMENT)
138         set(_deps doxygen-source-timestamp doxygen-version
139             ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-${TYPE})
140         set(_fast_arg "")
141         list (FIND ARGN "DEPGRAPHS" _index)
142         if (${_index} GREATER -1)
143             set(_fast_arg "ADD_FAST_TARGET")
144             if (TARGET dep-graphs-dot)
145                 list(APPEND _deps dep-graphs-dot)
146             endif()
147         endif()
148         list (FIND ARGN "DEPXML" _index)
149         if (${_index} GREATER -1)
150             list(APPEND _deps doxygen-xml)
151         endif()
152         gmx_add_custom_output_target(${TARGET} OUTPUT STAMP ${_fast_arg}
153             # Ensure the directory exists to avoid spurious warnings
154             COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPGRAPH_DIR}
155             COMMAND ${CMAKE_COMMAND} -DDOCTYPE=${TYPE} -P RunDoxygen.cmake
156             DEPENDS ${_deps}
157             WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
158             COMMENT "${COMMENT}" USES_TERMINAL)
159         if (_fast_arg)
160             add_dependencies(${TARGET}-fast doxygen-version)
161         endif()
162     endfunction()
163
164     # The XML target is necessary for the dependency graphs
165     add_doxygen_target(doxygen-xml xml "Extracting Doxygen documentation to XML")
166
167     # Add targets for generating the dependency graphs; they are necessary for
168     # the full and lib variants of the documentation.
169     if (USE_PYTHON_SCRIPTS)
170         # Add target that generates .dot files for the dependency graphs.
171         # The output also depends on the Doxygen source files, but the
172         # dependency on doxygen-xml takes care of that transitively.
173         gmx_add_custom_output_target(dep-graphs-dot ADD_FAST_TARGET
174             OUTPUT STAMP
175             COMMAND ${PYTHON_EXECUTABLE}
176                 ${CMAKE_CURRENT_SOURCE_DIR}/graphbuilder.py
177                 -S ${CMAKE_SOURCE_DIR} -B ${CMAKE_BINARY_DIR}
178                 --ignore-cycles ${CMAKE_CURRENT_SOURCE_DIR}/cycle-suppressions.txt
179                 -o ${DEPGRAPH_DIR}
180             DEPENDS doxygen-xml ${INSTALLED_HEADER_FILE}
181                 ${CMAKE_CURRENT_SOURCE_DIR}/doxygenxml.py
182                 ${CMAKE_CURRENT_SOURCE_DIR}/gmxtree.py
183                 ${CMAKE_CURRENT_SOURCE_DIR}/graphbuilder.py
184                 ${CMAKE_CURRENT_SOURCE_DIR}/cycle-suppressions.txt
185             COMMENT "Generating include dependency graphs for dot"
186             USES_TERMINAL)
187
188         # Add separate targets for converting the .dot files to .png.
189         # These are not needed by the Doxygen targets, but are useful for
190         # investigating just the graphs.
191         set(dep_graphs_command_dot
192             ${CMAKE_COMMAND} -DGRAPHDIR=${DEPGRAPH_DIR}
193             -DDOT_EXECUTABLE=${DOXYGEN_DOT_EXECUTABLE}
194             -P ${CMAKE_CURRENT_SOURCE_DIR}/generateGraphs.cmake)
195         add_custom_target(dep-graphs      COMMAND ${dep_graphs_command_dot}
196             COMMENT "Generating PNG include dependency graphs" VERBATIM)
197         add_custom_target(dep-graphs-fast COMMAND ${dep_graphs_command_dot}
198             COMMENT "Generating PNG include dependency graphs" VERBATIM)
199         add_dependencies(dep-graphs      dep-graphs-dot)
200         add_dependencies(dep-graphs-fast dep-graphs-dot-fast)
201     endif()
202
203     # Create the actual targets to build the documentation.
204     add_doxygen_target(doxygen-full full "Generating full documentation with Doxygen" DEPGRAPHS DEPXML)
205     add_doxygen_target(doxygen-lib  lib  "Generating library documentation with Doxygen" DEPGRAPHS DEPXML)
206     add_doxygen_target(doxygen-user user "Generating public API documentation with Doxygen" DEPXML)
207     add_doxygen_target(doxygen-dev dev "Generating verbose developer docs with Doxygen" DEPGRAPHS DEPXML)
208     # Convenience targets to build all the documentation flavors.
209     add_custom_target(doxygen-all)
210     add_custom_target(doxygen-all-fast)
211     add_dependencies(doxygen-all      doxygen-full doxygen-lib doxygen-user)
212     add_dependencies(doxygen-all-fast doxygen-full-fast doxygen-lib-fast doxygen-user)
213
214     # Finally, create the check-source target.
215     if (USE_PYTHON_SCRIPTS)
216         # TODO: Consider whether this is the best location for this code,
217         # since not all of it is Doxygen-specific (but nearly all of it
218         # relies on the Doxygen XML documentation).
219         # The output .log file currently needs to be here, since Jenkins
220         # expects that.
221         set(check_source_command
222             ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/check-source.py
223             -S ${CMAKE_SOURCE_DIR} -B ${CMAKE_BINARY_DIR}
224             -l ${CMAKE_CURRENT_BINARY_DIR}/check-source.log
225             --ignore ${CMAKE_CURRENT_SOURCE_DIR}/suppressions.txt
226             --ignore-cycles ${CMAKE_CURRENT_SOURCE_DIR}/cycle-suppressions.txt)
227         add_custom_target(check-source      COMMAND ${check_source_command}
228             COMMENT "Checking source code for various issues" VERBATIM USES_TERMINAL)
229         add_custom_target(check-source-fast COMMAND ${check_source_command}
230             COMMENT "Checking source code for various issues" VERBATIM USES_TERMINAL)
231         add_dependencies(check-source       doxygen-xml)
232     endif()
233 else()
234     function (add_disabled_doxygen_target TARGET)
235         add_custom_target(${TARGET}
236             COMMAND ${CMAKE_COMMAND} -E echo
237                 "Cannot build/run target ${TARGET} because Doxygen is not available"
238             COMMENT "Doxygen not available" VERBATIM)
239     endfunction()
240     add_disabled_doxygen_target(doxygen-all)
241     add_disabled_doxygen_target(doxygen-all-fast)
242     add_disabled_doxygen_target(doxygen-xml)
243     add_disabled_doxygen_target(doxygen-user)
244     add_disabled_doxygen_target(doxygen-lib)
245     add_disabled_doxygen_target(doxygen-lib-fast)
246     add_disabled_doxygen_target(doxygen-full)
247     add_disabled_doxygen_target(doxygen-full-fast)
248     add_disabled_doxygen_target(check-source)
249     add_disabled_doxygen_target(check-source-fast)
250     add_disabled_doxygen_target(dep-graphs)
251     add_disabled_doxygen_target(dep-graphs-fast)
252 endif()