Merge release-2018 into release-2019
[alexxy/gromacs.git] / docs / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2014,2015,2016,2017,2018,2019, 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 set(EXPECTED_SPHINX_VERSION 1.6.1)
62
63 if (DEFINED PYTHON_EXECUTABLE)
64     # Keep quiet on subsequent runs of cmake
65     set(PythonInterp_FIND_QUIETLY ON)
66 endif()
67 find_package(PythonInterp 2.7)
68
69
70 if (NOT ${PYTHON_VERSION_MAJOR} EQUAL 3)
71     find_package(Sphinx ${EXPECTED_SPHINX_VERSION} QUIET COMPONENTS pygments)
72 else()
73     MESSAGE(STATUS "Can not build documentation with Python 3")
74 endif()
75
76 # Even if we aren't going to make the full webpage, set up to put all
77 # the documentation output in the same place, for convenience
78 set(HTML_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/html")
79 file(MAKE_DIRECTORY ${HTML_OUTPUT_DIR})
80
81 # Prepare directories for pdf/tex output
82 set(TEX_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/manual")
83 set(SPHINX_LATEX_FILE "${TEX_OUTPUT_DIR}/gromacs.tex")
84 file(MAKE_DIRECTORY ${TEX_OUTPUT_DIR})
85
86 # The directory from which man pages will be installed; if it remains
87 # empty, they will be silently skipped.
88 set(MAN_PAGE_DIR)
89 if (SOURCE_IS_SOURCE_DISTRIBUTION)
90     # When building from the tarball, install the bundled man pages
91     # (unless overridden).
92     set(MAN_PAGE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
93 endif()
94
95 add_subdirectory(doxygen)
96
97 # TODO: Consider whether this could just be replaced by using
98 # GMX_DEVELOPER_BUILD to control this as well.
99 option(GMX_BUILD_MANUAL "Whether to try to configure to build the PDF manual" OFF)
100 mark_as_advanced(GMX_BUILD_MANUAL)
101
102 set(MANUAL_BUILD_IS_POSSIBLE ON)
103 set(MANUAL_BUILD_NOT_POSSIBLE_REASON)
104 set(NO_IMAGE_CONVERT_REASON)
105 if (NOT GMX_BUILD_MANUAL)
106     # Make sure we only do detection of manual-building dependencies
107     # when the user opted in for that.
108     set(MANUAL_BUILD_IS_POSSIBLE OFF)
109     set(MANUAL_BUILD_NOT_POSSIBLE_REASON "GMX_BUILD_MANUAL is not ON")
110 elseif (BUILD_IS_INSOURCE)
111     # UseLATEX.cmake does not work with an in-source build
112     set(MANUAL_BUILD_IS_POSSIBLE OFF)
113     set(MANUAL_BUILD_NOT_POSSIBLE_REASON "the build is in-source")
114 else()
115     include(manual/UseLATEX.cmake)
116     if(${PYTHON_VERSION_MAJOR} EQUAL 3)
117         set(MANUAL_BUILD_IS_POSSIBLE OFF)
118         set(MANUAL_BUILD_NOT_POSSIBLE_REASON "We can not build the documentation when using python3")
119     elseif(NOT SPHINX_FOUND)
120         set(MANUAL_BUILD_IS_POSSIBLE OFF)
121         set(MANUAL_BUILD_NOT_POSSIBLE_REASON "Sphinx has not been found and is needed to create the LaTex input files")
122     elseif(NOT PDFLATEX_COMPILER)
123         set(MANUAL_BUILD_IS_POSSIBLE OFF)
124         set(MANUAL_BUILD_NOT_POSSIBLE_REASON "pdflatex is not available")
125     elseif(NOT IMAGE_CONVERT_POSSIBLE)
126         set(MANUAL_BUILD_IS_POSSIBLE OFF)
127         set(MANUAL_BUILD_NOT_POSSIBLE_REASON "a working form of ImageMagick convert is not available")
128         set(NO_IMAGE_CONVERT_REASON "Can not convert files for online or pdf manual")
129         # TODO Later, identify other dependencies like bibtex,
130         # make_index, date, some graphics conversion program,
131         # etc. Perhaps patch UseLATEX.cmake and contribute upstream.
132     endif()
133
134 endif()
135
136 if (SPHINX_FOUND)
137     # We need to have all the Sphinx input files in a single directory, and
138     # since some of them are generated, we copy everything into the build tree,
139     # to this directory.
140     set(SPHINX_INPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/sphinx-input)
141     set(SPHINX_EXTENSION_PATH ${CMAKE_CURRENT_SOURCE_DIR})
142     # As the manual build now depends also on Sphinx, the inclusion path needs
143     # to be set after we know the basic information for Sphinx.
144     add_subdirectory(manual)
145     if (SOURCE_MD5SUM STREQUAL "unknown")
146         # But for testing the webpage build (e.g. from the repo) we
147         # need a default value.
148         set(REGRESSIONTEST_MD5SUM_STRING "unknown")
149     else()
150         # The real build of the webpage happens from the tarball, and
151         # this should be set to the matching MD5 sum.
152         set(REGRESSIONTEST_MD5SUM_STRING "${REGRESSIONTEST_MD5SUM}")
153     endif()
154     # The reference manual still contains the individual sections from the
155     # LaTeX document, with the files below grouped and annotated by chapter.
156     set(REFERENCEMANUAL_SPHINX_FILES_GENERAL
157         # Main index file, preface and introduction.
158         reference-manual/index.rst
159         reference-manual/preface.rst
160         reference-manual/introduction.rst
161         # Definitions and Units chapter
162         reference-manual/definitions.rst
163         # Topologies chapter
164         reference-manual/topologies.rst
165         reference-manual/topologies/particle-type.rst
166         reference-manual/topologies/parameter-files.rst
167         reference-manual/topologies/molecule-definition.rst
168         reference-manual/topologies/constraint-algorithm-section.rst
169         reference-manual/topologies/pdb2gmx-input-files.rst
170         reference-manual/topologies/topology-file-formats.rst
171         reference-manual/topologies/force-field-organization.rst
172         # File formats chapter
173         reference-manual/file-formats.rst
174         # Run parameters and programs chapter
175         reference-manual/run-parameters.rst
176         # Implementation details chapter
177         reference-manual/details.rst
178         # Averages and fluctations chapter
179         reference-manual/averages.rst
180         # References
181         reference-manual/references.rst
182         # PNG formated plot files that don't need to be converted into PNG
183         # for the web page.
184         reference-manual/plots/peregrine.png
185         reference-manual/plots/adress.png
186         reference-manual/plots/plotje.png
187         reference-manual/plots/xvgr.png
188         )
189     set(REFERENCEMANUAL_SPHINX_FILES_WITH_IMAGES
190         # Algorithms chapter
191         reference-manual/algorithms.rst
192         reference-manual/algorithms/periodic-boundary-conditions.rst
193         reference-manual/algorithms/group-concept.rst
194         reference-manual/algorithms/molecular-dynamics.rst
195         reference-manual/algorithms/shell-molecular-dynamics.rst
196         reference-manual/algorithms/constraint-algorithms.rst
197         reference-manual/algorithms/simulated-annealing.rst
198         reference-manual/algorithms/stochastic-dynamics.rst
199         reference-manual/algorithms/brownian-dynamics.rst
200         reference-manual/algorithms/energy-minimization.rst
201         reference-manual/algorithms/normal-mode-analysis.rst
202         reference-manual/algorithms/free-energy-calculations.rst
203         reference-manual/algorithms/replica-exchange.rst
204         reference-manual/algorithms/essential-dynamics.rst
205         reference-manual/algorithms/expanded-ensemble.rst
206         reference-manual/algorithms/parallelization-domain-decomp.rst
207         # Interaction functions and force fields chapter
208         reference-manual/functions.rst
209         reference-manual/functions/bonded-interactions.rst
210         reference-manual/functions/force-field.rst
211         reference-manual/functions/free-energy-interactions.rst
212         reference-manual/functions/interaction-methods.rst
213         reference-manual/functions/long-range-electrostatics.rst
214         reference-manual/functions/long-range-vdw.rst
215         reference-manual/functions/nonbonded-interactions.rst
216         reference-manual/functions/polarization.rst
217         reference-manual/functions/restraints.rst
218         # Special topics chapter
219         reference-manual/special.rst
220         reference-manual/special/free-energy-implementation.rst
221         reference-manual/special/pulling.rst
222         reference-manual/special/awh.rst
223         reference-manual/special/enforced-rotation.rst
224         reference-manual/special/electric-fields.rst
225         reference-manual/special/comp-electrophys.rst
226         reference-manual/special/free-energy-pmf.rst
227         reference-manual/special/remove-fast-dgf.rst
228         reference-manual/special/viscosity-calculation.rst
229         reference-manual/special/tabulated-interaction-functions.rst
230         reference-manual/special/qmmm.rst
231         reference-manual/special/vmd-imd.rst
232         reference-manual/special/membrane-embedding.rst
233         reference-manual/special/mimic-qmmm.rst
234         # Analysis chapter
235         reference-manual/analysis.rst
236         reference-manual/analysis/using-groups.rst
237         reference-manual/analysis/looking-at-trajectory.rst
238         reference-manual/analysis/general-properties.rst
239         reference-manual/analysis/radial-distribution-function.rst
240         reference-manual/analysis/correlation-function.rst
241         reference-manual/analysis/curve-fitting.rst
242         reference-manual/analysis/mean-square-displacement.rst
243         reference-manual/analysis/bond-angle-dihedral.rst
244         reference-manual/analysis/radius-of-gyration.rst
245         reference-manual/analysis/rmsd.rst
246         reference-manual/analysis/covariance-analysis.rst
247         reference-manual/analysis/dihedral-pca.rst
248         reference-manual/analysis/protein-related.rst
249         reference-manual/analysis/interface-related.rst)
250     # The image files have also been ordered by the respective
251     # chapter they are included in in the reference manual
252     set(REFERENCEMANUAL_IMAGE_FILES
253         # General folder
254         reference-manual/plots/decomp.pdf
255         reference-manual/plots/dih.pdf
256         reference-manual/plots/drift-all.pdf
257         reference-manual/plots/f-angle.pdf
258         reference-manual/plots/f-bond.pdf
259         reference-manual/plots/fp-highres.pdf
260         reference-manual/plots/int-mat.pdf
261         reference-manual/plots/mdpar.pdf
262         reference-manual/plots/parsort.pdf
263         reference-manual/plots/ring.pdf
264         reference-manual/plots/shiftf.pdf
265         # Algorithms chapter
266         reference-manual/algorithms/plots/dd-cells.pdf
267         reference-manual/algorithms/plots/dd-tric.pdf
268         reference-manual/algorithms/plots/flowchart.pdf
269         reference-manual/algorithms/plots/free1.pdf
270         reference-manual/algorithms/plots/free2.pdf
271         reference-manual/algorithms/plots/leapfrog.pdf
272         reference-manual/algorithms/plots/lincs.pdf
273         reference-manual/algorithms/plots/maxwell.pdf
274         reference-manual/algorithms/plots/mpmd-pme.pdf
275         reference-manual/algorithms/plots/nstric.pdf
276         reference-manual/algorithms/plots/par-lincs2.pdf
277         reference-manual/algorithms/plots/pbctric.pdf
278         reference-manual/algorithms/plots/rhododec.pdf
279         reference-manual/algorithms/plots/truncoct.pdf
280         reference-manual/algorithms/plots/verlet-drift.pdf
281         # Interaction functions chapter
282         reference-manual/functions/plots/angle.pdf
283         reference-manual/functions/plots/bstretch.pdf
284         reference-manual/functions/plots/chain.pdf
285         reference-manual/functions/plots/dummies.pdf
286         reference-manual/functions/plots/f-bham.pdf
287         reference-manual/functions/plots/fbposres.pdf
288         reference-manual/functions/plots/f-dih.pdf
289         reference-manual/functions/plots/f-dr.pdf
290         reference-manual/functions/plots/fig-02.pdf
291         reference-manual/functions/plots/fig-04.pdf
292         reference-manual/functions/plots/f-imps.pdf
293         reference-manual/functions/plots/f-lj.pdf
294         reference-manual/functions/plots/f-morse.pdf
295         reference-manual/functions/plots/f-pr.pdf
296         reference-manual/functions/plots/f-rbs.pdf
297         reference-manual/functions/plots/ring-imp.pdf
298         reference-manual/functions/plots/softcore.pdf
299         reference-manual/functions/plots/subst-im.pdf
300         reference-manual/functions/plots/tetra-im.pdf
301         reference-manual/functions/plots/vcrf.pdf
302         reference-manual/functions/plots/vsite-4fdn.pdf
303         # Special topics chapter
304         reference-manual/special/plots/awh-invN.pdf
305         reference-manual/special/plots/awh-pmfs.pdf
306         reference-manual/special/plots/awh-sampleweights.pdf
307         reference-manual/special/plots/awh-traj.pdf
308         reference-manual/special/plots/compelsetup.pdf
309         reference-manual/special/plots/dumaro.pdf
310         reference-manual/special/plots/dumtypes.pdf
311         reference-manual/special/plots/equipotential.pdf
312         reference-manual/special/plots/field.pdf
313         reference-manual/special/plots/gaussians.pdf
314         reference-manual/special/plots/pulldirrel.pdf
315         reference-manual/special/plots/pull.pdf
316         reference-manual/special/plots/pullref.pdf
317         reference-manual/special/plots/rotation.pdf
318         # Analysis chapter
319         reference-manual/analysis/plots/dih-def.pdf
320         reference-manual/analysis/plots/distm.pdf
321         reference-manual/analysis/plots/dssp.pdf
322         reference-manual/analysis/plots/hbond-insert.pdf
323         reference-manual/analysis/plots/hbond.pdf
324         reference-manual/analysis/plots/hpr-wheel.pdf
325         reference-manual/analysis/plots/msdwater.pdf
326         reference-manual/analysis/plots/ngmxdump.pdf
327         reference-manual/analysis/plots/phipsi.pdf
328         reference-manual/analysis/plots/rama.pdf
329         reference-manual/analysis/plots/rdfO-O.pdf
330         reference-manual/analysis/plots/rdf.pdf
331         reference-manual/analysis/plots/sgangle.pdf 
332         )
333     set(SPHINX_SOURCE_FILES
334         index.rst
335         download.rst
336         conf.py
337         links.dat
338         dev-manual/build-system.rst
339         dev-manual/change-management.rst
340         dev-manual/commitstyle.rst
341         dev-manual/documentation-generation.rst
342         dev-manual/contribute.rst
343         dev-manual/doxygen.rst
344         dev-manual/error-handling.rst
345         dev-manual/formatting.rst
346         dev-manual/gmxtree.rst
347         dev-manual/includestyle.rst
348         dev-manual/index.rst
349         dev-manual/jenkins.rst
350         dev-manual/known-issues.rst
351         dev-manual/language-features.rst
352         dev-manual/naming.rst
353         dev-manual/overview.rst
354         dev-manual/physical_validation.rst
355         dev-manual/redmine-states.png
356         dev-manual/relocatable-binaries.rst
357         dev-manual/reportstyle.rst
358         dev-manual/style.rst
359         dev-manual/testutils.rst
360         dev-manual/tools.rst
361         dev-manual/uncrustify.rst
362         fragments/doxygen-links.rst
363         how-to/index.rst
364         how-to/beginners.rst
365         how-to/topology.rst
366         how-to/special.rst
367         how-to/visualize.rst
368         install-guide/index.rst
369         release-notes/index.rst
370         release-notes/2019/2019.1.rst
371         release-notes/2019/major/highlights.rst
372         release-notes/2019/major/features.rst
373         release-notes/2019/major/performance.rst
374         release-notes/2019/major/tools.rst
375         release-notes/2019/major/bugs-fixed.rst
376         release-notes/2019/major/removed-functionality.rst
377         release-notes/2019/major/deprecated-functionality.rst
378         release-notes/2019/major/portability.rst
379         release-notes/2019/major/miscellaneous.rst
380         release-notes/2018/2018.6.rst
381         release-notes/2018/2018.5.rst
382         release-notes/2018/2018.4.rst
383         release-notes/2018/2018.3.rst
384         release-notes/2018/2018.2.rst
385         release-notes/2018/2018.1.rst
386         release-notes/2018/major/highlights.rst
387         release-notes/2018/major/features.rst
388         release-notes/2018/major/performance.rst
389         release-notes/2018/major/tools.rst
390         release-notes/2018/major/bugs-fixed.rst
391         release-notes/2018/major/removed-features.rst
392         release-notes/2018/major/portability.rst
393         release-notes/2018/major/miscellaneous.rst
394         release-notes/2016/2016.5.rst
395         release-notes/2016/2016.4.rst
396         release-notes/2016/2016.3.rst
397         release-notes/2016/2016.2.rst
398         release-notes/2016/2016.1.rst
399         release-notes/2016/major/highlights.rst
400         release-notes/2016/major/new-features.rst
401         release-notes/2016/major/performance.rst
402         release-notes/2016/major/tools.rst
403         release-notes/2016/major/bugs-fixed.rst
404         release-notes/2016/major/removed-features.rst
405         release-notes/2016/major/miscellaneous.rst
406         release-notes/older/index.rst
407         # the entry for user-guide/index.rst should not appear here,
408         # as it will be included conditionally further down depending on
409         # if the documentation will be build with the full reference
410         # manual or without.
411         user-guide/cmdline.rst
412         user-guide/cutoff-schemes.rst
413         user-guide/deprecation-policy.rst
414         user-guide/environment-variables.rst
415         user-guide/faq.rst
416         user-guide/floating-point.rst
417         user-guide/flow.rst
418         user-guide/force-fields.rst
419         user-guide/getting-started.rst
420         user-guide/index.rst
421         user-guide/managing-simulations.rst
422         user-guide/mdp-options.rst
423         user-guide/mdrun-features.rst
424         user-guide/mdrun-performance.rst
425         user-guide/run-time-errors.rst
426         user-guide/security.rst
427         user-guide/system-preparation.rst
428         user-guide/terminology.rst
429         )
430
431     include(SphinxMacros.cmake)
432     gmx_init_sphinx_setup(${SPHINX_INPUT_DIR})
433
434     # set temporary variables for doi inclusion
435     # into the manual, plain string + some wrapping
436     # for release builds, and dummy string for non-release
437     # builds
438     if("${GMX_MANUAL_DOI}" STREQUAL "")
439       # empty string means no doi, set dummy text
440       set(GMX_MANUAL_DOI_STRING "This is not a release build of GROMACS, so please reference")
441       set(GMX_MANUAL_DOI_STRING "${GMX_MANUAL_DOI_STRING} one of the GROMACS papers and the base release of the manual.")
442     else()
443       # release version, set plain old boring string
444       set(GMX_MANUAL_DOI_STRING "Please reference this documentation as https://doi.org/${GMX_MANUAL_DOI}.")
445     endif()
446     # same for source doi, but modify the text
447     if("${GMX_SOURCE_DOI}" STREQUAL "")
448       # empty string means no release build
449       set(GMX_SOURCE_DOI_STRING "This is not a release build of GROMACS. Please reference one of the")
450       set(GMX_SOURCE_DOI_STRING "${GMX_SOURCE_DOI_STRING} GROMACS papers, as well as the base release that this version is built from.")
451       set(GMX_SOURCE_DOI_STRING "${GMX_SOURCE_DOI_STRING} Also, please state what modifcations have been performed or where the version")
452       set(GMX_SOURCE_DOI_STRING "${GMX_SOURCE_DOI_STRING} was sourced from.")
453     else()
454       # release version, give them a doi url string
455       set(GMX_SOURCE_DOI_STRING "To cite the source code for this release, please cite")
456       set(GMX_SOURCE_DOI_STRING "${GMX_SOURCE_DOI_STRING} https://doi.org/${GMX_SOURCE_DOI}.")
457     endif()
458
459     if(IMAGE_CONVERT_POSSIBLE)
460         set(IMAGE_CONVERT_STRING "possible")
461     else()
462         set(IMAGE_CONVERT_STRING "impossible")
463     endif()
464
465     set(SPHINX_CONFIG_VARS_FILE ${SPHINX_INPUT_DIR}/conf-vars.py)
466     gmx_configure_version_file(conf-vars.py.cmakein ${SPHINX_CONFIG_VARS_FILE}
467         EXTRA_VARS
468             SPHINX_EXTENSION_PATH RELENG_PATH
469             IMAGE_CONVERT_STRING
470             EXPECTED_DOXYGEN_VERSION
471             EXPECTED_SPHINX_VERSION
472             CMAKE_MINIMUM_REQUIRED_VERSION REQUIRED_CUDA_VERSION
473             REQUIRED_OPENCL_MIN_VERSION
474             REQUIRED_CUDA_COMPUTE_CAPABILITY REGRESSIONTEST_VERSION
475             SOURCE_MD5SUM REGRESSIONTEST_MD5SUM_STRING
476             GMX_TNG_MINIMUM_REQUIRED_VERSION
477             GMX_LMFIT_REQUIRED_VERSION
478             GMX_MANUAL_DOI_STRING
479             GMX_SOURCE_DOI_STRING
480         COMMENT "Configuring Sphinx configuration file")
481     gmx_add_sphinx_input_file(${SPHINX_CONFIG_VARS_FILE})
482     gmx_add_sphinx_source_files(FILES ${SPHINX_SOURCE_FILES})
483     if (EXISTS ${RELENG_PATH}/docs/FileList.cmake)
484         include(${RELENG_PATH}/docs/FileList.cmake)
485         gmx_add_sphinx_source_files(
486             FROM ${RELENG_PATH}/docs TO dev-manual/releng PREFIX releng/docs/
487             FILES ${RELENG_SPHINX_FILES})
488     else()
489         gmx_add_sphinx_source_files(FILES
490             dev-manual/releng/index.rst
491             dev-manual/releng/jenkins-howto.rst
492             dev-manual/releng/jenkins-ui.rst
493             )
494     endif()
495     gmx_add_sphinx_source_files(
496         FILES
497         ${REFERENCEMANUAL_SPHINX_FILES_GENERAL})
498     if (IMAGE_CONVERT_POSSIBLE)
499         gmx_add_sphinx_source_files(
500             FILES
501             ${REFERENCEMANUAL_SPHINX_FILES_WITH_IMAGES}
502             ${REFERENCEMANUAL_IMAGE_FILES})
503         gmx_add_sphinx_image_conversion_files(
504             FILES
505             ${REFERENCEMANUAL_IMAGE_FILES})
506     endif()
507     gmx_add_sphinx_input_target(sphinx-input-rst)
508     gmx_add_sphinx_image_conversion_target(sphinx-image-conversion)
509     add_custom_target(sphinx-input)
510     add_dependencies(sphinx-input sphinx-input-rst sphinx-image-conversion)
511     # Remove other rst files from the build tree, since they confuse Sphinx.
512     # Skip generated files in onlinehelp/, and fragments.
513     # The latter do not cause issues with obsolete files, as they
514     # are not considered as Sphinx input files, but will only be
515     # included using an explicit .. include::.
516     gmx_remove_obsolete_sphinx_input_files("^(onlinehelp|fragments)/.*\\\\.rst$")
517
518     # TODO: Make this remove obsolete .rst files.
519     # TODO: This does not work in cross-compilation scenarios; disable up to
520     # the necessary level.
521     gmx_add_custom_output_target(sphinx-programs OUTPUT STAMP
522         COMMAND ${CMAKE_COMMAND} -E make_directory onlinehelp
523         COMMAND gmx -quiet help -export rst
524         DEPENDS gmx
525         WORKING_DIRECTORY ${SPHINX_INPUT_DIR}
526         COMMENT "Generating reStructuredText help")
527     # This dependency ensures that the directories exist before the
528     # executable tries to write things there.
529     add_dependencies(sphinx-programs sphinx-input)
530
531     # Make the INSTALL file for CPack for the tarball. This gets put
532     # into the tarball via the CPack rules below, which requires that
533     # the INSTALL file is in a separate directory by itself.
534     set(TEXT_INSTALL_GUIDE_OUTPUT_DIR "install-guide/text")
535     add_custom_target(install-guide
536         COMMAND
537             ${SPHINX_EXECUTABLE}
538             -q -E -b text
539             -w sphinx-install.log
540             -d ${CMAKE_CURRENT_BINARY_DIR}/install-guide/_doctrees
541             -c ${SPHINX_INPUT_DIR}
542             "${SPHINX_INPUT_DIR}/install-guide"
543             "${TEXT_INSTALL_GUIDE_OUTPUT_DIR}"
544         COMMAND
545             ${CMAKE_COMMAND} -E rename
546             ${TEXT_INSTALL_GUIDE_OUTPUT_DIR}/index.txt
547             ${TEXT_INSTALL_GUIDE_OUTPUT_DIR}/INSTALL
548         WORKING_DIRECTORY
549             ${CMAKE_CURRENT_BINARY_DIR}
550         COMMENT "Building INSTALL with Sphinx"
551         VERBATIM
552         )
553     add_dependencies(install-guide sphinx-input)
554     gmx_cpack_add_generated_source_directory(install-guide/text DESTINATION /)
555
556     # Sphinx cache with pickled ReST documents
557     set(SPHINX_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees")
558     add_custom_target(webpage-sphinx
559         DEPENDS sphinx-programs
560         DEPENDS sphinx-input
561         DEPENDS sphinx-image-conversion 
562         COMMAND
563             ${CMAKE_COMMAND} -E make_directory ${SPHINX_INPUT_DIR}/_static
564         COMMAND
565             ${SPHINX_EXECUTABLE}
566             -q -E -b html
567             -w sphinx-html.log
568             -d "${SPHINX_CACHE_DIR}"
569             "${SPHINX_INPUT_DIR}"
570             "${HTML_OUTPUT_DIR}"
571         WORKING_DIRECTORY
572             ${CMAKE_CURRENT_BINARY_DIR}
573         COMMENT "Building HTML documentation with Sphinx"
574         VERBATIM
575         )
576
577     add_custom_target(man
578         COMMAND
579             ${SPHINX_EXECUTABLE}
580             -q -E -b man
581             -w sphinx-man.log
582             -d ${SPHINX_CACHE_DIR}
583             -t do_man
584             ${SPHINX_INPUT_DIR}
585             ${CMAKE_CURRENT_BINARY_DIR}/man
586         COMMENT "Building man pages with Sphinx"
587         VERBATIM)
588     add_dependencies(man sphinx-input sphinx-programs)
589     if (GMX_BUILD_HELP)
590         # If requested, install the man pages built by the 'man' target
591         # created above.  Nothing will be installed if the user did not
592         # manually build the target.
593         set(MAN_PAGE_DIR ${CMAKE_CURRENT_BINARY_DIR})
594     endif()
595
596 else()
597     set(MANUAL_BUILD_IS_POSSIBLE OFF)
598     set(MANUAL_BUILD_NOT_POSSIBLE_REASON "Sphinx version ${EXPECTED_SPHINX_VERSION} is not available")
599
600     add_custom_target(webpage-sphinx
601         COMMAND ${CMAKE_COMMAND} -E echo
602             "HTML pages cannot be built because Sphinx version ${EXPECTED_SPHINX_VERSION} is not available"
603         VERBATIM)
604     add_custom_target(install-guide
605         COMMAND ${CMAKE_COMMAND} -E echo
606             "INSTALL cannot be built because Sphinx version ${EXPECTED_SPHINX_VERSION} is not available"
607         VERBATIM)
608     add_custom_target(man
609         COMMAND ${CMAKE_COMMAND} -E echo
610             "man pages cannot be built because Sphinx version ${EXPECTED_SPHINX_VERSION} is not available"
611         VERBATIM)
612     add_custom_target(sphinx-create-texman
613         COMMAND ${CMAKE_COMMAND} -E echo
614             "Cannot prepare LaTeX input files because Sphinx version ${EXPECTED_SPHINX_VERSION} is not available"
615         VERBATIM)
616 endif()
617
618 if (MAN_PAGE_DIR)
619     set(MAN_PAGE_DIR ${MAN_PAGE_DIR}/man)
620     # Trailing slash on directory is significant for
621     # install(DIRECTORY). See CMake docs.
622     install(DIRECTORY ${MAN_PAGE_DIR}/
623         DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
624         COMPONENT man OPTIONAL
625         FILES_MATCHING PATTERN "*.1")
626 endif()
627 gmx_cpack_add_generated_source_directory(man)
628
629 # Determine whether we can build all the HTML pages and content linked from
630 # there.  If not, construct an informative message if the user tries to
631 # build the target; most people never need to know, unless they've asked for
632 # the webpage build.
633 set(HTML_BUILD_IS_POSSIBLE ON)
634 set(HTML_BUILD_NOT_POSSIBLE_REASON)
635 set(HTML_BUILD_WARNINGS)
636
637 # Next, turn it off if any of the preconditions are unsatisified
638 if (NOT PYTHON_EXECUTABLE)
639     set(HTML_BUILD_IS_POSSIBLE OFF)
640     set(HTML_BUILD_NOT_POSSIBLE_REASON "Python is required")
641 elseif (NOT SPHINX_FOUND)
642     # Hardly anything gets built if Sphinx is not available, so don't bother.
643     set(HTML_BUILD_IS_POSSIBLE OFF)
644     set(HTML_BUILD_NOT_POSSIBLE_REASON "Sphinx version ${EXPECTED_SPHINX_VERSION} is required")
645 endif()
646 if (NOT MANUAL_BUILD_IS_POSSIBLE)
647     list(APPEND HTML_BUILD_WARNINGS
648          "Reference PDF manual was not built, so links to it do not work")
649 endif()
650 if (NOT DOXYGEN_EXECUTABLE)
651     list(APPEND HTML_BUILD_WARNINGS
652         "Doxygen was not available, so links to Doxygen do not work")
653 endif()
654 if (NOT DOXYGEN_DOT_EXECUTABLE)
655     list(APPEND HTML_BUILD_WARNINGS
656         "dot/graphviz was not found, so some graphs are missing")
657 endif()
658
659 if (HTML_BUILD_IS_POSSIBLE)
660     set(_webpage_target_properties)
661     if (HTML_BUILD_WARNINGS)
662         list(APPEND _webpage_target_properties
663              COMMAND ${CMAKE_COMMAND} -E echo
664                  "webpage was built, but with the following limitations:")
665         foreach(_warning ${HTML_BUILD_WARNINGS})
666         list(APPEND _webpage_target_properties
667              COMMAND ${CMAKE_COMMAND} -E echo " - ${_warning}")
668         endforeach()
669     endif()
670
671     if (MANUAL_BUILD_IS_POSSIBLE)
672         # Make the PDF reference guide
673         # TODO Try to make the PDF arrive directly in ${HTML_OUTPUT_DIR}
674         # TODO Make this depend on the output of the manual build, so that the
675         # file actually gets copied multiple times.
676         set(_manual_target_location ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf)
677         add_custom_command(
678             OUTPUT ${_manual_target_location}
679             COMMAND ${CMAKE_COMMAND}
680                 -E remove -f ${_manual_target_location}
681             COMMAND ${CMAKE_COMMAND}
682                 -E copy ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf ${_manual_target_location}
683             DEPENDS manual
684             VERBATIM)
685         list(APPEND _webpage_target_properties
686              DEPENDS ${_manual_target_location})
687     endif()
688
689     # The Doxygen configuration in doxygen/Doxyfile-common.cmakein
690     # makes all the Doxygen output directly in
691     # ${HTML_OUTPUT_DIR}/doxygen (and makes the directory if it needs
692     # to).
693
694     # Add a top-level target that builds everything related to the webpage,
695     # for Jenkins (and possibly others) to use
696     add_custom_target(webpage ${_webpage_target_properties}
697         COMMENT "Building webpage"
698         VERBATIM)
699     add_dependencies(webpage webpage-sphinx doxygen-all)
700 else()
701     add_custom_target(webpage
702         COMMAND ${CMAKE_COMMAND} -E echo
703             "Cannot build webpage because ${HTML_BUILD_NOT_POSSIBLE_REASON}"
704         COMMENT "Webpage build not possible"
705         VERBATIM)
706 endif()