Unify documentation for webpage build
[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.
42
43 # Even if we aren't going to make the full webpage, set up to put all
44 # the documentation output in the same place, for convenience
45 set(HTML_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/html")
46 file(MAKE_DIRECTORY ${HTML_OUTPUT_DIR})
47
48 add_subdirectory(install-guide)
49 add_subdirectory(man)
50 add_subdirectory(old-html)
51 add_subdirectory(doxygen)
52
53 option(GMX_BUILD_WEBPAGE "Whether to try to configure to build the GROMACS static webpages" OFF)
54 mark_as_advanced(GMX_BUILD_WEBPAGE)
55
56 option(GMX_BUILD_MANUAL "Whether to try to configure to build the PDF manual" ${GMX_BUILD_WEBPAGE})
57 mark_as_advanced(GMX_BUILD_MANUAL)
58 if(GMX_BUILD_MANUAL)
59     # Make sure we only do detection of manual-building dependencies
60     # when the user opted in for that.
61     add_subdirectory(manual)
62 endif()
63
64 find_package(Pandoc)
65
66 set(HTML_BUILD_IS_POSSIBLE OFF)
67 # We can only configure to build the webpage if the user asked for it,
68 # the build is outside of the source dir, and all the components can
69 # be built. There's no need to be talkative if we fail - most people
70 # never need to know.
71 if(GMX_BUILD_WEBPAGE AND
72         GMX_BUILD_HELP AND
73         NOT ${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR} AND
74         INSTALL_GUIDE_BUILD_IS_POSSIBLE AND
75         MANUAL_BUILD_IS_POSSIBLE AND
76         PANDOC_EXECUTABLE AND
77         DOXYGEN_EXECUTABLE AND
78         DOXYGEN_MSCGEN_EXECUTABLE)
79     set(HTML_BUILD_IS_POSSIBLE ON)
80 endif()
81
82 if(HTML_BUILD_IS_POSSIBLE)
83     # For a real build of the webpage, the md5sum of the tarballs must
84     # already be known, and so we may as well require that the real
85     # build of the webpage take place from cmake run from the unpacked
86     # tarball. Then, the *_MD5SUM and *_TARBALL variables will be able
87     # to be set on the cmake command line (e.g. by a Jenkins job
88     # configuration), and we can require that they are set. For local
89     # building of the webpages (e.g. for debugging), the *_MD5SUM
90     # variables need a fallback.
91     if(NOT SOURCE_IS_SOURCE_DISTRIBUTION)
92         if (SOURCE_TARBALL AND SOURCE_MD5SUM AND
93                 REGRESSIONTESTS_TARBALL AND REGRESSIONTESTS_MD5SUM)
94             set(BUILD_DOWNLOAD_SECTION on)
95         else()
96             set(BUILD_DOWNLOAD_SECTION off)
97         endif()
98     else()
99         foreach(VAR SOURCE_MD5SUM REGRESSIONTESTS_MD5SUM SOURCE_TARBALL REGRESSIONTESTS_TARBALL)
100             if(NOT DEFINED ${VAR})
101                 message(FATAL_ERROR "The build of the webpage requires that ${VAR} is set in the cmake cache, e.g. on the CMake command line")
102             endif()
103         endforeach()
104         set(BUILD_DOWNLOAD_SECTION on)
105     endif()
106
107     # If building from the repo, then tarballs may not exist, and if
108     # so, it would not make sense to build that part of the front
109     # page.
110     if(BUILD_DOWNLOAD_SECTION)
111         set(DOWNLOAD_SECTION
112 "# Downloads
113
114 *   Source code - [gromacs-${PROJECT_VERSION}.tar.gz](gromacs-${PROJECT_VERSION}.tar.gz)  
115     (md5sum ${SOURCE_MD5SUM})  
116     Other source code versions may be found at <ftp://ftp.gromacs.org/pub/gromacs/>
117
118 *   Regression tests - [regressiontests-${PROJECT_VERSION}.tar.gz](regressiontests-${PROJECT_VERSION}.tar.gz)  
119     (md5sum ${REGRESSIONTESTS_MD5SUM})
120 ")
121
122         # Copy the source tarball to the webpage output
123         add_custom_command(
124             OUTPUT ${HTML_OUTPUT_DIR}/gromacs-${PROJECT_VERSION}.tar.gz
125             COMMAND ${CMAKE_COMMAND}
126                -E copy ${SOURCE_TARBALL} ${HTML_OUTPUT_DIR}/gromacs-${PROJECT_VERSION}.tar.gz
127             VERBATIM
128             )
129
130         # Copy the regressiontests tarball to the webpage output
131         add_custom_command(
132             OUTPUT ${HTML_OUTPUT_DIR}/regressiontests-${PROJECT_VERSION}.tar.gz
133             COMMAND ${CMAKE_COMMAND}
134                -E copy ${REGRESSIONTESTS_TARBALL} ${HTML_OUTPUT_DIR}/regressiontests-${PROJECT_VERSION}.tar.gz
135             VERBATIM
136             )
137     else()
138         set(DOWNLOAD_SECTION "")
139     endif()
140
141     # Do replacement of CMake variables for version strings, etc.
142     configure_file(configure-html.cmake.in
143         ${CMAKE_CURRENT_BINARY_DIR}/configure-html.cmake
144         @ONLY)
145
146     # This defers until build time the configuration of
147     # index.md, which could be faster
148     add_custom_command(
149         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/index.md
150         COMMAND ${CMAKE_COMMAND}
151             -P ${CMAKE_CURRENT_BINARY_DIR}/configure-html.cmake
152         DEPENDS
153             ${CMAKE_CURRENT_BINARY_DIR}/configure-html.cmake
154             ${CMAKE_CURRENT_SOURCE_DIR}/index.md
155         COMMENT "Configuring index.md"
156         VERBATIM
157         )
158
159     # Put the CSS in the HTML output directory
160     add_custom_command(
161         OUTPUT ${HTML_OUTPUT_DIR}/buttondown.css
162         COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/buttondown.css ${HTML_OUTPUT_DIR}/buttondown.css
163         DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/buttondown.css
164         VERBATIM
165         )
166     list(APPEND extra_webpage_dependencies ${HTML_OUTPUT_DIR}/buttondown.css)
167
168     # Make the top-level index.html
169     add_custom_command(
170         OUTPUT ${HTML_OUTPUT_DIR}/index.html
171         COMMAND ${PANDOC_EXECUTABLE} -o ${HTML_OUTPUT_DIR}/index.html index.md -s --css buttondown.css
172         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/index.md ${HTML_OUTPUT_DIR}/buttondown.css
173         VERBATIM
174         )
175
176     # Make the PDF reference guide
177     # TODO Try to make the PDF arrive directly in ${HTML_OUTPUT_DIR}
178     add_custom_command(
179         OUTPUT ${HTML_OUTPUT_DIR}/manual-${PROJECT_VERSION}.pdf
180         COMMAND ${CMAKE_COMMAND}
181             -E remove -f ${HTML_OUTPUT_DIR}/manual-${PROJECT_VERSION}.pdf
182         COMMAND ${CMAKE_COMMAND}
183             -E copy ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf ${HTML_OUTPUT_DIR}/manual-${PROJECT_VERSION}.pdf
184         # UseLATEX.cmake makes a target called pdf, not ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf
185         DEPENDS pdf
186         VERBATIM
187         )
188
189     # TODO Move content from the "old" html output into the new user
190     # guide, or delete, as appropriate.
191     if(NOT SOURCE_IS_SOURCE_DISTRIBUTION)
192         # TODO If content remains here once the user guide is in
193         # decent shape, try to make the generated HTML arrive directly
194         # in ${HTML_OUTPUT_DIR}
195         add_custom_target(webpage-html
196             ${CMAKE_COMMAND} -E copy_directory old-html/final ${HTML_OUTPUT_DIR}
197             )
198         add_dependencies(webpage-html html)
199     else()
200         # In the source distribution, the html pages are already
201         # built, so we can avoid making gmx via the html target
202         add_custom_target(webpage-html
203             ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/old-html/final ${HTML_OUTPUT_DIR}
204             )
205     endif()
206
207     # The Doxygen configuration in doxygen/Doxyfile-common.cmakein
208     # makes all the Doxygen output directly in
209     # ${HTML_OUTPUT_DIR}/doxygen (and makes the directory if it needs
210     # to).
211
212     # Add other dependencies for doing the webpage build from the real
213     # tarball
214     if(BUILD_DOWNLOAD_SECTION)
215         list(APPEND extra_webpage_dependencies
216             ${HTML_OUTPUT_DIR}/gromacs-${PROJECT_VERSION}.tar.gz
217             ${HTML_OUTPUT_DIR}/regressiontests-${PROJECT_VERSION}.tar.gz
218             )
219     endif()
220
221     # Add a top-level target for the others to hook onto
222     add_custom_target(webpage
223         DEPENDS
224            ${HTML_OUTPUT_DIR}/index.html
225            install-guide
226            ${HTML_OUTPUT_DIR}/install-guide.html
227            ${HTML_OUTPUT_DIR}/install-guide.pdf
228            ${HTML_OUTPUT_DIR}/manual-${PROJECT_VERSION}.pdf
229            ${extra_webpage_dependencies}
230         VERBATIM
231         )
232     add_dependencies(webpage webpage-html doc-all)
233 endif()