9f08d24e69dc224d2c71e86e2231d59d76493a8b
[alexxy/gromacs.git] / docs / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2014,2015, 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 # This directory provides a unified place for building all kinds of
36 # GROMACS documentation. This includes some "static" content (Doxygen
37 # code documentation, reference manual, install guide, old online HTML
38 # images), and content generated from the gmx program for the various
39 # tools (man and HTML pages). It also provides the "webpage" target,
40 # that combines all of the above (except man pages in man format) into
41 # a form suitable for automated deployment to the GROMACS website. It
42 # also provides the INSTALL file for the tarball.
43 #
44 # The webpage is mostly built by Sphinx.  Variable values for Sphinx
45 # substitutions are configured by CMake (for things like version numbers),
46 # using gmx_configure_version_file().  This happens during build time instead
47 # of configure time, because 1) some of the version variables are only
48 # available during build time, and 2) we don't want to do all the Sphinx setup
49 # during configuration to save some time when not building the content.
50 # All the generated values get put into conf-vars.py (generated from
51 # conf-vars.py.cmakein), which in turn is included by the Sphinx configuration
52 # file conf.py.
53
54 set(SOURCE_MD5SUM "unknown" CACHE STRING
55     "MD5 sum of the source tarball, normally used only for the pre-release webpage build")
56 # REGRESSIONTEST_MD5SUM is set in cmake/gmxVersionInfo.cmake because it is used also in tests/CMakeLists.txt
57 mark_as_advanced(SOURCE_MD5SUM)
58
59 set(EXPECTED_DOXYGEN_VERSION 1.8.5)
60
61 find_package(PythonInterp)
62 find_package(Sphinx 1.2.3 COMPONENTS pygments)
63
64 # Even if we aren't going to make the full webpage, set up to put all
65 # the documentation output in the same place, for convenience
66 set(HTML_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/html")
67 file(MAKE_DIRECTORY ${HTML_OUTPUT_DIR})
68
69 # The directory from which man pages will be installed; if it remains
70 # empty, they will be silently skipped.
71 set(MAN_PAGE_DIR)
72 if (SOURCE_IS_SOURCE_DISTRIBUTION)
73     # When building from the tarball, install the bundled man pages
74     # (unless overridden).
75     set(MAN_PAGE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
76 endif()
77
78 add_subdirectory(doxygen)
79 add_subdirectory(manual)
80
81 if (SPHINX_FOUND)
82     # We need to have all the Sphinx input files in a single directory, and
83     # since some of them are generated, we copy everything into the build tree,
84     # to this directory.
85     set(SPHINX_INPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/sphinx-input)
86     set(SPHINX_CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/conf.py)
87     set(SPHINX_CONFIG_VARS_FILE ${SPHINX_INPUT_DIR}/conf-vars.py)
88     set(SPHINX_EXTENSION_PATH ${CMAKE_CURRENT_SOURCE_DIR})
89     if (SOURCE_IS_SOURCE_DISTRIBUTION OR GMX_BUILD_TARBALL)
90         # The real build of the webpage happens from the tarball, and
91         # this should be set to the matching MD5 sum.
92         set(REGRESSIONTEST_MD5SUM_STRING "${REGRESSIONTEST_MD5SUM}")
93     else()
94         # But for testing the webpage build (e.g. from the repo) we
95         # need a default value.
96         set(REGRESSIONTEST_MD5SUM_STRING "unknown")
97     endif()
98     set(SPHINX_SOURCE_FILES
99         index.rst
100         download.rst
101         dev-manual/index.rst
102         dev-manual/build-system.rst
103         dev-manual/doxygen.rst
104         dev-manual/formatting.rst
105         dev-manual/gmxtree.rst
106         dev-manual/includestyle.rst
107         dev-manual/naming.rst
108         dev-manual/overview.rst
109         dev-manual/relocatable-binaries.rst
110         dev-manual/style.rst
111         dev-manual/testutils.rst
112         dev-manual/tools.rst
113         dev-manual/uncrustify.rst
114         fragments/doxygen-links.rst
115         install-guide/index.rst
116         user-guide/index.rst
117         user-guide/getting-started.rst
118         user-guide/flow.rst
119         user-guide/cutoff-schemes.rst
120         user-guide/mdrun-features.rst
121         user-guide/mdrun-performance.rst
122         user-guide/mdp-options.rst
123         user-guide/file-formats.rst
124         user-guide/tools.rst
125         user-guide/environment-variables.rst
126         user-guide/plotje.gif
127         user-guide/xvgr.gif
128         conf.py
129         links.dat
130         )
131
132     # Remove other rst files from the build tree, since they confuse Sphinx.
133     file(GLOB_RECURSE _obsolete_sources RELATIVE ${SPHINX_INPUT_DIR}
134          ${SPHINX_INPUT_DIR}/*.rst)
135     list(REMOVE_ITEM _obsolete_sources ${SPHINX_SOURCE_FILES})
136     foreach(_file ${_obsolete_sources})
137         # Skip generated files in onlinehelp/, and fragments.
138         # The latter do not cause issues with obsolete files, as they
139         # are not considered as Sphinx input files, but will only be
140         # included using an explicit .. include::.
141         if (NOT _file MATCHES "^(onlinehelp|fragments)/.*\\.rst$")
142             message(STATUS "Removing obsolete Sphinx input ${_file}")
143             file(REMOVE ${SPHINX_INPUT_DIR}/${_file})
144         endif()
145     endforeach()
146
147     gmx_configure_version_file(conf-vars.py.cmakein ${SPHINX_CONFIG_VARS_FILE}
148         EXTRA_VARS
149             SPHINX_EXTENSION_PATH
150             EXPECTED_DOXYGEN_VERSION
151             GMX_CMAKE_MINIMUM_REQUIRED_VERSION REQUIRED_CUDA_VERSION
152             REQUIRED_CUDA_COMPUTE_CAPABILITY REGRESSIONTEST_VERSION
153             SOURCE_MD5SUM REGRESSIONTEST_MD5SUM_STRING
154         COMMENT "Configuring Sphinx configuration file")
155     set(SPHINX_INPUT_FILES ${SPHINX_CONFIG_VARS_FILE})
156     foreach(_file ${SPHINX_SOURCE_FILES})
157         add_custom_command(
158             OUTPUT ${SPHINX_INPUT_DIR}/${_file}
159             COMMAND ${CMAKE_COMMAND} -E copy
160                 ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
161                 ${SPHINX_INPUT_DIR}/${_file}
162             DEPENDS
163                 ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
164             COMMENT "Copying Sphinx input file ${_file}"
165             VERBATIM)
166         list(APPEND SPHINX_INPUT_FILES ${SPHINX_INPUT_DIR}/${_file})
167     endforeach()
168     gmx_add_custom_output_target(sphinx-input OUTPUT STAMP
169         DEPENDS ${SPHINX_INPUT_FILES})
170     # TODO: Make this remove obsolete .rst files.
171     # TODO: This does not work in cross-compilation scenarios; disable up to
172     # the necessary level.
173     gmx_add_custom_output_target(sphinx-programs OUTPUT STAMP
174         COMMAND ${CMAKE_COMMAND} -E make_directory onlinehelp
175         COMMAND gmx -quiet help -export rst
176         DEPENDS gmx
177         WORKING_DIRECTORY ${SPHINX_INPUT_DIR}
178         COMMENT "Generating reStructuredText help")
179     # This dependency ensures that the directories exist before the
180     # executable tries to write things there.
181     add_dependencies(sphinx-programs sphinx-input)
182
183     # Make the INSTALL file for CPack for the tarball. This gets put
184     # into the tarball via the CPack rules below, which requires that
185     # the INSTALL file is in a separate directory by itself.
186     set(TEXT_INSTALL_GUIDE_OUTPUT_DIR "install-guide/text")
187     add_custom_target(install-guide
188         COMMAND
189             ${SPHINX_EXECUTABLE}
190             -q -b text
191             -w sphinx-install.log
192             -d ${CMAKE_CURRENT_BINARY_DIR}/install-guide/_doctrees
193             -c ${SPHINX_INPUT_DIR}
194             "${SPHINX_INPUT_DIR}/install-guide"
195             "${TEXT_INSTALL_GUIDE_OUTPUT_DIR}"
196         COMMAND
197             ${CMAKE_COMMAND} -E rename
198             ${TEXT_INSTALL_GUIDE_OUTPUT_DIR}/index.txt
199             ${TEXT_INSTALL_GUIDE_OUTPUT_DIR}/INSTALL
200         WORKING_DIRECTORY
201             ${CMAKE_CURRENT_BINARY_DIR}
202         COMMENT "Building INSTALL with Sphinx"
203         VERBATIM
204         )
205     add_dependencies(install-guide sphinx-input)
206     gmx_cpack_add_generated_source_directory(install-guide/text DESTINATION /)
207
208     # Sphinx cache with pickled ReST documents
209     set(SPHINX_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees")
210
211     add_custom_target(webpage-sphinx
212         COMMAND
213             ${CMAKE_COMMAND} -E make_directory ${SPHINX_INPUT_DIR}/_static
214         COMMAND
215             ${SPHINX_EXECUTABLE}
216             -q -b html
217             -w sphinx-html.log
218             -d "${SPHINX_CACHE_DIR}"
219             "${SPHINX_INPUT_DIR}"
220             "${HTML_OUTPUT_DIR}"
221         WORKING_DIRECTORY
222             ${CMAKE_CURRENT_BINARY_DIR}
223         COMMENT "Building HTML documentation with Sphinx"
224         VERBATIM
225         )
226     add_dependencies(webpage-sphinx sphinx-input sphinx-programs)
227
228     add_custom_target(man
229         COMMAND
230             ${SPHINX_EXECUTABLE}
231             -q -b man
232             -w sphinx-man.log
233             -d ${SPHINX_CACHE_DIR}
234             -t do_man
235             ${SPHINX_INPUT_DIR}
236             ${CMAKE_CURRENT_BINARY_DIR}/man
237         COMMENT "Building man pages with Sphinx"
238         VERBATIM)
239     add_dependencies(man sphinx-input sphinx-programs)
240     if (GMX_BUILD_HELP)
241         # If requested, install the man pages built by the 'man' target
242         # created above.  Nothing will be installed if the user did not
243         # manually build the target.
244         set(MAN_PAGE_DIR ${CMAKE_CURRENT_BINARY_DIR})
245     endif()
246 else()
247     add_custom_target(webpage-sphinx
248         COMMAND ${CMAKE_COMMAND} -E echo
249             "HTML pages cannot be built because Sphinx is not available"
250         VERBATIM)
251     add_custom_target(man
252         COMMAND ${CMAKE_COMMAND} -E echo
253             "man pages cannot be built because Sphinx is not available"
254         VERBATIM)
255 endif()
256
257 if (MAN_PAGE_DIR)
258     set(MAN_PAGE_DIR ${MAN_PAGE_DIR}/man)
259     # Trailing slash on directory is significant for
260     # install(DIRECTORY). See CMake docs.
261     install(DIRECTORY ${MAN_PAGE_DIR}/
262         DESTINATION ${MAN_INSTALL_DIR}/man1
263         COMPONENT man OPTIONAL
264         FILES_MATCHING PATTERN "*.1")
265     install(DIRECTORY ${MAN_PAGE_DIR}/
266         DESTINATION ${MAN_INSTALL_DIR}/man7
267         COMPONENT man OPTIONAL
268         FILES_MATCHING PATTERN "*.7")
269 endif()
270 gmx_cpack_add_generated_source_directory(man)
271
272 # Determine whether we can build all the HTML pages and content linked from
273 # there.  If not, construct an informative message if the user tries to
274 # build the target; most people never need to know, unless they've asked for
275 # the webpage build.
276 set(HTML_BUILD_IS_POSSIBLE ON)
277 set(HTML_BUILD_NOT_POSSIBLE_REASON)
278 set(HTML_BUILD_WARNINGS)
279
280 # Next, turn it off if any of the preconditions are unsatisified
281 if (NOT PYTHON_EXECUTABLE)
282     set(HTML_BUILD_IS_POSSIBLE OFF)
283     set(HTML_BUILD_NOT_POSSIBLE_REASON "Python is required")
284 elseif (NOT SPHINX_FOUND)
285     # Hardly anything gets built if Sphinx is not available, so don't bother.
286     set(HTML_BUILD_IS_POSSIBLE OFF)
287     set(HTML_BUILD_NOT_POSSIBLE_REASON "Sphinx is required")
288 endif()
289 if (NOT MANUAL_BUILD_IS_POSSIBLE)
290     list(APPEND HTML_BUILD_WARNINGS
291          "Reference PDF manual was not built, so links to it do not work")
292 endif()
293 if (NOT DOXYGEN_EXECUTABLE)
294     list(APPEND HTML_BUILD_WARNINGS
295         "Doxygen was not available, so links to Doxygen do not work")
296 endif()
297 if (NOT DOXYGEN_DOT_EXECUTABLE)
298     list(APPEND HTML_BUILD_WARNINGS
299         "dot/graphviz was not found, so some graphs are missing")
300 endif()
301
302 if (HTML_BUILD_IS_POSSIBLE)
303     set(_webpage_target_properties)
304     if (HTML_BUILD_WARNINGS)
305         list(APPEND _webpage_target_properties
306              COMMAND ${CMAKE_COMMAND} -E echo
307                  "webpage was built, but with the following limitations:")
308         foreach(_warning ${HTML_BUILD_WARNINGS})
309         list(APPEND _webpage_target_properties
310              COMMAND ${CMAKE_COMMAND} -E echo " - ${_warning}")
311         endforeach()
312     endif()
313
314     if (MANUAL_BUILD_IS_POSSIBLE)
315         # Make the PDF reference guide
316         # TODO Try to make the PDF arrive directly in ${HTML_OUTPUT_DIR}
317         # TODO Make this depend on the output of the manual build, so that the
318         # file actually gets copied multiple times.
319         set(_manual_target_location ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf)
320         add_custom_command(
321             OUTPUT ${_manual_target_location}
322             COMMAND ${CMAKE_COMMAND}
323                 -E remove -f ${_manual_target_location}
324             COMMAND ${CMAKE_COMMAND}
325                 -E copy ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf ${_manual_target_location}
326             DEPENDS manual
327             VERBATIM)
328         list(APPEND _webpage_target_properties
329              DEPENDS ${_manual_target_location})
330     endif()
331
332     # The Doxygen configuration in doxygen/Doxyfile-common.cmakein
333     # makes all the Doxygen output directly in
334     # ${HTML_OUTPUT_DIR}/doxygen (and makes the directory if it needs
335     # to).
336
337     # Add a top-level target that builds everything related to the webpage,
338     # for Jenkins (and possibly others) to use
339     add_custom_target(webpage ${_webpage_target_properties}
340         COMMENT "Building webpage"
341         VERBATIM)
342     add_dependencies(webpage webpage-sphinx doxygen-all)
343 else()
344     add_custom_target(webpage
345         COMMAND ${CMAKE_COMMAND} -E echo
346             "Cannot build webpage because ${HTML_BUILD_NOT_POSSIBLE_REASON}"
347         COMMENT "Webpage build not possible"
348         VERBATIM)
349 endif()