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