292bea2210bc9ec3303e77058c6d41011f62316d
[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 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(old-html)
65 add_subdirectory(doxygen)
66
67 option(GMX_BUILD_WEBPAGE "Whether to try to configure to build the GROMACS static webpages" OFF)
68 mark_as_advanced(GMX_BUILD_WEBPAGE)
69 option(GMX_BUILD_MANUAL "Whether to try to configure to build the PDF manual" OFF)
70 mark_as_advanced(GMX_BUILD_MANUAL)
71 if(GMX_BUILD_MANUAL)
72     # Make sure we only do detection of manual-building dependencies
73     # when the user opted in for that.
74     add_subdirectory(manual)
75 endif()
76
77 if (SPHINX_FOUND)
78     # We need to copy all the Sphinx input files to a single directory, and
79     # since some of them are (or will be) generated, we just copy everything
80     # into the build tree, to this directory.
81     set(SPHINX_INPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/sphinx-input)
82     set(SPHINX_CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/conf.py)
83     set(SPHINX_CONFIG_VARS_FILE ${SPHINX_INPUT_DIR}/conf-vars.py)
84     gmx_configure_version_file(conf-vars.py.cmakein ${SPHINX_CONFIG_VARS_FILE}
85         EXTRA_VARS
86             GMX_CMAKE_MINIMUM_REQUIRED_VERSION REQUIRED_CUDA_VERSION
87             REQUIRED_CUDA_COMPUTE_CAPABILITY REGRESSIONTEST_VERSION
88             SOURCE_MD5SUM REGRESSIONTESTS_MD5SUM
89         COMMENT "Configuring Sphinx configuration file")
90     set(SPHINX_SOURCE_FILES
91         index.rst
92         download.rst
93         online.rst
94         install-guide/index.rst
95         man/gromacs.7.rst
96         user-guide/index.rst
97         user-guide/getting-started.rst
98         user-guide/cutoff-schemes.rst
99         user-guide/file-formats.rst
100         user-guide/tools.rst
101         user-guide/plotje.gif
102         user-guide/xvgr.gif
103         conf.py
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 GMX_BUILD_HELP)
239         set(HTML_BUILD_IS_POSSIBLE OFF)
240         message(STATUS "Cannot build webpage without GMX_BUILD_HELP=on")
241     endif()
242
243     if(NOT MANUAL_BUILD_IS_POSSIBLE)
244         set(HTML_BUILD_IS_POSSIBLE OFF)
245         message(STATUS "Cannot build webpage without being able to build the reference PDF manual")
246     endif()
247
248     if(NOT PYTHON_EXECUTABLE)
249         set(HTML_BUILD_IS_POSSIBLE OFF)
250         message(STATUS "Cannot build webpage without python")
251     endif()
252
253     if(NOT SPHINX_FOUND)
254         set(HTML_BUILD_IS_POSSIBLE OFF)
255         message(STATUS "Cannot build webpage without sphinx")
256     endif()
257
258     if(NOT DOXYGEN_EXECUTABLE)
259         set(HTML_BUILD_IS_POSSIBLE OFF)
260         message(STATUS "Cannot build webpage without doxygen")
261     endif()
262
263     if(NOT DOXYGEN_MSCGEN_EXECUTABLE)
264         set(HTML_BUILD_IS_POSSIBLE OFF)
265         message(STATUS "Cannot build webpage without mscgen")
266     endif()
267 endif()
268
269 if(HTML_BUILD_IS_POSSIBLE)
270     # If building the webpage from the repo, then tarballs may not
271     # exist, and if so, it would not make sense to build that part of
272     # the front page from index.rst.
273     if(BUILD_DOWNLOAD_SECTION)
274         # Copy the source tarball to the webpage output
275         add_custom_command(
276             OUTPUT ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
277             COMMAND ${CMAKE_COMMAND}
278                -E copy ${SOURCE_TARBALL} ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
279             VERBATIM
280             )
281
282         # Copy the regressiontests tarball to the webpage output
283         add_custom_command(
284             OUTPUT ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
285             COMMAND ${CMAKE_COMMAND}
286                -E copy ${REGRESSIONTESTS_TARBALL} ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
287             VERBATIM
288             )
289
290         # Add other dependencies for doing the webpage build from the real
291         # tarball
292         list(APPEND extra_webpage_dependencies
293             ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
294             ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
295             )
296     endif()
297
298     # Make the PDF reference guide
299     # TODO Try to make the PDF arrive directly in ${HTML_OUTPUT_DIR}
300     add_custom_command(
301         OUTPUT ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
302         COMMAND ${CMAKE_COMMAND}
303             -E remove -f ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
304         COMMAND ${CMAKE_COMMAND}
305             -E copy ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
306         # UseLATEX.cmake makes a target called pdf, not ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf
307         DEPENDS pdf
308         VERBATIM
309         )
310
311     # TODO Move content from the "old" html output into the new user
312     # guide, or delete, as appropriate.
313     if(NOT SOURCE_IS_SOURCE_DISTRIBUTION)
314         # TODO If content remains here once the user guide is in
315         # decent shape, try to make the generated HTML arrive directly
316         # in ${HTML_OUTPUT_DIR}
317         add_custom_target(webpage-html
318             ${CMAKE_COMMAND} -E copy_directory old-html/final ${HTML_OUTPUT_DIR}
319             )
320         add_dependencies(webpage-html html)
321     else()
322         # In the source distribution, the html pages are already
323         # built, so we can avoid making gmx via the html target
324         add_custom_target(webpage-html
325             ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/old-html/final ${HTML_OUTPUT_DIR}
326             )
327     endif()
328
329     # The Doxygen configuration in doxygen/Doxyfile-common.cmakein
330     # makes all the Doxygen output directly in
331     # ${HTML_OUTPUT_DIR}/doxygen (and makes the directory if it needs
332     # to).
333
334     # Add a top-level target for the others to hook onto
335     add_custom_target(webpage
336         DEPENDS
337            ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
338            ${extra_webpage_dependencies}
339         VERBATIM
340         )
341     add_dependencies(webpage webpage-sphinx webpage-html doxygen-all)
342 else()
343     add_custom_target(webpage
344         COMMAND ${CMAKE_COMMAND} -E echo "Cannot build webpage because of missing requirements. Check cmake status output for reasons"
345         COMMENT "Webpage build disabled"
346         )
347 endif()