Generalize markdown configuration machinery
[alexxy/gromacs.git] / docs / install-guide / CMakeLists.txt
index 770240d29a791db9eef6cb9a63a8a3fce564430b..7342ba4d7100f30a485b0400a58bcda67656c8ba 100644 (file)
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
 
-set(INSTALL_GUIDE_BUILD_IS_POSSIBLE OFF)
-if(NOT ${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
-    # We can only build the install guide outside of the source dir
-    find_package(Pandoc)
-    if(PANDOC_EXECUTABLE)
-        set(INSTALL_GUIDE_BUILD_IS_POSSIBLE ON)
-    endif()
-endif()
-
-if(INSTALL_GUIDE_BUILD_IS_POSSIBLE)
-    # Do replacement of CMake variables for version strings, etc.
-    # This defers until build time the configuration of
-    # install-guide.md, which could be faster for all the
-    # configurations that don't make the install guide even though it
-    # was possible.
-    configure_file(configure-install-guide.cmake.in
-        ${CMAKE_CURRENT_BINARY_DIR}/configure-install-guide.cmake
-        @ONLY)
-
-    # Configure the install-guide.md at build time
-    add_custom_command(
-        OUTPUT ${CMAKE_BINARY_DIR}/install-guide.md
-        COMMAND ${CMAKE_COMMAND}
-            -P ${CMAKE_CURRENT_BINARY_DIR}/configure-install-guide.cmake
-        DEPENDS
-            ${CMAKE_CURRENT_BINARY_DIR}/configure-install-guide.cmake
-            ${CMAKE_CURRENT_SOURCE_DIR}/install-guide.md
-        COMMENT "Configuring install guide"
-        VERBATIM
-        )
+# Note that the install-guide target, etc. can still be built
+# independent of the webpage target.
+if(MARKDOWN_CONFIGURE_IS_POSSIBLE AND PANDOC_EXECUTABLE)
+    set(name "install-guide")
+    configure_markdown(${name}.md)
+    make_markdown_html(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name}.md)
+    make_markdown_pdf(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name}.md)
 
     # Make the INSTALL file for CPack for the tarball. This gets put
     # into the tarball via the CPack rules in the top-level
@@ -69,59 +46,18 @@ if(INSTALL_GUIDE_BUILD_IS_POSSIBLE)
     add_custom_command(
         OUTPUT final/INSTALL
         COMMAND ${CMAKE_COMMAND} -E make_directory final
-        COMMAND ${PANDOC_EXECUTABLE} -t plain -o final/INSTALL install-guide.md
+        COMMAND ${PANDOC_EXECUTABLE} -t plain -o final/INSTALL ${name}.md
         DEPENDS
-            ${CMAKE_BINARY_DIR}/install-guide.md
+            ${CMAKE_CURRENT_BINARY_DIR}/${name}.md
         VERBATIM
         )
 
-    # Make the single-page HTML install guide
-    add_custom_command(
-        OUTPUT ${HTML_OUTPUT_DIR}/install-guide.html
-        COMMAND
-            ${PANDOC_EXECUTABLE} install-guide.md -o ${HTML_OUTPUT_DIR}/install-guide.html -s --toc --css buttondown.css
-        DEPENDS
-            ${CMAKE_BINARY_DIR}/install-guide.md
-        VERBATIM
-        )
-
-    # Make the PDF install guide
-    add_custom_command(
-        OUTPUT ${HTML_OUTPUT_DIR}/install-guide.pdf
-        COMMAND
-            ${PANDOC_EXECUTABLE} install-guide.md -o ${HTML_OUTPUT_DIR}/install-guide.pdf -s --toc
-        DEPENDS
-            ${CMAKE_BINARY_DIR}/install-guide.md
-        VERBATIM
-        )
-
-    # 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}/index.html
-    #     COMMAND
-    #         ${PANDOC_EXECUTABLE} install-guide.md -o install-guide.texi -s
-    #     COMMAND
-    #         ${MAKEINFO_EXECUTABLE} install-guide.texi --html -o ${HTML_OUTPUT_DIR}/install-guide --css-ref buttondown.css
-    #     DEPENDS
-    #         ${CMAKE_BINARY_DIR}/install-guide.md
-    #     VERBATIM
-    #     )
-
     # Add a top-level target for the webpage build to hook onto
-    add_custom_target(install-guide
+    add_custom_target(${name}
         DEPENDS
             final/INSTALL
-            ${HTML_OUTPUT_DIR}/install-guide.html
-            ${HTML_OUTPUT_DIR}/install-guide.pdf
+            ${HTML_OUTPUT_DIR}/${name}.html
+            ${HTML_OUTPUT_DIR}/${name}.pdf
         VERBATIM
         )
 endif()
-
-set(INSTALL_GUIDE_BUILD_IS_POSSIBLE ${INSTALL_GUIDE_BUILD_IS_POSSIBLE} PARENT_SCOPE)