+if(${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
+ 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()
+