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