From 2feb4bd500a937ed3d9a1bb6d5878539c5411ea3 Mon Sep 17 00:00:00 2001
From: Martyn Gigg <martyn.gigg@stfc.ac.uk>
Date: Fri, 20 Jan 2012 16:55:09 +0000
Subject: [PATCH] Refs #4411. Add a latex (for a pdf) target to sphinx.

The output PDF is not ideal at the moment but it is a start.
---
 .../MantidPlot/docs/python/CMakeLists.txt     | 40 +++++++++++++++----
 .../MantidPlot/docs/python/runsphinx.py.in    |  6 +--
 2 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/Code/Mantid/MantidPlot/docs/python/CMakeLists.txt b/Code/Mantid/MantidPlot/docs/python/CMakeLists.txt
index 97f43948600..f4762bcaa0a 100644
--- a/Code/Mantid/MantidPlot/docs/python/CMakeLists.txt
+++ b/Code/Mantid/MantidPlot/docs/python/CMakeLists.txt
@@ -8,8 +8,16 @@ find_package ( Sphinx )
 if ( SPHINX_FOUND )
   # Fill in the config file and autogen file with build information
   configure_file ( source/conf.py.in source/conf.py @ONLY ) 
-  configure_file ( autogen_api.py.in autogen_api.py @ONLY ) 
-  configure_file ( runsphinx.py.in runsphinx.py @ONLY )
+  configure_file ( autogen_api.py.in autogen_api.py @ONLY )
+  
+  # Two builders are required
+  set ( TARGET_NAME sphinx )
+  set ( SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR}/../../../${TARGET_NAME} )
+  set ( BUILDER html )
+  configure_file ( runsphinx.py.in runsphinx_html.py @ONLY )
+  set ( BUILDER latex ) 
+  configure_file ( runsphinx.py.in runsphinx_latex.py @ONLY )
+
   
   # Sphinx seems to require the config file to be next to the rest of the source 
   # files meaning we need to copy everything over to the build directory
@@ -34,13 +42,31 @@ if ( SPHINX_FOUND )
   set ( SPHINX_CONF_FILES ${SPHINX_CONF_FILES} ${out_file} )
   endforeach()  
 
-  set ( SPHINX_HTML_BUILD ${CMAKE_CURRENT_BINARY_DIR}/../../../python-sphinx/html )
-  # Sphinx is run as '${SPHINX_EXECUTABLE} -b sourcedir builddir'
-  add_custom_target ( python-sphinx 
+
+
+  # Both depend on the autogenerated API files
+  add_custom_target( ${TARGET_NAME}-generateapi
     COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/MantidPlot -xq autogen_api.py
-    COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/MantidPlot -xq runsphinx.py
     DEPENDS ${SPHINX_CONF_FILES}
-    COMMENT "Build Python Sphinx API documentation"
+    COMMENT "Generating Python API for sphinx"
+  )
+
+  # HTML target
+  set ( SPHINX_HTML_BUILD ${SPHINX_BUILD}/html )
+  add_custom_target ( ${TARGET_NAME}-html 
+    COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/MantidPlot -xq runsphinx_html.py
+    COMMENT "Build Sphinx html documentation"
+  )
+  add_dependencies( ${TARGET_NAME}-html ${TARGET_NAME}-generateapi )
+
+  # Latex target
+  set ( SPHINX_LATEX_BUILD ${SPHINX_BUILD}/latex )
+  add_custom_target ( ${TARGET_NAME}-latex 
+    COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/MantidPlot -xq runsphinx_latex.py
+    COMMENT "Build Python Sphinx latex documentation"
   )
+  add_dependencies( ${TARGET_NAME}-latex ${TARGET_NAME}-generateapi )
+
+  
 
 endif ()
diff --git a/Code/Mantid/MantidPlot/docs/python/runsphinx.py.in b/Code/Mantid/MantidPlot/docs/python/runsphinx.py.in
index 228a0545d8d..5d73a7df827 100644
--- a/Code/Mantid/MantidPlot/docs/python/runsphinx.py.in
+++ b/Code/Mantid/MantidPlot/docs/python/runsphinx.py.in
@@ -9,13 +9,13 @@ import os
 from pkg_resources import load_entry_point
 
 mantidplot = "@CMAKE_RUNTIME_OUTPUT_DIRECTORY@/MantidPlot"
-builder = "html"
+builder = "@BUILDER@"
 src_dir = "@CMAKE_CURRENT_BINARY_DIR@/source"
-output_dir = "@CMAKE_CURRENT_BINARY_DIR@/../../../python-sphinx/" + builder
+output_dir = os.path.join("@SPHINX_BUILD@", builder)
 argv = [mantidplot,'-b', builder, src_dir, output_dir]
 
 if __name__ == '__main__':
     sys.exit(
-        load_entry_point('Sphinx==1.1.2', 'console_scripts', 'sphinx-build')(argv)
+      load_entry_point('Sphinx==1.1.2', 'console_scripts', 'sphinx-build')(argv)
     )
 
-- 
GitLab