Add initial support for python bindings
[alexxy/gromacs.git] / docs / CMakeLists.txt
index 454758697f276f6e12d580dec8b7ccd68f755c8f..cdb1fdcfc0ca78d5450363e7aa4decf25a60330f 100644 (file)
 # pages), and content generated from the gmx program for the various
 # tools (man and HTML pages). It also provides the "webpage" target,
 # that combines all of the above (except man pages in man format) into
-# a form suitable for automated deployment to the GROMACS website.
+# a form suitable for automated deployment to the GROMACS website. It
+# also provides the INSTALL file for the tarball.
+#
+# All of the markdown content is configured, and we'd like to do that
+# at build time rather than configure time (for speed, when not
+# building markdown content). Also, the way they should be configured
+# varies with whether the source is a tarball or repo, and which file
+# is being configured. So several *_IS_POSSIBLE variables are used to
+# direct the configure-time logic so that all appropriate variables
+# are set by the time the configure-markdown.cmake.in file is
+# configured, so that later it can do the configuration of all the
+# markdown files and the right thing will happen in each case.
 
 # Even if we aren't going to make the full webpage, set up to put all
 # the documentation output in the same place, for convenience
 set(HTML_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/html")
 file(MAKE_DIRECTORY ${HTML_OUTPUT_DIR})
 
+if (BUILD_IS_INSOURCE)
+    set(MARKDOWN_CONFIGURE_IS_POSSIBLE off)
+else()
+    set(MARKDOWN_CONFIGURE_IS_POSSIBLE on)
+endif()
+find_package(Pandoc)
+
+# Set up common infrastructure for configuring markdown at build time.
+# Do replacement of CMake variables for version strings, etc. The use
+# of configure-markdown.cmake defers until build time the
+# configuration of markdown files, which could be faster for all the
+# configurations that don't make the documentation even though it was
+# possible, and helps avoid global re-configures if these files
+# change.
+set(SCRIPT_TO_CONFIGURE_MARKDOWN ${CMAKE_CURRENT_BINARY_DIR}/configure-markdown.cmake)
+configure_file(configure-markdown.cmake.in
+    ${SCRIPT_TO_CONFIGURE_MARKDOWN}
+    @ONLY)
+
+# Makes a custom command to configure a Markdown file found in the
+# current source directory with the configure-markdown.make script
+# produced above. The result is placed in the current binary directory
+# for future use.
+function(configure_markdown MARKDOWN_FILE)
+    add_custom_command(
+        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${MARKDOWN_FILE}
+        COMMAND ${CMAKE_COMMAND}
+            -D FILE_TO_CONFIGURE=${CMAKE_CURRENT_SOURCE_DIR}/${MARKDOWN_FILE}
+            -D CONFIGURED_FILE=${CMAKE_CURRENT_BINARY_DIR}/${MARKDOWN_FILE}
+            -P ${SCRIPT_TO_CONFIGURE_MARKDOWN}
+        DEPENDS
+            ${SCRIPT_TO_CONFIGURE_MARKDOWN}
+            ${CMAKE_CURRENT_SOURCE_DIR}/${MARKDOWN_FILE}
+        COMMENT "Configuring Markdown"
+        VERBATIM
+        )
+endfunction()
+
+# Makes a custom command to make single-page HTML from Markdown. Takes
+# a NAME argument for an output filename prefix, and a list of full
+# paths to input files to concatenate with Pandoc into the HTML
+# output.
+function(make_markdown_html NAME)
+    add_custom_command(
+        OUTPUT ${HTML_OUTPUT_DIR}/${NAME}.html
+        COMMAND
+            ${PANDOC_EXECUTABLE} ${ARGN} -o ${HTML_OUTPUT_DIR}/${NAME}.html -s --toc --css buttondown.css
+        DEPENDS ${ARGN}
+        VERBATIM
+        )
+endfunction()
+
+# Makes a custom command to make PDF from Markdown. Takes a NAME
+# argument for an output filename prefix, and a list of full paths to
+# input files to concatenate with Pandoc into the PDF.
+function(make_markdown_pdf NAME)
+    add_custom_command(
+        OUTPUT ${HTML_OUTPUT_DIR}/${NAME}.pdf
+        COMMAND
+            ${PANDOC_EXECUTABLE} ${ARGN} -o ${HTML_OUTPUT_DIR}/${NAME}.pdf -s --toc
+        DEPENDS ${ARGN}
+        VERBATIM
+        )
+endfunction()
+
+# function(make_markdown_multipage_html NAME)
+#     # Make the multi-page HTML install guide
+#
+#     # TODO This is currently disabled, because the pandoc-specific
+#     # buttondown.css doesn't work with the different kind of output
+#     # makeinfo produces. When we understand better how we want to do
+#     # generation, decide whether we want multi-page HTML output and
+#     # how to make it work well.
+#
+#     add_custom_command(
+#         OUTPUT ${HTML_OUTPUT_DIR}/${HTML_DIR}/index.html
+#         COMMAND
+#         ${PANDOC_EXECUTABLE} ${ARGN} -o ${NAME}.texi -s
+#         COMMAND
+#         ${MAKEINFO_EXECUTABLE} ${NAME}.texi --html -o ${HTML_OUTPUT_DIR}/${NAME} --css-ref buttondown.css
+#         DEPENDS ${ARGN}
+#         VERBATIM
+#         )
+# endfunction()
+
 add_subdirectory(install-guide)
+add_subdirectory(user-guide)
 add_subdirectory(man)
 add_subdirectory(old-html)
 add_subdirectory(doxygen)
@@ -61,8 +158,6 @@ if(GMX_BUILD_MANUAL)
     add_subdirectory(manual)
 endif()
 
-find_package(Pandoc)
-
 set(HTML_BUILD_IS_POSSIBLE OFF)
 # We can only configure to build the webpage if the user asked for it,
 # the build is outside of the source dir, and all the components can
@@ -70,8 +165,8 @@ set(HTML_BUILD_IS_POSSIBLE OFF)
 # never need to know.
 if(GMX_BUILD_WEBPAGE AND
         GMX_BUILD_HELP AND
-        NOT ${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR} AND
-        INSTALL_GUIDE_BUILD_IS_POSSIBLE AND
+        NOT BUILD_IS_INSOURCE AND
+        MARKDOWN_CONFIGURE_IS_POSSIBLE AND
         MANUAL_BUILD_IS_POSSIBLE AND
         PANDOC_EXECUTABLE AND
         DOXYGEN_EXECUTABLE AND
@@ -86,8 +181,9 @@ if(HTML_BUILD_IS_POSSIBLE)
     # tarball. Then, the *_MD5SUM and *_TARBALL variables will be able
     # to be set on the cmake command line (e.g. by a Jenkins job
     # configuration), and we can require that they are set. For local
-    # building of the webpages (e.g. for debugging), the *_MD5SUM
-    # variables need a fallback.
+    # building of the webpages (e.g. for debugging), those variables
+    # can be left unset, and if so, the download section will not be
+    # constructed.
     if(NOT SOURCE_IS_SOURCE_DISTRIBUTION)
         if (SOURCE_TARBALL AND SOURCE_MD5SUM AND
                 REGRESSIONTESTS_TARBALL AND REGRESSIONTESTS_MD5SUM)
@@ -104,58 +200,40 @@ if(HTML_BUILD_IS_POSSIBLE)
         set(BUILD_DOWNLOAD_SECTION on)
     endif()
 
-    # If building from the repo, then tarballs may not exist, and if
-    # so, it would not make sense to build that part of the front
-    # page.
+    # If building the webpage from the repo, then tarballs may not
+    # exist, and if so, it would not make sense to build that part of
+    # the front page from index.md.
     if(BUILD_DOWNLOAD_SECTION)
         set(DOWNLOAD_SECTION
 "# Downloads
 
-*   Source code - [gromacs-${PROJECT_VERSION}.tar.gz](gromacs-${PROJECT_VERSION}.tar.gz)  
+*   Source code - [gromacs-${GMX_VERSION_STRING}.tar.gz](gromacs-${GMX_VERSION_STRING}.tar.gz)  
     (md5sum ${SOURCE_MD5SUM})  
     Other source code versions may be found at <ftp://ftp.gromacs.org/pub/gromacs/>
 
-*   Regression tests - [regressiontests-${PROJECT_VERSION}.tar.gz](regressiontests-${PROJECT_VERSION}.tar.gz)  
+*   Regression tests - [regressiontests-${GMX_VERSION_STRING}.tar.gz](regressiontests-${GMX_VERSION_STRING}.tar.gz)  
     (md5sum ${REGRESSIONTESTS_MD5SUM})
 ")
 
         # Copy the source tarball to the webpage output
         add_custom_command(
-            OUTPUT ${HTML_OUTPUT_DIR}/gromacs-${PROJECT_VERSION}.tar.gz
+            OUTPUT ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
             COMMAND ${CMAKE_COMMAND}
-               -E copy ${SOURCE_TARBALL} ${HTML_OUTPUT_DIR}/gromacs-${PROJECT_VERSION}.tar.gz
+               -E copy ${SOURCE_TARBALL} ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
             VERBATIM
             )
 
         # Copy the regressiontests tarball to the webpage output
         add_custom_command(
-            OUTPUT ${HTML_OUTPUT_DIR}/regressiontests-${PROJECT_VERSION}.tar.gz
+            OUTPUT ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
             COMMAND ${CMAKE_COMMAND}
-               -E copy ${REGRESSIONTESTS_TARBALL} ${HTML_OUTPUT_DIR}/regressiontests-${PROJECT_VERSION}.tar.gz
+               -E copy ${REGRESSIONTESTS_TARBALL} ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
             VERBATIM
             )
     else()
         set(DOWNLOAD_SECTION "")
     endif()
 
-    # Do replacement of CMake variables for version strings, etc.
-    configure_file(configure-html.cmake.in
-        ${CMAKE_CURRENT_BINARY_DIR}/configure-html.cmake
-        @ONLY)
-
-    # This defers until build time the configuration of
-    # index.md, which could be faster
-    add_custom_command(
-        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/index.md
-        COMMAND ${CMAKE_COMMAND}
-            -P ${CMAKE_CURRENT_BINARY_DIR}/configure-html.cmake
-        DEPENDS
-            ${CMAKE_CURRENT_BINARY_DIR}/configure-html.cmake
-            ${CMAKE_CURRENT_SOURCE_DIR}/index.md
-        COMMENT "Configuring index.md"
-        VERBATIM
-        )
-
     # Put the CSS in the HTML output directory
     add_custom_command(
         OUTPUT ${HTML_OUTPUT_DIR}/buttondown.css
@@ -165,22 +243,14 @@ if(HTML_BUILD_IS_POSSIBLE)
         )
     list(APPEND extra_webpage_dependencies ${HTML_OUTPUT_DIR}/buttondown.css)
 
-    # Make the top-level index.html
-    add_custom_command(
-        OUTPUT ${HTML_OUTPUT_DIR}/index.html
-        COMMAND ${PANDOC_EXECUTABLE} -o ${HTML_OUTPUT_DIR}/index.html index.md -s --css buttondown.css
-        DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/index.md ${HTML_OUTPUT_DIR}/buttondown.css
-        VERBATIM
-        )
-
     # Make the PDF reference guide
     # TODO Try to make the PDF arrive directly in ${HTML_OUTPUT_DIR}
     add_custom_command(
-        OUTPUT ${HTML_OUTPUT_DIR}/manual-${PROJECT_VERSION}.pdf
+        OUTPUT ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
         COMMAND ${CMAKE_COMMAND}
-            -E remove -f ${HTML_OUTPUT_DIR}/manual-${PROJECT_VERSION}.pdf
+            -E remove -f ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
         COMMAND ${CMAKE_COMMAND}
-            -E copy ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf ${HTML_OUTPUT_DIR}/manual-${PROJECT_VERSION}.pdf
+            -E copy ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
         # UseLATEX.cmake makes a target called pdf, not ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf
         DEPENDS pdf
         VERBATIM
@@ -213,19 +283,21 @@ if(HTML_BUILD_IS_POSSIBLE)
     # tarball
     if(BUILD_DOWNLOAD_SECTION)
         list(APPEND extra_webpage_dependencies
-            ${HTML_OUTPUT_DIR}/gromacs-${PROJECT_VERSION}.tar.gz
-            ${HTML_OUTPUT_DIR}/regressiontests-${PROJECT_VERSION}.tar.gz
+            ${HTML_OUTPUT_DIR}/gromacs-${GMX_VERSION_STRING}.tar.gz
+            ${HTML_OUTPUT_DIR}/regressiontests-${GMX_VERSION_STRING}.tar.gz
             )
     endif()
 
+    configure_markdown(index.md)
+    make_markdown_html(index ${CMAKE_CURRENT_BINARY_DIR}/index.md)
+
     # Add a top-level target for the others to hook onto
     add_custom_target(webpage
         DEPENDS
            ${HTML_OUTPUT_DIR}/index.html
            install-guide
-           ${HTML_OUTPUT_DIR}/install-guide.html
-           ${HTML_OUTPUT_DIR}/install-guide.pdf
-           ${HTML_OUTPUT_DIR}/manual-${PROJECT_VERSION}.pdf
+           user-guide
+           ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
            ${extra_webpage_dependencies}
         VERBATIM
         )