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