6947156d36a78ac82e5d0f745bbea659dda48a22
[alexxy/gromacs.git] / docs / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2014, 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 # All of the markdown content is configured, and we'd like to do that
45 # at build time rather than configure time (for speed, when not
46 # building markdown content). Also, the way they should be configured
47 # varies with whether the source is a tarball or repo, and which file
48 # is being configured. So several *_IS_POSSIBLE variables are used to
49 # direct the configure-time logic so that all appropriate variables
50 # are set by the time the configure-markdown.cmake.in file is
51 # configured, so that later it can do the configuration of all the
52 # markdown files and the right thing will happen in each case.
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 if(${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
60     set(MARKDOWN_CONFIGURE_IS_POSSIBLE off)
61 else()
62     set(MARKDOWN_CONFIGURE_IS_POSSIBLE on)
63 endif()
64 find_package(Pandoc)
65
66 # Set up common infrastructure for configuring markdown at build time.
67 # Do replacement of CMake variables for version strings, etc. The use
68 # of configure-markdown.cmake defers until build time the
69 # configuration of markdown files, which could be faster for all the
70 # configurations that don't make the documentation even though it was
71 # possible, and helps avoid global re-configures if these files
72 # change.
73 set(SCRIPT_TO_CONFIGURE_MARKDOWN ${CMAKE_CURRENT_BINARY_DIR}/configure-markdown.cmake)
74 configure_file(configure-markdown.cmake.in
75     ${SCRIPT_TO_CONFIGURE_MARKDOWN}
76     @ONLY)
77
78 # Makes a custom command to configure a Markdown file found in the
79 # current source directory with the configure-markdown.make script
80 # produced above. The result is placed in the current binary directory
81 # for future use.
82 function(configure_markdown MARKDOWN_FILE)
83     add_custom_command(
84         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${MARKDOWN_FILE}
85         COMMAND ${CMAKE_COMMAND}
86             -D FILE_TO_CONFIGURE=${CMAKE_CURRENT_SOURCE_DIR}/${MARKDOWN_FILE}
87             -D CONFIGURED_FILE=${CMAKE_CURRENT_BINARY_DIR}/${MARKDOWN_FILE}
88             -P ${SCRIPT_TO_CONFIGURE_MARKDOWN}
89         DEPENDS
90             ${SCRIPT_TO_CONFIGURE_MARKDOWN}
91             ${CMAKE_CURRENT_SOURCE_DIR}/${MARKDOWN_FILE}
92         COMMENT "Configuring Markdown"
93         VERBATIM
94         )
95 endfunction()
96
97 # Makes a custom command to make single-page HTML from Markdown. Takes
98 # a NAME argument for an output filename prefix, and a list of full
99 # paths to input files to concatenate with Pandoc into the HTML
100 # output.
101 function(make_markdown_html NAME)
102     add_custom_command(
103         OUTPUT ${HTML_OUTPUT_DIR}/${NAME}.html
104         COMMAND
105             ${PANDOC_EXECUTABLE} ${ARGN} -o ${HTML_OUTPUT_DIR}/${NAME}.html -s --toc --css buttondown.css
106         DEPENDS ${ARGN}
107         VERBATIM
108         )
109 endfunction()
110
111 # Makes a custom command to make PDF from Markdown. Takes a NAME
112 # argument for an output filename prefix, and a list of full paths to
113 # input files to concatenate with Pandoc into the PDF.
114 function(make_markdown_pdf NAME)
115     add_custom_command(
116         OUTPUT ${HTML_OUTPUT_DIR}/${NAME}.pdf
117         COMMAND
118             ${PANDOC_EXECUTABLE} ${ARGN} -o ${HTML_OUTPUT_DIR}/${NAME}.pdf -s --toc
119         DEPENDS ${ARGN}
120         VERBATIM
121         )
122 endfunction()
123
124 # function(make_markdown_multipage_html NAME)
125 #     # Make the multi-page HTML install guide
126 #
127 #     # TODO This is currently disabled, because the pandoc-specific
128 #     # buttondown.css doesn't work with the different kind of output
129 #     # makeinfo produces. When we understand better how we want to do
130 #     # generation, decide whether we want multi-page HTML output and
131 #     # how to make it work well.
132 #
133 #     add_custom_command(
134 #         OUTPUT ${HTML_OUTPUT_DIR}/${HTML_DIR}/index.html
135 #         COMMAND
136 #         ${PANDOC_EXECUTABLE} ${ARGN} -o ${NAME}.texi -s
137 #         COMMAND
138 #         ${MAKEINFO_EXECUTABLE} ${NAME}.texi --html -o ${HTML_OUTPUT_DIR}/${NAME} --css-ref buttondown.css
139 #         DEPENDS ${ARGN}
140 #         VERBATIM
141 #         )
142 # endfunction()
143
144 add_subdirectory(install-guide)
145 add_subdirectory(user-guide)
146 add_subdirectory(man)
147 add_subdirectory(old-html)
148 add_subdirectory(doxygen)
149
150 option(GMX_BUILD_WEBPAGE "Whether to try to configure to build the GROMACS static webpages" OFF)
151 mark_as_advanced(GMX_BUILD_WEBPAGE)
152
153 option(GMX_BUILD_MANUAL "Whether to try to configure to build the PDF manual" ${GMX_BUILD_WEBPAGE})
154 mark_as_advanced(GMX_BUILD_MANUAL)
155 if(GMX_BUILD_MANUAL)
156     # Make sure we only do detection of manual-building dependencies
157     # when the user opted in for that.
158     add_subdirectory(manual)
159 endif()
160
161 set(HTML_BUILD_IS_POSSIBLE OFF)
162 # We can only configure to build the webpage if the user asked for it,
163 # the build is outside of the source dir, and all the components can
164 # be built. There's no need to be talkative if we fail - most people
165 # never need to know.
166 if(GMX_BUILD_WEBPAGE AND
167         GMX_BUILD_HELP AND
168         NOT ${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR} AND
169         MARKDOWN_CONFIGURE_IS_POSSIBLE AND
170         MANUAL_BUILD_IS_POSSIBLE AND
171         PANDOC_EXECUTABLE AND
172         DOXYGEN_EXECUTABLE AND
173         DOXYGEN_MSCGEN_EXECUTABLE)
174     set(HTML_BUILD_IS_POSSIBLE ON)
175 endif()
176
177 if(HTML_BUILD_IS_POSSIBLE)
178     # For a real build of the webpage, the md5sum of the tarballs must
179     # already be known, and so we may as well require that the real
180     # build of the webpage take place from cmake run from the unpacked
181     # tarball. Then, the *_MD5SUM and *_TARBALL variables will be able
182     # to be set on the cmake command line (e.g. by a Jenkins job
183     # configuration), and we can require that they are set. For local
184     # building of the webpages (e.g. for debugging), those variables
185     # can be left unset, and if so, the download section will not be
186     # constructed.
187     if(NOT SOURCE_IS_SOURCE_DISTRIBUTION)
188         if (SOURCE_TARBALL AND SOURCE_MD5SUM AND
189                 REGRESSIONTESTS_TARBALL AND REGRESSIONTESTS_MD5SUM)
190             set(BUILD_DOWNLOAD_SECTION on)
191         else()
192             set(BUILD_DOWNLOAD_SECTION off)
193         endif()
194     else()
195         foreach(VAR SOURCE_MD5SUM REGRESSIONTESTS_MD5SUM SOURCE_TARBALL REGRESSIONTESTS_TARBALL)
196             if(NOT DEFINED ${VAR})
197                 message(FATAL_ERROR "The build of the webpage requires that ${VAR} is set in the cmake cache, e.g. on the CMake command line")
198             endif()
199         endforeach()
200         set(BUILD_DOWNLOAD_SECTION on)
201     endif()
202
203     # If building the webpage from the repo, then tarballs may not
204     # exist, and if so, it would not make sense to build that part of
205     # the front page from index.md.
206     if(BUILD_DOWNLOAD_SECTION)
207         set(DOWNLOAD_SECTION
208 "# Downloads
209
210 *   Source code - [gromacs-${GMX_VERSION_STRING}.tar.gz](gromacs-${GMX_VERSION_STRING}.tar.gz)  
211     (md5sum ${SOURCE_MD5SUM})  
212     Other source code versions may be found at <ftp://ftp.gromacs.org/pub/gromacs/>
213
214 *   Regression tests - [regressiontests-${GMX_VERSION_STRING}.tar.gz](regressiontests-${GMX_VERSION_STRING}.tar.gz)  
215     (md5sum ${REGRESSIONTESTS_MD5SUM})
216 ")
217
218         # Copy the source tarball to the webpage output
219         add_custom_command(
220             OUTPUT ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
221             COMMAND ${CMAKE_COMMAND}
222                -E copy ${SOURCE_TARBALL} ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
223             VERBATIM
224             )
225
226         # Copy the regressiontests tarball to the webpage output
227         add_custom_command(
228             OUTPUT ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
229             COMMAND ${CMAKE_COMMAND}
230                -E copy ${REGRESSIONTESTS_TARBALL} ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
231             VERBATIM
232             )
233     else()
234         set(DOWNLOAD_SECTION "")
235     endif()
236
237     # Put the CSS in the HTML output directory
238     add_custom_command(
239         OUTPUT ${HTML_OUTPUT_DIR}/buttondown.css
240         COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/buttondown.css ${HTML_OUTPUT_DIR}/buttondown.css
241         DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/buttondown.css
242         VERBATIM
243         )
244     list(APPEND extra_webpage_dependencies ${HTML_OUTPUT_DIR}/buttondown.css)
245
246     # Make the PDF reference guide
247     # TODO Try to make the PDF arrive directly in ${HTML_OUTPUT_DIR}
248     add_custom_command(
249         OUTPUT ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
250         COMMAND ${CMAKE_COMMAND}
251             -E remove -f ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
252         COMMAND ${CMAKE_COMMAND}
253             -E copy ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
254         # UseLATEX.cmake makes a target called pdf, not ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf
255         DEPENDS pdf
256         VERBATIM
257         )
258
259     # TODO Move content from the "old" html output into the new user
260     # guide, or delete, as appropriate.
261     if(NOT SOURCE_IS_SOURCE_DISTRIBUTION)
262         # TODO If content remains here once the user guide is in
263         # decent shape, try to make the generated HTML arrive directly
264         # in ${HTML_OUTPUT_DIR}
265         add_custom_target(webpage-html
266             ${CMAKE_COMMAND} -E copy_directory old-html/final ${HTML_OUTPUT_DIR}
267             )
268         add_dependencies(webpage-html html)
269     else()
270         # In the source distribution, the html pages are already
271         # built, so we can avoid making gmx via the html target
272         add_custom_target(webpage-html
273             ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/old-html/final ${HTML_OUTPUT_DIR}
274             )
275     endif()
276
277     # The Doxygen configuration in doxygen/Doxyfile-common.cmakein
278     # makes all the Doxygen output directly in
279     # ${HTML_OUTPUT_DIR}/doxygen (and makes the directory if it needs
280     # to).
281
282     # Add other dependencies for doing the webpage build from the real
283     # tarball
284     if(BUILD_DOWNLOAD_SECTION)
285         list(APPEND extra_webpage_dependencies
286             ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
287             ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
288             )
289     endif()
290
291     configure_markdown(index.md)
292     make_markdown_html(index ${CMAKE_CURRENT_BINARY_DIR}/index.md)
293
294     # Add a top-level target for the others to hook onto
295     add_custom_target(webpage
296         DEPENDS
297            ${HTML_OUTPUT_DIR}/index.html
298            install-guide
299            user-guide
300            ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
301            ${extra_webpage_dependencies}
302         VERBATIM
303         )
304     add_dependencies(webpage webpage-html doc-all)
305 endif()