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