First general additions to the documentation
[gromacs.git] / docs / CMakeLists.txt
bloba549c4793e3243dc06d79168187af43c8e0cab20
2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2014,2015,2016,2017, 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.
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.
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.
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.
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.
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.
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.
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.
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)
59 set(EXPECTED_DOXYGEN_VERSION 1.8.5)
61 set(EXPECTED_SPHINX_VERSION 1.4.1)
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 find_package(Sphinx ${EXPECTED_SPHINX_VERSION} QUIET COMPONENTS pygments)
70 # Even if we aren't going to make the full webpage, set up to put all
71 # the documentation output in the same place, for convenience
72 set(HTML_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/html")
73 file(MAKE_DIRECTORY ${HTML_OUTPUT_DIR})
75 # The directory from which man pages will be installed; if it remains
76 # empty, they will be silently skipped.
77 set(MAN_PAGE_DIR)
78 if (SOURCE_IS_SOURCE_DISTRIBUTION)
79     # When building from the tarball, install the bundled man pages
80     # (unless overridden).
81     set(MAN_PAGE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
82 endif()
84 add_subdirectory(doxygen)
85 add_subdirectory(manual)
87 if (SPHINX_FOUND)
88     # We need to have all the Sphinx input files in a single directory, and
89     # since some of them are generated, we copy everything into the build tree,
90     # to this directory.
91     set(SPHINX_INPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/sphinx-input)
92     set(SPHINX_EXTENSION_PATH ${CMAKE_CURRENT_SOURCE_DIR})
93     if (SOURCE_MD5SUM STREQUAL "unknown")
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     else()
98         # The real build of the webpage happens from the tarball, and
99         # this should be set to the matching MD5 sum.
100         set(REGRESSIONTEST_MD5SUM_STRING "${REGRESSIONTEST_MD5SUM}")
101     endif()
102     set(SPHINX_SOURCE_FILES
103         index.rst
104         download.rst
105         dev-manual/index.rst
106         dev-manual/build-system.rst
107         dev-manual/commitstyle.rst
108         dev-manual/documentation-generation.rst
109         dev-manual/doxygen.rst
110         dev-manual/formatting.rst
111         dev-manual/gmxtree.rst
112         dev-manual/includestyle.rst
113         dev-manual/jenkins.rst
114         dev-manual/language-features.rst
115         dev-manual/naming.rst
116         dev-manual/overview.rst
117         dev-manual/redmine-states.png
118         dev-manual/relocatable-binaries.rst
119         dev-manual/reportstyle.rst
120         dev-manual/style.rst
121         dev-manual/testutils.rst
122         dev-manual/tools.rst
123         dev-manual/uncrustify.rst
124         fragments/doxygen-links.rst
125         install-guide/index.rst
126         user-guide/index.rst
127         user-guide/cutoff-schemes.rst
128         user-guide/getting-started.rst
129         user-guide/force-fields.rst
130         user-guide/faq.rst
131         user-guide/flow.rst
132         user-guide/floating-point.rst
133         user-guide/how-to.rst
134         user-guide/system-preparation.rst
135         user-guide/managing-simulations.rst
136         user-guide/mdrun-features.rst
137         user-guide/mdrun-performance.rst
138         user-guide/mdp-options.rst
139         user-guide/run-time-errors.rst
140         user-guide/file-formats.rst
141         user-guide/cmdline.rst
142         user-guide/environment-variables.rst
143         user-guide/terminology.rst
144         user-guide/plotje.gif
145         user-guide/xvgr.gif
146         conf.py
147         links.dat
148         )
150     include(SphinxMacros.cmake)
151     gmx_init_sphinx_setup(${SPHINX_INPUT_DIR})
153     set(SPHINX_CONFIG_VARS_FILE ${SPHINX_INPUT_DIR}/conf-vars.py)
154     gmx_configure_version_file(conf-vars.py.cmakein ${SPHINX_CONFIG_VARS_FILE}
155         EXTRA_VARS
156             SPHINX_EXTENSION_PATH RELENG_PATH
157             EXPECTED_DOXYGEN_VERSION
158             EXPECTED_SPHINX_VERSION
159             CMAKE_MINIMUM_REQUIRED_VERSION REQUIRED_CUDA_VERSION
160             REQUIRED_OPENCL_MIN_VERSION
161             REQUIRED_CUDA_COMPUTE_CAPABILITY REGRESSIONTEST_VERSION
162             SOURCE_MD5SUM REGRESSIONTEST_MD5SUM_STRING
163             GMX_TNG_MINIMUM_REQUIRED_VERSION
164             GMX_LMFIT_MINIMUM_REQUIRED_VERSION
165         COMMENT "Configuring Sphinx configuration file")
166     gmx_add_sphinx_input_file(${SPHINX_CONFIG_VARS_FILE})
167     gmx_add_sphinx_source_files(FILES ${SPHINX_SOURCE_FILES})
168     if (EXISTS ${RELENG_PATH}/docs/FileList.cmake)
169         include(${RELENG_PATH}/docs/FileList.cmake)
170         gmx_add_sphinx_source_files(
171             FROM ${RELENG_PATH}/docs TO dev-manual/releng PREFIX releng/docs/
172             FILES ${RELENG_SPHINX_FILES})
173     else()
174         gmx_add_sphinx_source_files(FILES
175             dev-manual/releng/index.rst
176             dev-manual/releng/jenkins-howto.rst
177             dev-manual/releng/jenkins-ui.rst
178             )
179     endif()
180     gmx_add_sphinx_input_target(sphinx-input)
181     # Remove other rst files from the build tree, since they confuse Sphinx.
182     # Skip generated files in onlinehelp/, and fragments.
183     # The latter do not cause issues with obsolete files, as they
184     # are not considered as Sphinx input files, but will only be
185     # included using an explicit .. include::.
186     gmx_remove_obsolete_sphinx_input_files("^(onlinehelp|fragments)/.*\\\\.rst$")
188     # TODO: Make this remove obsolete .rst files.
189     # TODO: This does not work in cross-compilation scenarios; disable up to
190     # the necessary level.
191     gmx_add_custom_output_target(sphinx-programs OUTPUT STAMP
192         COMMAND ${CMAKE_COMMAND} -E make_directory onlinehelp
193         COMMAND gmx -quiet help -export rst
194         DEPENDS gmx
195         WORKING_DIRECTORY ${SPHINX_INPUT_DIR}
196         COMMENT "Generating reStructuredText help")
197     # This dependency ensures that the directories exist before the
198     # executable tries to write things there.
199     add_dependencies(sphinx-programs sphinx-input)
201     # Make the INSTALL file for CPack for the tarball. This gets put
202     # into the tarball via the CPack rules below, which requires that
203     # the INSTALL file is in a separate directory by itself.
204     set(TEXT_INSTALL_GUIDE_OUTPUT_DIR "install-guide/text")
205     add_custom_target(install-guide
206         COMMAND
207             ${SPHINX_EXECUTABLE}
208             -q -b text
209             -w sphinx-install.log
210             -d ${CMAKE_CURRENT_BINARY_DIR}/install-guide/_doctrees
211             -c ${SPHINX_INPUT_DIR}
212             "${SPHINX_INPUT_DIR}/install-guide"
213             "${TEXT_INSTALL_GUIDE_OUTPUT_DIR}"
214         COMMAND
215             ${CMAKE_COMMAND} -E rename
216             ${TEXT_INSTALL_GUIDE_OUTPUT_DIR}/index.txt
217             ${TEXT_INSTALL_GUIDE_OUTPUT_DIR}/INSTALL
218         WORKING_DIRECTORY
219             ${CMAKE_CURRENT_BINARY_DIR}
220         COMMENT "Building INSTALL with Sphinx"
221         VERBATIM
222         )
223     add_dependencies(install-guide sphinx-input)
224     gmx_cpack_add_generated_source_directory(install-guide/text DESTINATION /)
226     # Sphinx cache with pickled ReST documents
227     set(SPHINX_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees")
229     add_custom_target(webpage-sphinx
230         COMMAND
231             ${CMAKE_COMMAND} -E make_directory ${SPHINX_INPUT_DIR}/_static
232         COMMAND
233             ${SPHINX_EXECUTABLE}
234             -q -b html
235             -w sphinx-html.log
236             -d "${SPHINX_CACHE_DIR}"
237             "${SPHINX_INPUT_DIR}"
238             "${HTML_OUTPUT_DIR}"
239         WORKING_DIRECTORY
240             ${CMAKE_CURRENT_BINARY_DIR}
241         COMMENT "Building HTML documentation with Sphinx"
242         VERBATIM
243         )
244     add_dependencies(webpage-sphinx sphinx-input sphinx-programs)
246     add_custom_target(man
247         COMMAND
248             ${SPHINX_EXECUTABLE}
249             -q -b man
250             -w sphinx-man.log
251             -d ${SPHINX_CACHE_DIR}
252             -t do_man
253             ${SPHINX_INPUT_DIR}
254             ${CMAKE_CURRENT_BINARY_DIR}/man
255         COMMENT "Building man pages with Sphinx"
256         VERBATIM)
257     add_dependencies(man sphinx-input sphinx-programs)
258     if (GMX_BUILD_HELP)
259         # If requested, install the man pages built by the 'man' target
260         # created above.  Nothing will be installed if the user did not
261         # manually build the target.
262         set(MAN_PAGE_DIR ${CMAKE_CURRENT_BINARY_DIR})
263     endif()
264 else()
265     add_custom_target(webpage-sphinx
266         COMMAND ${CMAKE_COMMAND} -E echo
267             "HTML pages cannot be built because Sphinx version ${EXPECTED_SPHINX_VERSION} is not available"
268         VERBATIM)
269     add_custom_target(install-guide
270         COMMAND ${CMAKE_COMMAND} -E echo
271             "INSTALL cannot be built because Sphinx version ${EXPECTED_SPHINX_VERSION} is not available"
272         VERBATIM)
273     add_custom_target(man
274         COMMAND ${CMAKE_COMMAND} -E echo
275             "man pages cannot be built because Sphinx version ${EXPECTED_SPHINX_VERSION} is not available"
276         VERBATIM)
277 endif()
279 if (MAN_PAGE_DIR)
280     set(MAN_PAGE_DIR ${MAN_PAGE_DIR}/man)
281     # Trailing slash on directory is significant for
282     # install(DIRECTORY). See CMake docs.
283     install(DIRECTORY ${MAN_PAGE_DIR}/
284         DESTINATION ${MAN_INSTALL_DIR}/man1
285         COMPONENT man OPTIONAL
286         FILES_MATCHING PATTERN "*.1")
287 endif()
288 gmx_cpack_add_generated_source_directory(man)
290 # Determine whether we can build all the HTML pages and content linked from
291 # there.  If not, construct an informative message if the user tries to
292 # build the target; most people never need to know, unless they've asked for
293 # the webpage build.
294 set(HTML_BUILD_IS_POSSIBLE ON)
295 set(HTML_BUILD_NOT_POSSIBLE_REASON)
296 set(HTML_BUILD_WARNINGS)
298 # Next, turn it off if any of the preconditions are unsatisified
299 if (NOT PYTHON_EXECUTABLE)
300     set(HTML_BUILD_IS_POSSIBLE OFF)
301     set(HTML_BUILD_NOT_POSSIBLE_REASON "Python is required")
302 elseif (NOT SPHINX_FOUND)
303     # Hardly anything gets built if Sphinx is not available, so don't bother.
304     set(HTML_BUILD_IS_POSSIBLE OFF)
305     set(HTML_BUILD_NOT_POSSIBLE_REASON "Sphinx version ${EXPECTED_SPHINX_VERSION} is required")
306 endif()
307 if (NOT MANUAL_BUILD_IS_POSSIBLE)
308     list(APPEND HTML_BUILD_WARNINGS
309          "Reference PDF manual was not built, so links to it do not work")
310 endif()
311 if (NOT DOXYGEN_EXECUTABLE)
312     list(APPEND HTML_BUILD_WARNINGS
313         "Doxygen was not available, so links to Doxygen do not work")
314 endif()
315 if (NOT DOXYGEN_DOT_EXECUTABLE)
316     list(APPEND HTML_BUILD_WARNINGS
317         "dot/graphviz was not found, so some graphs are missing")
318 endif()
320 if (HTML_BUILD_IS_POSSIBLE)
321     set(_webpage_target_properties)
322     if (HTML_BUILD_WARNINGS)
323         list(APPEND _webpage_target_properties
324              COMMAND ${CMAKE_COMMAND} -E echo
325                  "webpage was built, but with the following limitations:")
326         foreach(_warning ${HTML_BUILD_WARNINGS})
327         list(APPEND _webpage_target_properties
328              COMMAND ${CMAKE_COMMAND} -E echo " - ${_warning}")
329         endforeach()
330     endif()
332     if (MANUAL_BUILD_IS_POSSIBLE)
333         # Make the PDF reference guide
334         # TODO Try to make the PDF arrive directly in ${HTML_OUTPUT_DIR}
335         # TODO Make this depend on the output of the manual build, so that the
336         # file actually gets copied multiple times.
337         set(_manual_target_location ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf)
338         add_custom_command(
339             OUTPUT ${_manual_target_location}
340             COMMAND ${CMAKE_COMMAND}
341                 -E remove -f ${_manual_target_location}
342             COMMAND ${CMAKE_COMMAND}
343                 -E copy ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf ${_manual_target_location}
344             DEPENDS manual
345             VERBATIM)
346         list(APPEND _webpage_target_properties
347              DEPENDS ${_manual_target_location})
348     endif()
350     # The Doxygen configuration in doxygen/Doxyfile-common.cmakein
351     # makes all the Doxygen output directly in
352     # ${HTML_OUTPUT_DIR}/doxygen (and makes the directory if it needs
353     # to).
355     # Add a top-level target that builds everything related to the webpage,
356     # for Jenkins (and possibly others) to use
357     add_custom_target(webpage ${_webpage_target_properties}
358         COMMENT "Building webpage"
359         VERBATIM)
360     add_dependencies(webpage webpage-sphinx doxygen-all)
361 else()
362     add_custom_target(webpage
363         COMMAND ${CMAKE_COMMAND} -E echo
364             "Cannot build webpage because ${HTML_BUILD_NOT_POSSIBLE_REASON}"
365         COMMENT "Webpage build not possible"
366         VERBATIM)
367 endif()