Replace tool HTML help with Sphinx-generated docs
[alexxy/gromacs.git] / docs / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2014,2015, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
8 #
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
13 #
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23 #
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
31 #
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
34
35 # This directory provides a unified place for building all kinds of
36 # GROMACS documentation. This includes some "static" content (Doxygen
37 # code documentation, reference manual, install guide, old online HTML
38 # pages), 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 # Even if we aren't going to make the full webpage, set up to put all
55 # the documentation output in the same place, for convenience
56 set(HTML_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/html")
57 file(MAKE_DIRECTORY ${HTML_OUTPUT_DIR})
58
59 find_package(PythonInterp)
60 find_package(Sphinx 1.2.3 COMPONENTS pygments)
61
62 add_subdirectory(man)
63 add_subdirectory(old-html)
64 add_subdirectory(doxygen)
65
66 option(GMX_BUILD_WEBPAGE "Whether to try to configure to build the GROMACS static webpages" OFF)
67 mark_as_advanced(GMX_BUILD_WEBPAGE)
68 option(GMX_BUILD_MANUAL "Whether to try to configure to build the PDF manual" OFF)
69 mark_as_advanced(GMX_BUILD_MANUAL)
70 if(GMX_BUILD_MANUAL)
71     # Make sure we only do detection of manual-building dependencies
72     # when the user opted in for that.
73     add_subdirectory(manual)
74 endif()
75
76 if (SPHINX_FOUND)
77     # We need to copy all the Sphinx input files to a single directory, and
78     # since some of them are (or will be) generated, we just copy everything
79     # into the build tree, to this directory.
80     set(SPHINX_INPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/sphinx-input)
81     set(SPHINX_CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/conf.py)
82     set(SPHINX_CONFIG_VARS_FILE ${SPHINX_INPUT_DIR}/conf-vars.py)
83     gmx_configure_version_file(conf-vars.py.cmakein ${SPHINX_CONFIG_VARS_FILE}
84         EXTRA_VARS
85             GMX_CMAKE_MINIMUM_REQUIRED_VERSION REQUIRED_CUDA_VERSION
86             REQUIRED_CUDA_COMPUTE_CAPABILITY REGRESSIONTEST_VERSION
87             SOURCE_MD5SUM REGRESSIONTESTS_MD5SUM
88         COMMENT "Configuring Sphinx configuration file")
89     set(SPHINX_SOURCE_FILES
90         index.rst
91         download.rst
92         online.rst
93         install-guide/index.rst
94         user-guide/index.rst
95         user-guide/getting-started.rst
96         user-guide/cutoff-schemes.rst
97         user-guide/file-formats.rst
98         user-guide/tools.rst
99         conf.py
100         )
101     set(SPHINX_INPUT_FILES ${SPHINX_CONFIG_VARS_FILE})
102     foreach(_file ${SPHINX_SOURCE_FILES})
103         add_custom_command(
104             OUTPUT ${SPHINX_INPUT_DIR}/${_file}
105             COMMAND ${CMAKE_COMMAND} -E copy
106                 ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
107                 ${SPHINX_INPUT_DIR}/${_file}
108             DEPENDS
109                 ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
110             COMMENT "Copying Sphinx input file ${_file}"
111             VERBATIM)
112         list(APPEND SPHINX_INPUT_FILES ${SPHINX_INPUT_DIR}/${_file})
113     endforeach()
114     gmx_add_custom_output_target(sphinx-input OUTPUT STAMP
115         DEPENDS ${SPHINX_INPUT_FILES})
116     gmx_add_custom_output_target(sphinx-programs OUTPUT STAMP
117         COMMAND ${CMAKE_COMMAND} -E make_directory programs
118         COMMAND gmx -quiet help -export rst
119         DEPENDS gmx
120         WORKING_DIRECTORY ${SPHINX_INPUT_DIR}
121         COMMENT "Generating reStructuredText help")
122     # This dependency ensures that the directories exist before the
123     # executable tries to write things there.
124     add_dependencies(sphinx-programs sphinx-input)
125
126     # Make the INSTALL file for CPack for the tarball. This gets put
127     # into the tarball via the CPack rules below, which requires that
128     # the INSTALL file is in a separate directory by itself.
129     set(TEXT_INSTALL_GUIDE_OUTPUT_DIR "install-guide/text")
130     add_custom_target(install-guide
131         COMMAND
132             ${SPHINX_EXECUTABLE}
133             -q -b text
134             -w sphinx-install.log
135             -d ${CMAKE_CURRENT_BINARY_DIR}/install-guide/_doctrees
136             -c ${SPHINX_INPUT_DIR}
137             "${SPHINX_INPUT_DIR}/install-guide"
138             "${TEXT_INSTALL_GUIDE_OUTPUT_DIR}"
139         COMMAND
140             ${CMAKE_COMMAND} -E rename
141             ${TEXT_INSTALL_GUIDE_OUTPUT_DIR}/index.txt
142             ${TEXT_INSTALL_GUIDE_OUTPUT_DIR}/INSTALL
143         WORKING_DIRECTORY
144             ${CMAKE_CURRENT_BINARY_DIR}
145         COMMENT "Building INSTALL with Sphinx"
146         VERBATIM
147         )
148     add_dependencies(install-guide sphinx-input)
149     gmx_cpack_add_generated_source_directory(install-guide/text DESTINATION /)
150
151     # For a real build of the webpage, the md5sum of the tarballs must
152     # already be known, and so we may as well require that the real
153     # build of the webpage take place from cmake run from the unpacked
154     # tarball. Then, the *_MD5SUM and *_TARBALL variables will be able
155     # to be set on the cmake command line (e.g. by a Jenkins job
156     # configuration), and we can require that they are set. For local
157     # building of the webpages (e.g. for debugging), those variables
158     # can be left unset, and if so, the download section will not be
159     # constructed.
160     if(SOURCE_IS_SOURCE_DISTRIBUTION AND GMX_BUILD_WEBPAGE)
161         foreach(VAR SOURCE_MD5SUM REGRESSIONTESTS_MD5SUM SOURCE_TARBALL REGRESSIONTESTS_TARBALL)
162             if(NOT DEFINED ${VAR})
163                 message(FATAL_ERROR "The build of the webpage requires that ${VAR} is set in the cmake cache, e.g. on the CMake command line")
164             endif()
165         endforeach()
166         set(BUILD_DOWNLOAD_SECTION on)
167     else()
168         if (SOURCE_TARBALL AND SOURCE_MD5SUM AND
169                 REGRESSIONTESTS_TARBALL AND REGRESSIONTESTS_MD5SUM)
170             set(BUILD_DOWNLOAD_SECTION on)
171         else()
172             set(BUILD_DOWNLOAD_SECTION off)
173         endif()
174     endif()
175
176     # Sphinx cache with pickled ReST documents
177     set(SPHINX_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees")
178
179     add_custom_target(webpage-sphinx
180         COMMAND
181             ${CMAKE_COMMAND} -E make_directory ${SPHINX_INPUT_DIR}/_static
182         COMMAND
183             ${SPHINX_EXECUTABLE}
184             -q -b html
185             -w sphinx-html.log
186             -d "${SPHINX_CACHE_DIR}"
187             "${SPHINX_INPUT_DIR}"
188             "${HTML_OUTPUT_DIR}"
189         WORKING_DIRECTORY
190             ${CMAKE_CURRENT_BINARY_DIR}
191         COMMENT "Building HTML documentation with Sphinx"
192         VERBATIM
193         )
194     add_dependencies(webpage-sphinx sphinx-input sphinx-programs)
195 endif()
196
197 set(HTML_BUILD_IS_POSSIBLE OFF)
198 # We can only configure to build the webpage if the user asked for it,
199 # the build is outside of the source dir, and all the components can
200 # be built. There's no intrinsic need to be talkative if we fail -
201 # most people never need to know, unless they've asked for the webpage
202 # build.
203 if(GMX_BUILD_WEBPAGE)
204     set(HTML_BUILD_IS_POSSIBLE ON)
205     # Next, turn it off in any of the preconditions are unsatisified
206
207     if(NOT GMX_BUILD_HELP)
208         set(HTML_BUILD_IS_POSSIBLE OFF)
209         message(STATUS "Cannot build webpage without GMX_BUILD_HELP=on")
210     endif()
211
212     if(NOT MANUAL_BUILD_IS_POSSIBLE)
213         set(HTML_BUILD_IS_POSSIBLE OFF)
214         message(STATUS "Cannot build webpage without being able to build the reference PDF manual")
215     endif()
216
217     if(NOT PYTHON_EXECUTABLE)
218         set(HTML_BUILD_IS_POSSIBLE OFF)
219         message(STATUS "Cannot build webpage without python")
220     endif()
221
222     if(NOT SPHINX_FOUND)
223         set(HTML_BUILD_IS_POSSIBLE OFF)
224         message(STATUS "Cannot build webpage without sphinx")
225     endif()
226
227     if(NOT DOXYGEN_EXECUTABLE)
228         set(HTML_BUILD_IS_POSSIBLE OFF)
229         message(STATUS "Cannot build webpage without doxygen")
230     endif()
231
232     if(NOT DOXYGEN_MSCGEN_EXECUTABLE)
233         set(HTML_BUILD_IS_POSSIBLE OFF)
234         message(STATUS "Cannot build webpage without mscgen")
235     endif()
236 endif()
237
238 if(HTML_BUILD_IS_POSSIBLE)
239     # If building the webpage from the repo, then tarballs may not
240     # exist, and if so, it would not make sense to build that part of
241     # the front page from index.rst.
242     if(BUILD_DOWNLOAD_SECTION)
243         # Copy the source tarball to the webpage output
244         add_custom_command(
245             OUTPUT ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
246             COMMAND ${CMAKE_COMMAND}
247                -E copy ${SOURCE_TARBALL} ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
248             VERBATIM
249             )
250
251         # Copy the regressiontests tarball to the webpage output
252         add_custom_command(
253             OUTPUT ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
254             COMMAND ${CMAKE_COMMAND}
255                -E copy ${REGRESSIONTESTS_TARBALL} ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
256             VERBATIM
257             )
258
259         # Add other dependencies for doing the webpage build from the real
260         # tarball
261         list(APPEND extra_webpage_dependencies
262             ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
263             ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
264             )
265     endif()
266
267     # Make the PDF reference guide
268     # TODO Try to make the PDF arrive directly in ${HTML_OUTPUT_DIR}
269     add_custom_command(
270         OUTPUT ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
271         COMMAND ${CMAKE_COMMAND}
272             -E remove -f ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
273         COMMAND ${CMAKE_COMMAND}
274             -E copy ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
275         # UseLATEX.cmake makes a target called pdf, not ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf
276         DEPENDS pdf
277         VERBATIM
278         )
279
280     # TODO Move content from the "old" html output into the new user
281     # guide, or delete, as appropriate.
282     if(NOT SOURCE_IS_SOURCE_DISTRIBUTION)
283         # TODO If content remains here once the user guide is in
284         # decent shape, try to make the generated HTML arrive directly
285         # in ${HTML_OUTPUT_DIR}
286         add_custom_target(webpage-html
287             ${CMAKE_COMMAND} -E copy_directory old-html/final ${HTML_OUTPUT_DIR}
288             )
289         add_dependencies(webpage-html html)
290     else()
291         # In the source distribution, the html pages are already
292         # built, so we can avoid making gmx via the html target
293         add_custom_target(webpage-html
294             ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/old-html/final ${HTML_OUTPUT_DIR}
295             )
296     endif()
297
298     # The Doxygen configuration in doxygen/Doxyfile-common.cmakein
299     # makes all the Doxygen output directly in
300     # ${HTML_OUTPUT_DIR}/doxygen (and makes the directory if it needs
301     # to).
302
303     # Add a top-level target for the others to hook onto
304     add_custom_target(webpage
305         DEPENDS
306            ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
307            ${extra_webpage_dependencies}
308         VERBATIM
309         )
310     add_dependencies(webpage webpage-sphinx webpage-html doxygen-all)
311 else()
312     add_custom_target(webpage
313         COMMAND ${CMAKE_COMMAND} -E echo "Cannot build webpage because of missing requirements. Check cmake status output for reasons"
314         COMMENT "Webpage build disabled"
315         )
316 endif()