Convert developer manual to rst
[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 option(GMX_BUILD_WEBPAGE "Whether to try to configure to build the GROMACS static webpages" OFF)
55 option(GMX_BUILD_MANUAL "Whether to try to configure to build the PDF manual" OFF)
56 mark_as_advanced(GMX_BUILD_WEBPAGE GMX_BUILD_MANUAL)
57
58 find_package(PythonInterp)
59 find_package(Sphinx 1.2.3 COMPONENTS pygments)
60
61 # Even if we aren't going to make the full webpage, set up to put all
62 # the documentation output in the same place, for convenience
63 set(HTML_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/html")
64 file(MAKE_DIRECTORY ${HTML_OUTPUT_DIR})
65
66 # The directory from which man pages will be installed; if it remains
67 # empty, they will be silently skipped.
68 set(MAN_PAGE_DIR)
69 if (SOURCE_IS_SOURCE_DISTRIBUTION)
70     # When building from the tarball, install the bundled man pages
71     # (unless overridden).
72     set(MAN_PAGE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
73 endif()
74
75 add_subdirectory(doxygen)
76
77 set(SOURCE_MD5SUM "unknown" CACHE STRING "MD5 sum of the source tarball, normally used only for the pre-release webpage build")
78 # REGRESSIONTEST_MD5SUM is set in cmake/gmxVersionInfo.cmake because it is used also in tests/CMakeLists.txt
79 mark_as_advanced(SOURCE_MD5SUM)
80
81 if(GMX_BUILD_MANUAL)
82     # Make sure we only do detection of manual-building dependencies
83     # when the user opted in for that.
84     add_subdirectory(manual)
85 endif()
86
87 if (SPHINX_FOUND)
88     # We need to copy all the Sphinx input files to a single directory, and
89     # since some of them are (or will be) generated, we just copy everything
90     # into the build tree, to this directory.
91     set(SPHINX_INPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/sphinx-input)
92     set(SPHINX_CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/conf.py)
93     set(SPHINX_CONFIG_VARS_FILE ${SPHINX_INPUT_DIR}/conf-vars.py)
94     set(SPHINX_EXTENSION_PATH ${CMAKE_CURRENT_SOURCE_DIR})
95     if(REGRESSIONTEST_MD5SUM)
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     else()
100         # But for testing the webpage build (e.g. from the repo) we
101         # need a default value.
102         set(REGRESSIONTEST_MD5SUM_STRING "unknown")
103     endif()
104     gmx_configure_version_file(conf-vars.py.cmakein ${SPHINX_CONFIG_VARS_FILE}
105         EXTRA_VARS
106             SPHINX_EXTENSION_PATH
107             GMX_CMAKE_MINIMUM_REQUIRED_VERSION REQUIRED_CUDA_VERSION
108             REQUIRED_CUDA_COMPUTE_CAPABILITY REGRESSIONTEST_VERSION
109             SOURCE_MD5SUM REGRESSIONTEST_MD5SUM_STRING
110         COMMENT "Configuring Sphinx configuration file")
111     set(SPHINX_SOURCE_FILES
112         index.rst
113         download.rst
114         dev-manual/index.rst
115         dev-manual/doxygen.rst
116         dev-manual/doxygen-links.rst
117         dev-manual/formatting.rst
118         dev-manual/gmxtree.rst
119         dev-manual/includestyle.rst
120         dev-manual/naming.rst
121         dev-manual/style.rst
122         dev-manual/tools.rst
123         dev-manual/uncrustify.rst
124         install-guide/index.rst
125         man/gromacs.7.rst
126         user-guide/index.rst
127         user-guide/getting-started.rst
128         user-guide/flow.rst
129         user-guide/cutoff-schemes.rst
130         user-guide/mdrun-features.rst
131         user-guide/mdrun-performance.rst
132         user-guide/mdp-options.rst
133         user-guide/file-formats.rst
134         user-guide/tools.rst
135         user-guide/environment-variables.rst
136         user-guide/plotje.gif
137         user-guide/xvgr.gif
138         conf.py
139         links.dat
140         )
141     set(SPHINX_INPUT_FILES ${SPHINX_CONFIG_VARS_FILE})
142     foreach(_file ${SPHINX_SOURCE_FILES})
143         add_custom_command(
144             OUTPUT ${SPHINX_INPUT_DIR}/${_file}
145             COMMAND ${CMAKE_COMMAND} -E copy
146                 ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
147                 ${SPHINX_INPUT_DIR}/${_file}
148             DEPENDS
149                 ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
150             COMMENT "Copying Sphinx input file ${_file}"
151             VERBATIM)
152         list(APPEND SPHINX_INPUT_FILES ${SPHINX_INPUT_DIR}/${_file})
153     endforeach()
154     gmx_add_custom_output_target(sphinx-input OUTPUT STAMP
155         DEPENDS ${SPHINX_INPUT_FILES})
156     gmx_add_custom_output_target(sphinx-programs OUTPUT STAMP
157         COMMAND ${CMAKE_COMMAND} -E make_directory programs
158         COMMAND gmx -quiet help -export rst
159         DEPENDS gmx
160         WORKING_DIRECTORY ${SPHINX_INPUT_DIR}
161         COMMENT "Generating reStructuredText help")
162     # This dependency ensures that the directories exist before the
163     # executable tries to write things there.
164     add_dependencies(sphinx-programs sphinx-input)
165
166     # Make the INSTALL file for CPack for the tarball. This gets put
167     # into the tarball via the CPack rules below, which requires that
168     # the INSTALL file is in a separate directory by itself.
169     set(TEXT_INSTALL_GUIDE_OUTPUT_DIR "install-guide/text")
170     add_custom_target(install-guide
171         COMMAND
172             ${SPHINX_EXECUTABLE}
173             -q -b text
174             -w sphinx-install.log
175             -d ${CMAKE_CURRENT_BINARY_DIR}/install-guide/_doctrees
176             -c ${SPHINX_INPUT_DIR}
177             "${SPHINX_INPUT_DIR}/install-guide"
178             "${TEXT_INSTALL_GUIDE_OUTPUT_DIR}"
179         COMMAND
180             ${CMAKE_COMMAND} -E rename
181             ${TEXT_INSTALL_GUIDE_OUTPUT_DIR}/index.txt
182             ${TEXT_INSTALL_GUIDE_OUTPUT_DIR}/INSTALL
183         WORKING_DIRECTORY
184             ${CMAKE_CURRENT_BINARY_DIR}
185         COMMENT "Building INSTALL with Sphinx"
186         VERBATIM
187         )
188     add_dependencies(install-guide sphinx-input)
189     gmx_cpack_add_generated_source_directory(install-guide/text DESTINATION /)
190
191     # Sphinx cache with pickled ReST documents
192     set(SPHINX_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees")
193
194     add_custom_target(webpage-sphinx
195         COMMAND
196             ${CMAKE_COMMAND} -E make_directory ${SPHINX_INPUT_DIR}/_static
197         COMMAND
198             ${SPHINX_EXECUTABLE}
199             -q -b html
200             -w sphinx-html.log
201             -d "${SPHINX_CACHE_DIR}"
202             "${SPHINX_INPUT_DIR}"
203             "${HTML_OUTPUT_DIR}"
204         WORKING_DIRECTORY
205             ${CMAKE_CURRENT_BINARY_DIR}
206         COMMENT "Building HTML documentation with Sphinx"
207         VERBATIM
208         )
209     add_dependencies(webpage-sphinx sphinx-input sphinx-programs)
210
211     add_custom_target(man
212         COMMAND
213             ${SPHINX_EXECUTABLE}
214             -q -b man
215             -w sphinx-man.log
216             -d ${SPHINX_CACHE_DIR}
217             -t do_man
218             ${SPHINX_INPUT_DIR}
219             ${CMAKE_CURRENT_BINARY_DIR}/man
220         COMMENT "Building man pages with Sphinx"
221         VERBATIM)
222     add_dependencies(man sphinx-input sphinx-programs)
223     if (GMX_BUILD_HELP)
224         # If requested, install the man pages built by the 'man' target
225         # created above.  Nothing will be installed if the user did not
226         # manually build the target.
227         set(MAN_PAGE_DIR ${CMAKE_CURRENT_BINARY_DIR})
228     endif()
229 endif()
230
231 if (MAN_PAGE_DIR)
232     set(MAN_PAGE_DIR ${MAN_PAGE_DIR}/man)
233     # Trailing slash on directory is significant for
234     # install(DIRECTORY). See CMake docs.
235     install(DIRECTORY ${MAN_PAGE_DIR}/
236         DESTINATION ${MAN_INSTALL_DIR}/man1
237         COMPONENT man OPTIONAL
238         FILES_MATCHING PATTERN "*.1")
239     install(DIRECTORY ${MAN_PAGE_DIR}/
240         DESTINATION ${MAN_INSTALL_DIR}/man7
241         COMPONENT man OPTIONAL
242         FILES_MATCHING PATTERN "*.7")
243 endif()
244 gmx_cpack_add_generated_source_directory(man)
245
246 set(HTML_BUILD_IS_POSSIBLE OFF)
247 # We can only configure to build the webpage if the user asked for it,
248 # the build is outside of the source dir, and all the components can
249 # be built. There's no intrinsic need to be talkative if we fail -
250 # most people never need to know, unless they've asked for the webpage
251 # build.
252 if(GMX_BUILD_WEBPAGE)
253     set(HTML_BUILD_IS_POSSIBLE ON)
254     # Next, turn it off in any of the preconditions are unsatisified
255
256     if(NOT MANUAL_BUILD_IS_POSSIBLE)
257         set(HTML_BUILD_IS_POSSIBLE OFF)
258         message(STATUS "Cannot build webpage without being able to build the reference PDF manual")
259     endif()
260
261     if(NOT PYTHON_EXECUTABLE)
262         set(HTML_BUILD_IS_POSSIBLE OFF)
263         message(STATUS "Cannot build webpage without python")
264     endif()
265
266     if(NOT SPHINX_FOUND)
267         set(HTML_BUILD_IS_POSSIBLE OFF)
268         message(STATUS "Cannot build webpage without sphinx")
269     endif()
270
271     if(NOT DOXYGEN_EXECUTABLE)
272         set(HTML_BUILD_IS_POSSIBLE OFF)
273         message(STATUS "Cannot build webpage without doxygen")
274     endif()
275
276     if(NOT DOXYGEN_MSCGEN_EXECUTABLE)
277         set(HTML_BUILD_IS_POSSIBLE OFF)
278         message(STATUS "Cannot build webpage without mscgen")
279     endif()
280 endif()
281
282 # TODO Get rid of the remaining content in old-html
283 add_custom_target(webpage-old-images
284     ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/old-html ${HTML_OUTPUT_DIR}
285     COMMENT "Copying flowchart images"
286     VERBATIM
287     )
288
289 if(HTML_BUILD_IS_POSSIBLE)
290     # Make the PDF reference guide
291     # TODO Try to make the PDF arrive directly in ${HTML_OUTPUT_DIR}
292     add_custom_command(
293         OUTPUT ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
294         COMMAND ${CMAKE_COMMAND}
295             -E remove -f ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
296         COMMAND ${CMAKE_COMMAND}
297             -E copy ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
298         # UseLATEX.cmake makes a target called pdf, not ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf
299         DEPENDS pdf
300         VERBATIM
301         )
302
303     # The Doxygen configuration in doxygen/Doxyfile-common.cmakein
304     # makes all the Doxygen output directly in
305     # ${HTML_OUTPUT_DIR}/doxygen (and makes the directory if it needs
306     # to).
307
308     # Add a top-level target for the others to hook onto
309     add_custom_target(webpage
310         DEPENDS
311            ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
312            ${extra_webpage_dependencies}
313         VERBATIM
314         )
315     add_dependencies(webpage webpage-sphinx webpage-old-images doxygen-all)
316 else()
317     add_custom_target(webpage
318         COMMAND ${CMAKE_COMMAND} -E echo "Cannot build webpage because of missing requirements. Check cmake status output for reasons"
319         COMMENT "Webpage build disabled"
320         )
321 endif()