Move flow chart from old-html to Sphinx
[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 # 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 # 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 set(MAN_PAGE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
60
61 find_package(PythonInterp)
62 find_package(Sphinx 1.2.3 COMPONENTS pygments)
63
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         install-guide/index.rst
93         man/gromacs.7.rst
94         user-guide/index.rst
95         user-guide/getting-started.rst
96         user-guide/flow.rst
97         user-guide/cutoff-schemes.rst
98         user-guide/file-formats.rst
99         user-guide/tools.rst
100         user-guide/plotje.gif
101         user-guide/xvgr.gif
102         conf.py
103         links.dat
104         )
105     set(SPHINX_INPUT_FILES ${SPHINX_CONFIG_VARS_FILE})
106     foreach(_file ${SPHINX_SOURCE_FILES})
107         add_custom_command(
108             OUTPUT ${SPHINX_INPUT_DIR}/${_file}
109             COMMAND ${CMAKE_COMMAND} -E copy
110                 ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
111                 ${SPHINX_INPUT_DIR}/${_file}
112             DEPENDS
113                 ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
114             COMMENT "Copying Sphinx input file ${_file}"
115             VERBATIM)
116         list(APPEND SPHINX_INPUT_FILES ${SPHINX_INPUT_DIR}/${_file})
117     endforeach()
118     gmx_add_custom_output_target(sphinx-input OUTPUT STAMP
119         DEPENDS ${SPHINX_INPUT_FILES})
120     gmx_add_custom_output_target(sphinx-programs OUTPUT STAMP
121         COMMAND ${CMAKE_COMMAND} -E make_directory programs
122         COMMAND gmx -quiet help -export rst
123         DEPENDS gmx
124         WORKING_DIRECTORY ${SPHINX_INPUT_DIR}
125         COMMENT "Generating reStructuredText help")
126     # This dependency ensures that the directories exist before the
127     # executable tries to write things there.
128     add_dependencies(sphinx-programs sphinx-input)
129
130     # Make the INSTALL file for CPack for the tarball. This gets put
131     # into the tarball via the CPack rules below, which requires that
132     # the INSTALL file is in a separate directory by itself.
133     set(TEXT_INSTALL_GUIDE_OUTPUT_DIR "install-guide/text")
134     add_custom_target(install-guide
135         COMMAND
136             ${SPHINX_EXECUTABLE}
137             -q -b text
138             -w sphinx-install.log
139             -d ${CMAKE_CURRENT_BINARY_DIR}/install-guide/_doctrees
140             -c ${SPHINX_INPUT_DIR}
141             "${SPHINX_INPUT_DIR}/install-guide"
142             "${TEXT_INSTALL_GUIDE_OUTPUT_DIR}"
143         COMMAND
144             ${CMAKE_COMMAND} -E rename
145             ${TEXT_INSTALL_GUIDE_OUTPUT_DIR}/index.txt
146             ${TEXT_INSTALL_GUIDE_OUTPUT_DIR}/INSTALL
147         WORKING_DIRECTORY
148             ${CMAKE_CURRENT_BINARY_DIR}
149         COMMENT "Building INSTALL with Sphinx"
150         VERBATIM
151         )
152     add_dependencies(install-guide sphinx-input)
153     gmx_cpack_add_generated_source_directory(install-guide/text DESTINATION /)
154
155     # For a real build of the webpage, the md5sum of the tarballs must
156     # already be known, and so we may as well require that the real
157     # build of the webpage take place from cmake run from the unpacked
158     # tarball. Then, the *_MD5SUM and *_TARBALL variables will be able
159     # to be set on the cmake command line (e.g. by a Jenkins job
160     # configuration), and we can require that they are set. For local
161     # building of the webpages (e.g. for debugging), those variables
162     # can be left unset, and if so, the download section will not be
163     # constructed.
164     if(SOURCE_IS_SOURCE_DISTRIBUTION AND GMX_BUILD_WEBPAGE)
165         foreach(VAR SOURCE_MD5SUM REGRESSIONTESTS_MD5SUM SOURCE_TARBALL REGRESSIONTESTS_TARBALL)
166             if(NOT DEFINED ${VAR})
167                 message(FATAL_ERROR "The build of the webpage requires that ${VAR} is set in the cmake cache, e.g. on the CMake command line")
168             endif()
169         endforeach()
170         set(BUILD_DOWNLOAD_SECTION on)
171     else()
172         if (SOURCE_TARBALL AND SOURCE_MD5SUM AND
173                 REGRESSIONTESTS_TARBALL AND REGRESSIONTESTS_MD5SUM)
174             set(BUILD_DOWNLOAD_SECTION on)
175         else()
176             set(BUILD_DOWNLOAD_SECTION off)
177         endif()
178     endif()
179
180     # Sphinx cache with pickled ReST documents
181     set(SPHINX_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees")
182
183     add_custom_target(webpage-sphinx
184         COMMAND
185             ${CMAKE_COMMAND} -E make_directory ${SPHINX_INPUT_DIR}/_static
186         COMMAND
187             ${SPHINX_EXECUTABLE}
188             -q -b html
189             -w sphinx-html.log
190             -d "${SPHINX_CACHE_DIR}"
191             "${SPHINX_INPUT_DIR}"
192             "${HTML_OUTPUT_DIR}"
193         WORKING_DIRECTORY
194             ${CMAKE_CURRENT_BINARY_DIR}
195         COMMENT "Building HTML documentation with Sphinx"
196         VERBATIM
197         )
198     add_dependencies(webpage-sphinx sphinx-input sphinx-programs)
199
200     add_custom_target(man
201         COMMAND
202             ${SPHINX_EXECUTABLE}
203             -q -b man
204             -w sphinx-man.log
205             -d ${SPHINX_CACHE_DIR}
206             -t do_man
207             ${SPHINX_INPUT_DIR}
208             ${CMAKE_CURRENT_BINARY_DIR}/man
209         COMMENT "Building man pages with Sphinx"
210         VERBATIM)
211     add_dependencies(man sphinx-input sphinx-programs)
212     if (NOT SOURCE_IS_SOURCE_DISTRIBUTION OR GMX_BUILD_HELP)
213         set(MAN_PAGE_DIR ${CMAKE_CURRENT_BINARY_DIR}/man)
214     endif()
215 endif()
216 if (SOURCE_IS_SOURCE_DISTRIBUTION OR (GMX_BUILD_HELP AND SPHINX_FOUND))
217     install(DIRECTORY ${MAN_PAGE_DIR}/
218         DESTINATION ${MAN_INSTALL_DIR}/man1
219         COMPONENT man OPTIONAL
220         FILES_MATCHING PATTERN "*.1")
221     install(DIRECTORY ${MAN_PAGE_DIR}/
222         DESTINATION ${MAN_INSTALL_DIR}/man7
223         COMPONENT man OPTIONAL
224         FILES_MATCHING PATTERN "*.7")
225 endif()
226 gmx_cpack_add_generated_source_directory(man)
227
228 set(HTML_BUILD_IS_POSSIBLE OFF)
229 # We can only configure to build the webpage if the user asked for it,
230 # the build is outside of the source dir, and all the components can
231 # be built. There's no intrinsic need to be talkative if we fail -
232 # most people never need to know, unless they've asked for the webpage
233 # build.
234 if(GMX_BUILD_WEBPAGE)
235     set(HTML_BUILD_IS_POSSIBLE ON)
236     # Next, turn it off in any of the preconditions are unsatisified
237
238     if(NOT MANUAL_BUILD_IS_POSSIBLE)
239         set(HTML_BUILD_IS_POSSIBLE OFF)
240         message(STATUS "Cannot build webpage without being able to build the reference PDF manual")
241     endif()
242
243     if(NOT PYTHON_EXECUTABLE)
244         set(HTML_BUILD_IS_POSSIBLE OFF)
245         message(STATUS "Cannot build webpage without python")
246     endif()
247
248     if(NOT SPHINX_FOUND)
249         set(HTML_BUILD_IS_POSSIBLE OFF)
250         message(STATUS "Cannot build webpage without sphinx")
251     endif()
252
253     if(NOT DOXYGEN_EXECUTABLE)
254         set(HTML_BUILD_IS_POSSIBLE OFF)
255         message(STATUS "Cannot build webpage without doxygen")
256     endif()
257
258     if(NOT DOXYGEN_MSCGEN_EXECUTABLE)
259         set(HTML_BUILD_IS_POSSIBLE OFF)
260         message(STATUS "Cannot build webpage without mscgen")
261     endif()
262 endif()
263
264 # TODO Get rid of the remaining content in old-html
265 add_custom_target(webpage-old-images
266     ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/old-html ${HTML_OUTPUT_DIR}
267     COMMENT "Copying flowchart images"
268     VERBATIM
269     )
270
271 if(HTML_BUILD_IS_POSSIBLE)
272     # If building the webpage from the repo, then tarballs may not
273     # exist, and if so, it would not make sense to build that part of
274     # the front page from index.rst.
275     if(BUILD_DOWNLOAD_SECTION)
276         # Copy the source tarball to the webpage output
277         add_custom_command(
278             OUTPUT ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
279             COMMAND ${CMAKE_COMMAND}
280                -E copy ${SOURCE_TARBALL} ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
281             VERBATIM
282             )
283
284         # Copy the regressiontests tarball to the webpage output
285         add_custom_command(
286             OUTPUT ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
287             COMMAND ${CMAKE_COMMAND}
288                -E copy ${REGRESSIONTESTS_TARBALL} ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
289             VERBATIM
290             )
291
292         # Add other dependencies for doing the webpage build from the real
293         # tarball
294         list(APPEND extra_webpage_dependencies
295             ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
296             ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
297             )
298     endif()
299
300     # Make the PDF reference guide
301     # TODO Try to make the PDF arrive directly in ${HTML_OUTPUT_DIR}
302     add_custom_command(
303         OUTPUT ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
304         COMMAND ${CMAKE_COMMAND}
305             -E remove -f ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
306         COMMAND ${CMAKE_COMMAND}
307             -E copy ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
308         # UseLATEX.cmake makes a target called pdf, not ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf
309         DEPENDS pdf
310         VERBATIM
311         )
312
313     # The Doxygen configuration in doxygen/Doxyfile-common.cmakein
314     # makes all the Doxygen output directly in
315     # ${HTML_OUTPUT_DIR}/doxygen (and makes the directory if it needs
316     # to).
317
318     # Add a top-level target for the others to hook onto
319     add_custom_target(webpage
320         DEPENDS
321            ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
322            ${extra_webpage_dependencies}
323         VERBATIM
324         )
325     add_dependencies(webpage webpage-sphinx webpage-old-images doxygen-all)
326 else()
327     add_custom_target(webpage
328         COMMAND ${CMAKE_COMMAND} -E echo "Cannot build webpage because of missing requirements. Check cmake status output for reasons"
329         COMMENT "Webpage build disabled"
330         )
331 endif()