CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

PROJECT(ParaViewTutorial NONE)

INCLUDE(UseLATEX.cmake)
INCLUDE(CTest)

SET(PARAVIEW_VERSION "5.2")

SET(SHORT_TITLE "The ParaView Tutorial")
SET(LONG_TITLE "${SHORT_TITLE} \\\\ {\\small Version ${PARAVIEW_VERSION}}")

OPTION(SAVE_TREES "When on, tries to squeeze more on each page to reduce the number of pages needed to print the document." OFF)

IF (SAVE_TREES)
  SET(GLOBAL_OPTIONS "10pt,twocolumn,openany")
  SET(SAVE_TREES_FLAG true)
ELSE (SAVE_TREES)
  SET(GLOBAL_OPTIONS "12pt")
  SET(SAVE_TREES_FLAG false)
ENDIF (SAVE_TREES)

# find git last commit hash
if (__BUILDBOT_UPLOAD_FILES)
  set(MOST_RECENT_TAG "unknown")
  add_custom_target(upload_pdf ALL)
  find_package(Git REQUIRED)
  execute_process(
    COMMAND "${GIT_EXECUTABLE}" "describe" "--tags"
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    OUTPUT_VARIABLE MOST_RECENT_TAG
    OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()

SET(CHAPTER_FILES
  Introduction.tex
  BasicUsage.tex
  VisualizingLargeModels.tex
  BatchPythonScripting.tex
  FurtherReading.tex
  )

set (name "ParaViewTutorial")
ADD_LATEX_DOCUMENT(${name}.tex
  INPUTS ${CHAPTER_FILES}
  CONFIGURE ParaViewTutorial.tex
  IMAGE_DIRS images images/icons
  USE_INDEX
  )
if (__BUILDBOT_UPLOAD_FILES)
  include(CopyToUpload.cmake)
  copy_to_upload(${name}.pdf "${name}-${MOST_RECENT_TAG}.pdf")
endif()

set(TUTORIAL_INSTALL_NAME "ParaViewTutorial" CACHE STRING "The base name of the installed file")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${name}.pdf DESTINATION doc RENAME ${TUTORIAL_INSTALL_NAME}.pdf)

add_test(
  NAME TestParaViewTutorial
  COMMAND ${CMAKE_COMMAND} 
    -D LOG_FILE_NAME:STRING=${CMAKE_CURRENT_BINARY_DIR}/ParaViewTutorial.log
    -P ${CMAKE_SOURCE_DIR}/TestLatexLog.cmake)
set_tests_properties(TestParaViewTutorial PROPERTIES
  FAIL_REGULAR_EXPRESSION "Error;Warning")
