From 543e6b900077606609397358b0b6b418b8560599 Mon Sep 17 00:00:00 2001
From: mpilman <markus.pilman@snowflake.com>
Date: Wed, 6 Feb 2019 17:54:01 -0800
Subject: [PATCH] intermediate commit

---
 CMakeLists.txt               |  1 +
 cmake/FindSphinx.cmake       |  7 +++++++
 documentation/CMakeLists.txt | 16 ++++++++++++++++
 3 files changed, 24 insertions(+)
 create mode 100644 cmake/FindSphinx.cmake
 create mode 100644 documentation/CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 911da1ee39..e79e44b0a5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -222,6 +222,7 @@ endif()
 add_subdirectory(bindings)
 add_subdirectory(fdbbackup)
 add_subdirectory(tests)
+add_subdirectory(documentation)
 
 if(WIN32)
   add_subdirectory(packaging/msi)
diff --git a/cmake/FindSphinx.cmake b/cmake/FindSphinx.cmake
new file mode 100644
index 0000000000..8d3715d880
--- /dev/null
+++ b/cmake/FindSphinx.cmake
@@ -0,0 +1,7 @@
+find_program(SPHINXBUILD
+  sphinx-build
+  DOC "Sphinx-build tool")
+
+find_package_handle_standard_args(Sphinx
+  FOUND_VAR SPHINX_FOUND
+  REQUIRED_VARS SPHINXBUILD)
diff --git a/documentation/CMakeLists.txt b/documentation/CMakeLists.txt
new file mode 100644
index 0000000000..2678ef9ac4
--- /dev/null
+++ b/documentation/CMakeLists.txt
@@ -0,0 +1,16 @@
+find_package(Sphinx)
+if(SPHINX_FOUND)
+  set(SPHINX_OPTIONS "" CACHE STRING "Additional Options to pass to sphinx-build")
+  set(SPHINX_PAPER_SIZE "letter" CACHE STRING "Paper size for documents generated with sphinx")
+  set(SPHINX_OPTS "${SPHINX_OPTIONS} -c . -d ${CMAKE_CURRENT_BINARY_DIR}/doctrees -D latex_paper_size=${SPHINX_PAPER_SIZE}")
+  file(GLOB_RECURSE RST_FILES "source/*rst")
+  file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html ${CMAKE_CURRENT_BINARY_DIR}/doctrees)
+  add_custom_command(
+    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/html/index.html
+    COMMAND ${SPHINXBUILD} -b html ${SPHINX_OPTS} ${CMAKE_CURRENT_BINARY_DIR}/html
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/sphinx
+    DEPENDS ${RST_FILES})
+  add_custom_target(html DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/html/index.html)
+else()
+  message(WARNING "Cound not find sphinx-build - will not build documentatioin")
+endif()